# sdz0z6/bedrock architecture

> Architecture diagram of the GitHub repository sdz0z6/bedrock, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sdz0z6/bedrock
- Repository: https://github.com/sdz0z6/bedrock

## Overview

Bedrock Cost is a Flask dashboard for read-only AWS cost, model-usage, and quota monitoring, with account-ledger management and scheduled alerts. The main user workflow is login → select a dashboard page → load accounts and query the relevant AWS data → render reports and charts. Separate flows estimate current-day cost from CloudWatch metrics and public prices, and send scheduled Telegram or email alerts. The README documents these product capabilities; some implementation details are unsampled, so those relationships are shown only where documented or indexed.

Main entry points: [`src/bedrock_cost/views.py`](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/views.py) (Page routes), [`src/bedrock_cost/alerts.py`](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/alerts.py) (Scheduled alert jobs), [`src/bedrock_cost/cloudwatch_metrics.py`](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cloudwatch_metrics.py) (CloudWatch metrics), [`src/bedrock_cost/mail_alerts.py`](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_alerts.py) (Email alerts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_flask["Flask application<br/>[__init__.py]"]
  node_routes["Page routes<br/>[views.py]"]
end

subgraph group_cost["Cost reporting"]
  node_costdata["Cost Explorer data<br/>[cost_explorer.py]"]
  node_overview["Account cost report<br/>[report.py]"]
  node_usage["Cost usage breakdown<br/>[usage_explorer.py]"]
  node_estimate["Cost estimator<br/>[cost_estimate.py]"]
  node_pricing["Model pricing<br/>[pricing.py]"]
  node_chart["Stacked chart renderer<br/>[chart.py]"]
end

subgraph group_model["Model monitoring"]
  node_metrics["CloudWatch metrics"]
  node_quotas["Model quotas<br/>[quotas.py]"]
end

subgraph group_accounts["Accounts and access"]
  node_auth["Login and protection<br/>[auth.py]"]
  node_ledger[("Account ledger<br/>[excel_source.py]")]
  node_config["Runtime settings<br/>[config.py]"]
end

subgraph group_alerts["Alerts and messaging"]
  node_alertjobs["Scheduled alert jobs<br/>[alerts.py]"]
  node_mailalerts["Email alerts<br/>[mail_alerts.py]"]
  node_mailinbox["Mailbox reader<br/>[mail_inbox.py]"]
  node_mailrules["Mail rules<br/>[mail_rules.py]"]
  node_cards["Alert cards<br/>[cards.py]"]
  node_telegram["Telegram client<br/>[telegram.py]"]
end

node_visitor(("Dashboard user"))
node_awsce{{"AWS Cost Explorer"}}
node_awscw{{"AWS CloudWatch"}}
node_awsbedrock{{"Bedrock and Quotas"}}
node_publicpricing{{"AWS public pricing"}}
node_emailserver{{"Account mail server"}}
node_telegramapi{{"Telegram API"}}

node_visitor -->|"opens dashboard"| node_flask
node_flask -->|"registers login"| node_auth
node_flask -->|"registers routes"| node_routes
node_routes -->|"protects pages"| node_auth
node_routes -->|"loads accounts"| node_ledger
node_routes -->|"builds overview"| node_overview
node_overview -->|"fetches costs"| node_costdata
node_costdata -->|"queries costs"| node_awsce
node_routes -->|"builds breakdown"| node_usage
node_usage -->|"queries costs"| node_awsce
node_routes -->|"renders charts"| node_chart
node_routes -->|"loads model usage"| node_metrics
node_metrics -->|"queries metrics"| node_awscw
node_metrics -->|"resolves profiles"| node_awsbedrock
node_routes -->|"builds quota report"| node_quotas
node_quotas -->|"loads quotas"| node_awsbedrock
node_routes -->|"builds estimate"| node_estimate
node_estimate -->|"reads metrics"| node_metrics
node_estimate -->|"applies prices"| node_pricing
node_pricing -->|"fetches price list"| node_publicpricing
node_routes -->|"uses settings"| node_config
node_alertjobs -->|"loads accounts"| node_ledger
node_alertjobs -->|"fetches costs"| node_costdata
node_alertjobs -->|"reads usage"| node_metrics
node_alertjobs -->|"builds cards"| node_cards
node_alertjobs -->|"sends alerts"| node_telegram
node_telegram -->|"sends messages"| node_telegramapi
node_mailalerts -->|"reads messages"| node_mailinbox
node_mailalerts -->|"applies rules"| node_mailrules
node_mailinbox -->|"reads inbox"| node_emailserver
node_mailalerts -->|"notifies groups"| node_telegram

click node_flask "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/__init__.py"
click node_routes "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/views.py"
click node_auth "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/auth.py"
click node_ledger "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/excel_source.py"
click node_config "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/config.py"
click node_costdata "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cost_explorer.py"
click node_overview "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/report.py"
click node_usage "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/usage_explorer.py"
click node_estimate "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cost_estimate.py"
click node_pricing "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/pricing.py"
click node_chart "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/chart.py"
click node_metrics "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cloudwatch_metrics.py"
click node_quotas "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/quotas.py"
click node_alertjobs "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/alerts.py"
click node_mailalerts "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_alerts.py"
click node_mailinbox "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_inbox.py"
click node_mailrules "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_rules.py"
click node_cards "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cards.py"
click node_telegram "https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/telegram.py"

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_flask,node_routes,node_visitor toneBlue
class node_costdata,node_overview,node_usage,node_estimate,node_pricing,node_chart toneAmber
class node_metrics,node_quotas,node_emailserver,node_telegramapi toneMint
class node_auth,node_ledger,node_config toneRose
class node_alertjobs,node_mailalerts,node_mailinbox,node_mailrules,node_cards,node_telegram,node_awsce,node_awscw,node_awsbedrock,node_publicpricing toneIndigo
```

## Components

### Web application

- [Flask application](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/__init__.py): `src/bedrock_cost/__init__.py`
- [Page routes](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/views.py): `src/bedrock_cost/views.py`

### Cost reporting

- [Cost Explorer data](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cost_explorer.py): `src/bedrock_cost/cost_explorer.py`
- [Account cost report](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/report.py): `src/bedrock_cost/report.py`
- [Cost usage breakdown](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/usage_explorer.py): `src/bedrock_cost/usage_explorer.py`
- [Cost estimator](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cost_estimate.py): `src/bedrock_cost/cost_estimate.py`
- [Model pricing](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/pricing.py): `src/bedrock_cost/pricing.py`
- [Stacked chart renderer](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/chart.py): `src/bedrock_cost/chart.py`

### Model monitoring

- [CloudWatch metrics](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cloudwatch_metrics.py): `src/bedrock_cost/cloudwatch_metrics.py`
- [Model quotas](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/quotas.py): `src/bedrock_cost/quotas.py`

### Accounts and access

- [Login and protection](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/auth.py): `src/bedrock_cost/auth.py`
- [Account ledger](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/excel_source.py): `src/bedrock_cost/excel_source.py`
- [Runtime settings](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/config.py): `src/bedrock_cost/config.py`

### Alerts and messaging

- [Scheduled alert jobs](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/alerts.py): `src/bedrock_cost/alerts.py`
- [Email alerts](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_alerts.py): `src/bedrock_cost/mail_alerts.py`
- [Mailbox reader](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_inbox.py): `src/bedrock_cost/mail_inbox.py`
- [Mail rules](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/mail_rules.py): `src/bedrock_cost/mail_rules.py`
- [Alert cards](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/cards.py): `src/bedrock_cost/cards.py`
- [Telegram client](https://github.com/sdz0z6/bedrock/blob/master/src/bedrock_cost/telegram.py): `src/bedrock_cost/telegram.py`

### Other components

- **Dashboard user**
- **AWS Cost Explorer**
- **AWS CloudWatch**
- **Bedrock and Quotas**
- **AWS public pricing**
- **Account mail server**
- **Telegram API**

## Connections

- Dashboard user → Flask application: opens dashboard (evidence: `README.md`)
- Flask application → Login and protection: registers login (evidence: `src/bedrock_cost/__init__.py`)
- Flask application → Page routes: registers routes (evidence: `src/bedrock_cost/__init__.py`)
- Page routes → Login and protection: protects pages (evidence: `src/bedrock_cost/views.py`)
- Page routes → Account ledger: loads accounts (evidence: `src/bedrock_cost/views.py`)
- Page routes → Account cost report: builds overview (evidence: `README.md`)
- Account cost report → Cost Explorer data: fetches costs (evidence: `src/bedrock_cost/report.py`)
- Cost Explorer data → AWS Cost Explorer: queries costs (evidence: `src/bedrock_cost/cost_explorer.py`)
- Page routes → Cost usage breakdown: builds breakdown (evidence: `src/bedrock_cost/views.py`)
- Cost usage breakdown → AWS Cost Explorer: queries costs (evidence: `src/bedrock_cost/usage_explorer.py`)
- Page routes → Stacked chart renderer: renders charts (evidence: `src/bedrock_cost/views.py`)
- Page routes → CloudWatch metrics: loads model usage (evidence: `src/bedrock_cost/views.py`)
- CloudWatch metrics → AWS CloudWatch: queries metrics (evidence: `src/bedrock_cost/cloudwatch_metrics.py`)
- CloudWatch metrics → Bedrock and Quotas: resolves profiles (evidence: `src/bedrock_cost/cloudwatch_metrics.py`)
- Page routes → Model quotas: builds quota report (evidence: `src/bedrock_cost/views.py`)
- Model quotas → Bedrock and Quotas: loads quotas (evidence: `README.md`)
- Page routes → Cost estimator: builds estimate (evidence: `src/bedrock_cost/views.py`)
- Cost estimator → CloudWatch metrics: reads metrics (evidence: `src/bedrock_cost/cost_estimate.py`)
- Cost estimator → Model pricing: applies prices (evidence: `src/bedrock_cost/cost_estimate.py`)
- Model pricing → AWS public pricing: fetches price list (evidence: `README.md`)
- Page routes → Runtime settings: uses settings (evidence: `src/bedrock_cost/views.py`)
- Scheduled alert jobs → Account ledger: loads accounts (evidence: `src/bedrock_cost/accounts.py`)
- Scheduled alert jobs → Cost Explorer data: fetches costs (evidence: `src/bedrock_cost/alerts.py`)
- Scheduled alert jobs → CloudWatch metrics: reads usage (evidence: `src/bedrock_cost/alerts.py`)
- Scheduled alert jobs → Alert cards: builds cards (evidence: `src/bedrock_cost/alerts.py`)
- Scheduled alert jobs → Telegram client: sends alerts (evidence: `src/bedrock_cost/alerts.py`)
- Telegram client → Telegram API: sends messages (evidence: `src/bedrock_cost/telegram.py`)
- Email alerts → Mailbox reader: reads messages (evidence: `src/bedrock_cost/mail_alerts.py`)
- Email alerts → Mail rules: applies rules (evidence: `src/bedrock_cost/mail_alerts.py`)
- Mailbox reader → Account mail server: reads inbox (evidence: `src/bedrock_cost/mail_inbox.py`)
- Email alerts → Telegram client: notifies groups (evidence: `src/bedrock_cost/mail_alerts.py`)
