Developers often overspend on cloud; this tool: Fetches Azure VM, app service, DB cost Predicts monthly bill Shows per-service breakdown Alerts if budget exceeds a limit Suggests cost-optimization tips
- To analyze Azure cloud resource costs
- To provide detailed cost breakdown and visualization
- To implement budget monitoring and alerting
- To integrate AI-based cost intelligence
Azure Cost Analyzer/
βββ README.md
βββ backend/ # FastAPI backend application
β βββ alembic.ini
β βββ docker-compose.yml
β βββ Dockerfile
β βββ entrypoint.sh
β βββ pyproject.toml
β βββ requirements.txt
β βββ app/
β βββ config.py # Application configuration
β βββ main.py # FastAPI application entry point
β βββ scheduler.py # Task scheduler for alerts & anomalies
β βββ alembic/ # Database migration scripts
β β βββ env.py
β β βββ README
β β βββ script.py.mako
β β βββ versions/ # Migration history
β βββ azure/ # Azure SDK integration
β β βββ auth.py # Azure authentication logic
β β βββ cost_client.py # Azure Cost Management API client
β βββ db/
β β βββ database.py # PostgreSQL connection setup
β β βββ models.py # SQLAlchemy ORM models
β β βββ operations.py # Generic database operations
β β βββ alert_operations.py # Alert-specific DB operations
β βββ exceptions/
β β βββ cost_exceptions.py # Custom exception classes
β βββ handlers/
β β βββ exception_handlers.py # Global exception handlers
β βββ models/ # Pydantic data models
β β βββ alert_models.py # Alert request/response models
β β βββ cost_models.py # Cost analysis data models
β βββ routes/ # API endpoints
β β βββ alert_routes.py # Alert API routes
β β βββ cost_routes.py # Cost analysis API routes
β βββ services/ # Business logic & orchestration
β β βββ alert_service.py # Alert management logic
β β βββ cache_service.py # Caching layer for performance
β β βββ cost_preprocessor.py # Data preprocessing pipeline
β β βββ cost_service.py # Cost data fetching & analysis
β β βββ cost_tasks.py # Background task definitions
β β βββ email_service.py # Email notification service
β βββ utils/
β βββ responses.py # Standardized API response helpers
βββ frontend/ # React + TypeScript UI application
βββ package.json
βββ tsconfig.json
βββ vite.config.ts
βββ tailwind.config.ts
βββ postcss.config.js
βββ eslint.config.js
βββ vitest.config.ts
βββ components.json
βββ index.html
βββ public/
β βββ robots.txt
β βββ staticwebapp.config.json
βββ src/
βββ App.tsx
βββ main.tsx
βββ vite-env.d.ts
βββ App.css
βββ index.css
βββ components/ # Reusable UI components
β βββ AppSidebar.tsx
β βββ NavLink.tsx
β βββ dashboard/ # Dashboard-specific components
β βββ ui/ # Shadcn/ui components
βββ hooks/ # Custom React hooks
β βββ use-cost-data.ts
β βββ use-mobile.tsx
β βββ use-toast.ts
βββ lib/ # Utility functions & types
β βββ api.ts # API client configuration
β βββ colors.ts # Color constants
β βββ config.ts # Frontend configuration
β βββ types.ts # TypeScript type definitions
β βββ utils.ts # Helper utilities
βββ pages/ # Page components
β βββ Index.tsx # Dashboard home page
β βββ CostAnalysis.tsx # Cost analysis page
β βββ Budget.tsx # Budget management page
β βββ Reports.tsx # Reports page
β βββ Settings.tsx # Settings page
β βββ NotFound.tsx # 404 page
βββ test/ # Test files
βββ example.test.ts
βββ setup.ts
- Python 3.11+ recommended
- Git installed
- (Optional) Azure CLI for auth workflows
# Install uv if needed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create and sync environment
uv venv
uv pip install -r requirements.txt
uv run app/main.pypython -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt
python -m app/main.pyTo use this project, you must have:
- An Azure Subscription
- Billing Reader or Cost Management Reader role on that subscription
- Owner access (only once, to set things up)
-
Navigate to "Microsoft Entra ID (Azure AD)" β "App registrations" β "New registration".
-
Enter a name (eg: cost-analyzer)
-
Supported account types: Choose
Accounts in this organizational directory only (Single tenant) -
Click Register.
After registration, you land on Overview page.
Copy and save these safely:
| Field | What it is |
|---|---|
| Application (client) ID | Appβs username |
| Directory (tenant) ID | Your Azure organization |
| Object ID | Internal Azure reference |
You will use:
Put them in a .env file later.
- Go to "Certificates & secrets" β "New client secret".
- Add a description and expiry, then click "Add".
- Copy the generated Value (this is your
AZURE_CLIENT_SECRET).
- In the Azure Portal, search for "Subscriptions".
- Select your subscription and copy the Subscription ID.
- Go to Subscriptions β "Access control (IAM)" β "Add role assignment".
- You'll see a long list of roles. Search for "Cost Management Reader" role β Click Next.
- Select your app (Service Principal):
i) search by app name or client id
ii) select it β click Select β click Next
- Review details:
i) Role: Cost Management Reader
ii) Scope: Subscription
iii) Member: Your app - Click Assign
Refer the .env.example from both backend and frontend folders. Create a .env file in each and fill in the required values.
The application supports sending email alerts for budget warnings and anomaly detection. Follow the steps below to configure SMTP:
-
Enable 2-Step Verification (if not already enabled):
- Go to myaccount.google.com/security
- Enable 2-Step Verification
-
Generate an App Password:
- Go to myaccount.google.com/apppasswords
- Select "Mail" and "Windows Computer" (or your device)
- Click "Generate"
- Copy the generated 16-character password
-
Add to .env:
SMTP_SERVER=smtp.gmail.com SMTP_PORT=587 SMTP_USERNAME=your-email@gmail.com SMTP_PASSWORD=your-16-char-app-password SMTP_FROM_EMAIL=your-email@gmail.com SMTP_FROM_NAME=Azure Cost Analyzer
-
You can also refer to How to Configure Gmail SMTP Server Settings