|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +The FinOps Toolkit is an open-source collection of tools for adopting and implementing FinOps capabilities in the Microsoft Cloud. It contains templates, PowerShell modules, workbooks, optimization engines, and supporting documentation organized in a modular architecture. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +### Building and Development |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build entire toolkit |
| 15 | +npm run build |
| 16 | +# or |
| 17 | +pwsh -Command ./src/scripts/Build-Toolkit |
| 18 | + |
| 19 | +# Build FinOps hubs |
| 20 | +pwsh -Command ./src/scripts/Build-Toolkit finops-hub |
| 21 | + |
| 22 | +# Build specific components |
| 23 | +npm run build-ps # PowerShell module only |
| 24 | +pwsh -Command ./src/scripts/Build-Bicep # Bicep templates |
| 25 | +pwsh -Command ./src/scripts/Build-Workbook # Azure Monitor workbooks |
| 26 | +pwsh -Command ./src/scripts/Build-OpenData # Open data files |
| 27 | + |
| 28 | +# Deploy for testing |
| 29 | +npm run deploy-test |
| 30 | +# or |
| 31 | +pwsh -Command ./src/scripts/Deploy-Toolkit -Build -Test |
| 32 | + |
| 33 | +# Package for release |
| 34 | +npm run package |
| 35 | +# or |
| 36 | +pwsh -Command ./src/scripts/Package-Toolkit -Build |
| 37 | +``` |
| 38 | + |
| 39 | +### Testing |
| 40 | + |
| 41 | +```bash |
| 42 | +# Run PowerShell unit tests |
| 43 | +npm run pester |
| 44 | +# or |
| 45 | +pwsh -Command Invoke-Pester -Output Detailed -Path ./src/powershell/Tests/Unit/* |
| 46 | + |
| 47 | +# Run integration tests |
| 48 | +pwsh -Command ./src/scripts/Test-PowerShell -Integration |
| 49 | + |
| 50 | +# Run specific test categories |
| 51 | +pwsh -Command ./src/scripts/Test-PowerShell -Hubs -Exports |
| 52 | + |
| 53 | +# Lint PowerShell code |
| 54 | +pwsh -Command ./src/scripts/Test-PowerShell -Lint |
| 55 | +``` |
| 56 | + |
| 57 | +### Bicep Development |
| 58 | + |
| 59 | +```bash |
| 60 | +# Validate Bicep templates |
| 61 | +bicep build path/to/template.bicep --stdout |
| 62 | + |
| 63 | +# Test template deployment |
| 64 | +az deployment group what-if --resource-group myRG --template-file template.bicep |
| 65 | +``` |
| 66 | + |
| 67 | +## Architecture and Code Organization |
| 68 | + |
| 69 | +### High-Level Structure |
| 70 | + |
| 71 | +- **`/src/templates/`** - ARM/Bicep infrastructure templates with modular namespace organization |
| 72 | +- **`/src/powershell/`** - PowerShell module with public/private functions and comprehensive tests |
| 73 | +- **`/src/optimization-engine/`** - Azure Optimization Engine for cost recommendations |
| 74 | +- **`/src/workbooks/`** - Azure Monitor workbooks for governance and optimization |
| 75 | +- **`/src/open-data/`** - Reference data (pricing, regions, services) with utilities |
| 76 | +- **`/src/scripts/`** - Build automation and development tools |
| 77 | +- **`/docs/`** - Jekyll documentation website |
| 78 | +- **`/docs-mslearn/`** - Microsoft Learn documentation website |
| 79 | +- **`/docs-wiki/`** - GitHub wiki documentation |
| 80 | + |
| 81 | +### Current Architectural Reorganization |
| 82 | + |
| 83 | +The FinOps hubs solution is actively migrating to a namespace-based modular structure: |
| 84 | + |
| 85 | +- **`Microsoft.FinOpsHubs/`** - Core FinOps Hub infrastructure modules |
| 86 | +- **`Microsoft.CostManagement/`** - Cost management exports and schemas |
| 87 | +- **`fx/`** - Shared foundation components (hub-types, scripts, utilities) |
| 88 | + |
| 89 | +### Template Architecture |
| 90 | + |
| 91 | +Templates use a multi-target build system that generates: |
| 92 | + |
| 93 | +- Azure Quickstart Templates (ARM JSON) |
| 94 | +- Bicep Registry modules |
| 95 | +- Standalone deployments |
| 96 | +- Azure portal UI definitions |
| 97 | + |
| 98 | +Key patterns: |
| 99 | + |
| 100 | +- **`.build.config`** files control build behavior per template |
| 101 | +- **`settings.json`** contains component-specific configuration |
| 102 | +- **`ftkver.txt`** files maintain version synchronization |
| 103 | +- **Conditional resource deployment** based on parameters |
| 104 | + |
| 105 | +### PowerShell Module Structure |
| 106 | + |
| 107 | +- **`Public/`** - User-facing cmdlets (Get-_, Set-_, New-\*, etc.) |
| 108 | +- **`Private/`** - Internal utilities and helpers |
| 109 | +- **`Tests/Unit/`** - Pester unit tests with mocking |
| 110 | +- **`Tests/Integration/`** - End-to-end Azure integration tests |
| 111 | +- **Module manifest** defines exports and dependencies |
| 112 | + |
| 113 | +### Data Flow and Integration |
| 114 | + |
| 115 | +- **Open data** provides reference information consumed by templates and PowerShell |
| 116 | +- **Build scripts** orchestrate compilation across all components |
| 117 | +- **Version management** is centralized through `Update-Version.ps1` |
| 118 | +- **Templates reference** shared schemas and types from `fx/` namespace |
| 119 | + |
| 120 | +## Key Development Patterns |
| 121 | + |
| 122 | +### Template Development |
| 123 | + |
| 124 | +- Use `newApp()` and `newHub()` functions from `fx/hub-types.bicep` for consistent resource naming |
| 125 | +- Follow the conditional deployment pattern: `resource foo 'type' = if (condition) { ... }` |
| 126 | +- Implement proper parameter validation with `@allowed`, `@minValue`, `@maxValue` |
| 127 | +- Include telemetry tracking via `defaultTelemetry` parameter |
| 128 | + |
| 129 | +### PowerShell Development |
| 130 | + |
| 131 | +- All public functions must have comment-based help |
| 132 | +- Use approved verbs from `Get-Verb` |
| 133 | +- Implement comprehensive parameter validation |
| 134 | +- Support `-WhatIf` and `-Confirm` for destructive operations |
| 135 | +- Include Pester tests for all functions |
| 136 | + |
| 137 | +### Testing Strategy |
| 138 | + |
| 139 | +- **Lint tests** validate syntax and coding standards |
| 140 | +- **Unit tests** test isolated function behavior with mocks |
| 141 | +- **Integration tests** perform end-to-end validation against Azure |
| 142 | +- **Template validation** uses `bicep build` and ARM what-if deployments |
| 143 | + |
| 144 | +### Build System Integration |
| 145 | + |
| 146 | +The PowerShell-based build system: |
| 147 | + |
| 148 | +- Compiles templates to multiple target formats |
| 149 | +- Validates all code before packaging |
| 150 | +- Maintains version consistency across components |
| 151 | +- Generates release artifacts automatically |
| 152 | + |
| 153 | +### Version Management |
| 154 | + |
| 155 | +- Central version in `package.json` (currently 12.0.0) |
| 156 | +- Synchronized across all components via build scripts |
| 157 | +- Individual `ftkver.txt` files distributed to modules |
| 158 | +- Git tags correspond to release versions |
| 159 | + |
| 160 | +## Repository Conventions |
| 161 | + |
| 162 | +### Branch Strategy |
| 163 | + |
| 164 | +- **`dev`** - Main integration branch |
| 165 | +- Feature branches merge into `dev` |
| 166 | +- Releases are tagged from `dev` |
| 167 | + |
| 168 | +### File Organization |
| 169 | + |
| 170 | +- Templates follow namespace/module/component structure |
| 171 | +- PowerShell follows standard module layout |
| 172 | +- Documentation uses Jekyll conventions |
| 173 | +- Build artifacts are generated, not checked in |
| 174 | + |
| 175 | +### Coding Standards |
| 176 | + |
| 177 | +- Always follow the content and coding standards defined in `docs-wiki/Coding-guidelines.md` |
| 178 | +- Content (text strings): Follow the Microsoft style guide and always use sentence casing except for proper nouns |
| 179 | +- Bicep: Follow Azure Bicep style guide |
| 180 | +- PowerShell: Use PowerShell best practices and approved verbs |
| 181 | +- Documentation: Use markdown with consistent formatting |
| 182 | +- Commit messages: Use conventional commit format |
0 commit comments