# anuppillai1784/tenant-cost-attribution architecture

> Architecture diagram of the GitHub repository anuppillai1784/tenant-cost-attribution, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anuppillai1784/tenant-cost-attribution
- Repository: https://github.com/anuppillai1784/tenant-cost-attribution

## Overview

This Python tool attributes inference-request spend to tenants, departments, and features, then checks reconciliation, projects budgets, and detects daily spend spikes. The main workflow is the demo command: generate events, ingest and reload them from SQLite, price and aggregate them, then write JSON outputs and print a text summary. The separate reconcile command checks stored events. The graph preserves the documented pricing, reporting, budget, anomaly, and synthetic-demo capabilities. Relationships are supported by the README and indexed excerpts; unsampled implementation details are not inferred.

Main entry points: [`cost_attribution/demo.py`](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/demo.py) (Demo runner), [`cost_attribution/cli.py`](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/cli.py) (CLI commands), [`cost_attribution/render.py`](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/render.py) (Text rendering), [`cost_attribution/report.py`](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/report.py) (Report data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Command entry"]
  node_module_entry["Module entry<br/>[__main__.py]"]
  node_commands["CLI commands<br/>[cli.py]"]
  node_demo_runner["Demo runner<br/>[demo.py]"]
end

subgraph group_ingestion["Event ingestion"]
  node_synthetic_events["Synthetic events<br/>[synthetic.py]"]
  node_event_ledger[("Event ledger<br/>[ledger.py]")]
end

subgraph group_accounting["Spend accounting"]
  node_pricing["Versioned pricing<br/>[prices.py]"]
  node_attribution["Attribution and reconciliation<br/>[attribution.py]"]
end

subgraph group_analysis["Analysis and output"]
  node_budget_projection["Budget projection<br/>[budgets.py]"]
  node_report_data["Report data<br/>[report.py]"]
  node_anomaly_detection["Anomaly detection<br/>[anomalies.py]"]
  node_text_rendering["Text rendering<br/>[render.py]"]
  node_report_file["Report JSON<br/>[report.json]"]
  node_alerts_file["Alerts JSON<br/>[alerts.json]"]
end

node_operator(("Operator"))
node_terminal(("Terminal output"))

node_operator -->|"runs module"| node_module_entry
node_module_entry -->|"calls main"| node_commands
node_commands -->|"runs demo"| node_demo_runner
node_commands -->|"opens and loads"| node_event_ledger
node_commands -->|"prices and reconciles"| node_attribution
node_commands -->|"renders result"| node_text_rendering
node_commands -->|"prints summary"| node_terminal
node_demo_runner -->|"generates events"| node_synthetic_events
node_demo_runner -->|"ingests and loads"| node_event_ledger
node_demo_runner -->|"prices and aggregates"| node_attribution
node_attribution -->|"prices events"| node_pricing
node_demo_runner -->|"detects anomalies"| node_anomaly_detection
node_demo_runner -->|"builds report"| node_report_data
node_report_data -->|"totals by dimension"| node_attribution
node_report_data -->|"projects budgets"| node_budget_projection
node_demo_runner -->|"writes report"| node_report_file
node_demo_runner -->|"writes alerts"| node_alerts_file
node_demo_runner -->|"renders summary"| node_text_rendering
node_text_rendering -->|"formats report"| node_report_data
node_text_rendering -->|"formats alerts"| node_anomaly_detection
node_text_rendering -->|"prints summary"| node_terminal

click node_module_entry "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/__main__.py"
click node_commands "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/cli.py"
click node_demo_runner "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/demo.py"
click node_synthetic_events "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/synthetic.py"
click node_event_ledger "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/ledger.py"
click node_pricing "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/prices.py"
click node_attribution "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/attribution.py"
click node_budget_projection "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/budgets.py"
click node_report_data "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/report.py"
click node_anomaly_detection "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/anomalies.py"
click node_text_rendering "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/render.py"
click node_report_file "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/examples/report.json"
click node_alerts_file "https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/examples/alerts.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_module_entry,node_commands,node_demo_runner toneBlue
class node_synthetic_events,node_event_ledger toneAmber
class node_pricing,node_attribution toneMint
class node_budget_projection,node_report_data,node_anomaly_detection,node_text_rendering,node_report_file,node_alerts_file toneRose
class node_operator,node_terminal toneIndigo
```

## Components

### Command entry

- [Module entry](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/__main__.py): `cost_attribution/__main__.py`
- [CLI commands](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/cli.py): `cost_attribution/cli.py`
- [Demo runner](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/demo.py): `cost_attribution/demo.py`

### Event ingestion

- [Synthetic events](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/synthetic.py): `cost_attribution/synthetic.py`
- [Event ledger](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/ledger.py): `cost_attribution/ledger.py`

### Spend accounting

- [Versioned pricing](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/prices.py): `cost_attribution/prices.py`
- [Attribution and reconciliation](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/attribution.py): `cost_attribution/attribution.py`

### Analysis and output

- [Budget projection](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/budgets.py): `cost_attribution/budgets.py`
- [Report data](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/report.py): `cost_attribution/report.py`
- [Anomaly detection](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/anomalies.py): `cost_attribution/anomalies.py`
- [Text rendering](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/cost_attribution/render.py): `cost_attribution/render.py`
- [Report JSON](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/examples/report.json): `examples/report.json`
- [Alerts JSON](https://github.com/anuppillai1784/tenant-cost-attribution/blob/main/examples/alerts.json): `examples/alerts.json`

### Other components

- **Operator**
- **Terminal output**

## Connections

- Operator → Module entry: runs module (evidence: `README.md`)
- Module entry → CLI commands: calls main (evidence: `cost_attribution/__main__.py`)
- CLI commands → Demo runner: runs demo (evidence: `cost_attribution/cli.py`)
- CLI commands → Event ledger: opens and loads (evidence: `cost_attribution/cli.py`)
- CLI commands → Attribution and reconciliation: prices and reconciles (evidence: `cost_attribution/cli.py`)
- CLI commands → Text rendering: renders result (evidence: `cost_attribution/cli.py`)
- CLI commands → Terminal output: prints summary (evidence: `cost_attribution/cli.py`)
- Demo runner → Synthetic events: generates events (evidence: `cost_attribution/demo.py`)
- Demo runner → Event ledger: ingests and loads (evidence: `cost_attribution/demo.py`)
- Demo runner → Attribution and reconciliation: prices and aggregates (evidence: `cost_attribution/demo.py`)
- Attribution and reconciliation → Versioned pricing: prices events (evidence: `cost_attribution/attribution.py`)
- Demo runner → Anomaly detection: detects anomalies (evidence: `cost_attribution/demo.py`)
- Demo runner → Report data: builds report (evidence: `cost_attribution/demo.py`)
- Report data → Attribution and reconciliation: totals by dimension (evidence: `cost_attribution/report.py`)
- Report data → Budget projection: projects budgets (evidence: `cost_attribution/report.py`)
- Demo runner → Report JSON: writes report (evidence: `cost_attribution/demo.py`)
- Demo runner → Alerts JSON: writes alerts (evidence: `cost_attribution/demo.py`)
- Demo runner → Text rendering: renders summary (evidence: `cost_attribution/demo.py`)
- Text rendering → Report data: formats report (evidence: `cost_attribution/render.py`)
- Text rendering → Anomaly detection: formats alerts (evidence: `cost_attribution/render.py`)
- Text rendering → Terminal output: prints summary
