# salehtl/ledger architecture

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

- Interactive diagram: https://gitdiagram.com/salehtl/ledger
- Repository: https://github.com/salehtl/ledger

## Overview

Ledger is a private, single-user budgeting PWA backed by one Go process and SQLite. Its main workflow reads bank alerts from a read-only IMAP mailbox, parses and categorizes transactions, stores them, and serves budget state to the PWA over HTTP and live updates. The product also supports historical imports, review and transaction management, accounts, projects, recurring charges, reports, insights, and ingest monitoring with alerts. Relationships use README statements or shown frontend calls; several backend resource and integration links are documented at package level rather than verified in sampled handlers.

Main entry points: [`frontend/src/api/client.ts`](https://github.com/salehtl/ledger/blob/main/frontend/src/api/client.ts) (API client), [`internal/server`](https://github.com/salehtl/ledger/tree/main/internal/server) (HTTP and live API), [`frontend/src/app/AppShell.tsx`](https://github.com/salehtl/ledger/blob/main/frontend/src/app/AppShell.tsx) (Budget PWA), [`internal/store`](https://github.com/salehtl/ledger/tree/main/internal/store) (SQLite store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Email intake"]
  node_imap["IMAP worker"]
  node_parser["Parse cascade"]
  node_categorizer["Categorization"]
  node_classifier["AI classifier"]
  node_importer["Historical import"]
end

subgraph group_backend["Ledger services"]
  node_api["HTTP and live API"]
  node_csv["CSV export<br/>[export.go]"]
end

subgraph group_storage["Persistent data"]
  node_db[("SQLite store")]
end

subgraph group_frontend["PWA experience"]
  node_pwa["Budget PWA<br/>[AppShell.tsx]"]
  node_httpclient["API client<br/>[client.ts]"]
  node_health["Ingest health UI"]
  node_transactions["Transactions and review<br/>[Transactions.tsx]"]
  node_home["Budget home<br/>[Home.tsx]"]
  node_insights["Insights and reports<br/>[Insights.tsx]"]
  node_settings["Settings and rules<br/>[SettingsPage.tsx]"]
  node_accounts["Accounts and balances"]
  node_projects["Projects"]
  node_recurringui["Recurring charges"]
  node_reports["Financial reports"]
end

subgraph group_extras["Planning and reporting"]
  node_budget["Budget math"]
  node_recurring["Recurring detection"]
  node_monitor["Ingest monitoring"]
  node_push["Web Push"]
end

node_mail(("Bank email"))
node_ai{{"AI provider"}}
node_browser(("User"))

node_mail -->|"arrives in"| node_imap
node_imap -->|"submits messages"| node_parser
node_parser -->|"passes transactions"| node_categorizer
node_parser -->|"checks classification"| node_classifier
node_categorizer -->|"categorizes unknowns"| node_classifier
node_classifier -->|"requests classification"| node_ai
node_categorizer -->|"stores results"| node_db
node_imap -->|"retains raw bodies"| node_db
node_importer -->|"backfills history"| node_db
node_api -->|"reads and writes"| node_db
node_budget -->|"uses transactions"| node_db
node_recurring -->|"checks history"| node_db
node_monitor -->|"publishes drift alerts"| node_api
node_api -->|"sends alerts"| node_push
node_browser -->|"uses"| node_pwa
node_pwa -->|"requests data"| node_httpclient
node_httpclient -->|"calls HTTP API"| node_api
node_api -->|"streams live updates"| node_pwa
node_pwa -->|"shows budget"| node_home
node_pwa -->|"opens transactions"| node_transactions
node_pwa -->|"opens insights"| node_insights
node_httpclient -->|"fetches health"| node_health
node_httpclient -.->|"serves transaction actions"| node_transactions
node_httpclient -.->|"serves settings"| node_settings
node_httpclient -.->|"serves account data"| node_accounts
node_httpclient -.->|"serves project data"| node_projects
node_httpclient -.->|"serves schedules"| node_recurringui
node_httpclient -.->|"serves reports"| node_reports
node_httpclient -.->|"requests export"| node_csv
node_api -.->|"exposes budget state"| node_budget
node_api -.->|"exposes recurring results"| node_recurring

click node_imap "https://github.com/salehtl/ledger/tree/main/internal/ingest"
click node_parser "https://github.com/salehtl/ledger/tree/main/internal/parse"
click node_categorizer "https://github.com/salehtl/ledger/tree/main/internal/categorize"
click node_classifier "https://github.com/salehtl/ledger/tree/main/internal/classify"
click node_importer "https://github.com/salehtl/ledger/tree/main/internal/importer"
click node_api "https://github.com/salehtl/ledger/tree/main/internal/server"
click node_db "https://github.com/salehtl/ledger/tree/main/internal/store"
click node_budget "https://github.com/salehtl/ledger/tree/main/internal/budget"
click node_recurring "https://github.com/salehtl/ledger/tree/main/internal/recur"
click node_monitor "https://github.com/salehtl/ledger/tree/main/internal/monitor"
click node_push "https://github.com/salehtl/ledger/tree/main/internal/push"
click node_pwa "https://github.com/salehtl/ledger/blob/main/frontend/src/app/AppShell.tsx"
click node_httpclient "https://github.com/salehtl/ledger/blob/main/frontend/src/api/client.ts"
click node_health "https://github.com/salehtl/ledger/blob/main/frontend/src/screens/settings/IngestHealthPage.tsx"
click node_transactions "https://github.com/salehtl/ledger/blob/main/frontend/src/screens/Transactions.tsx"
click node_home "https://github.com/salehtl/ledger/blob/main/frontend/src/screens/Home.tsx"
click node_insights "https://github.com/salehtl/ledger/blob/main/frontend/src/screens/Insights.tsx"
click node_settings "https://github.com/salehtl/ledger/blob/main/frontend/src/screens/settings/SettingsPage.tsx"
click node_accounts "https://github.com/salehtl/ledger/tree/main/frontend/src/screens/accounts"
click node_projects "https://github.com/salehtl/ledger/tree/main/frontend/src/screens/projects"
click node_recurringui "https://github.com/salehtl/ledger/tree/main/frontend/src/screens/recurring"
click node_reports "https://github.com/salehtl/ledger/tree/main/frontend/src/screens/reports"
click node_csv "https://github.com/salehtl/ledger/blob/main/internal/server/export.go"

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_imap,node_parser,node_categorizer,node_classifier,node_importer,node_browser toneBlue
class node_api,node_csv toneAmber
class node_db toneMint
class node_pwa,node_httpclient,node_health,node_transactions,node_home,node_insights,node_settings,node_accounts,node_projects,node_recurringui,node_reports toneRose
class node_budget,node_recurring,node_monitor,node_push,node_mail,node_ai toneIndigo
```

## Components

### Email intake

- [IMAP worker](https://github.com/salehtl/ledger/tree/main/internal/ingest): `internal/ingest`
- [Parse cascade](https://github.com/salehtl/ledger/tree/main/internal/parse): `internal/parse`
- [Categorization](https://github.com/salehtl/ledger/tree/main/internal/categorize): `internal/categorize`
- [AI classifier](https://github.com/salehtl/ledger/tree/main/internal/classify): `internal/classify`
- [Historical import](https://github.com/salehtl/ledger/tree/main/internal/importer): `internal/importer`

### Ledger services

- [HTTP and live API](https://github.com/salehtl/ledger/tree/main/internal/server): `internal/server`
- [CSV export](https://github.com/salehtl/ledger/blob/main/internal/server/export.go): `internal/server/export.go`

### Persistent data

- [SQLite store](https://github.com/salehtl/ledger/tree/main/internal/store): `internal/store`

### PWA experience

- [Budget PWA](https://github.com/salehtl/ledger/blob/main/frontend/src/app/AppShell.tsx): `frontend/src/app/AppShell.tsx`
- [API client](https://github.com/salehtl/ledger/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [Ingest health UI](https://github.com/salehtl/ledger/blob/main/frontend/src/screens/settings/IngestHealthPage.tsx): `frontend/src/screens/settings/IngestHealthPage.tsx`
- [Transactions and review](https://github.com/salehtl/ledger/blob/main/frontend/src/screens/Transactions.tsx): `frontend/src/screens/Transactions.tsx`
- [Budget home](https://github.com/salehtl/ledger/blob/main/frontend/src/screens/Home.tsx): `frontend/src/screens/Home.tsx`
- [Insights and reports](https://github.com/salehtl/ledger/blob/main/frontend/src/screens/Insights.tsx): `frontend/src/screens/Insights.tsx`
- [Settings and rules](https://github.com/salehtl/ledger/blob/main/frontend/src/screens/settings/SettingsPage.tsx): `frontend/src/screens/settings/SettingsPage.tsx`
- [Accounts and balances](https://github.com/salehtl/ledger/tree/main/frontend/src/screens/accounts): `frontend/src/screens/accounts`
- [Projects](https://github.com/salehtl/ledger/tree/main/frontend/src/screens/projects): `frontend/src/screens/projects`
- [Recurring charges](https://github.com/salehtl/ledger/tree/main/frontend/src/screens/recurring): `frontend/src/screens/recurring`
- [Financial reports](https://github.com/salehtl/ledger/tree/main/frontend/src/screens/reports): `frontend/src/screens/reports`

### Planning and reporting

- [Budget math](https://github.com/salehtl/ledger/tree/main/internal/budget): `internal/budget`
- [Recurring detection](https://github.com/salehtl/ledger/tree/main/internal/recur): `internal/recur`
- [Ingest monitoring](https://github.com/salehtl/ledger/tree/main/internal/monitor): `internal/monitor`
- [Web Push](https://github.com/salehtl/ledger/tree/main/internal/push): `internal/push`

### Other components

- **Bank email**
- **AI provider**
- **User**

## Connections

- Bank email → IMAP worker: arrives in
- IMAP worker → Parse cascade: submits messages
- Parse cascade → Categorization: passes transactions
- Parse cascade → AI classifier: checks classification
- Categorization → AI classifier: categorizes unknowns
- AI classifier → AI provider: requests classification
- Categorization → SQLite store: stores results
- IMAP worker → SQLite store: retains raw bodies
- Historical import → SQLite store: backfills history
- HTTP and live API → SQLite store: reads and writes
- Budget math → SQLite store: uses transactions
- Recurring detection → SQLite store: checks history
- Ingest monitoring → HTTP and live API: publishes drift alerts
- HTTP and live API → Web Push: sends alerts
- User → Budget PWA: uses
- Budget PWA → API client: requests data (evidence: `frontend/src/app/AppShell.tsx`)
- API client → HTTP and live API: calls HTTP API (evidence: `frontend/src/api/client.ts`)
- HTTP and live API → Budget PWA: streams live updates
- Budget PWA → Budget home: shows budget (evidence: `frontend/src/app/AppShell.tsx`)
- Budget PWA → Transactions and review: opens transactions (evidence: `frontend/src/app/AppShell.tsx`)
- Budget PWA → Insights and reports: opens insights (evidence: `frontend/src/app/AppShell.tsx`)
- API client → Ingest health UI: fetches health (evidence: `frontend/src/screens/settings/IngestHealthPage.tsx`)
- API client → Transactions and review: serves transaction actions
- API client → Settings and rules: serves settings
- API client → Accounts and balances: serves account data
- API client → Projects: serves project data
- API client → Recurring charges: serves schedules
- API client → Financial reports: serves reports
- API client → CSV export: requests export
- HTTP and live API → Budget math: exposes budget state
- HTTP and live API → Recurring detection: exposes recurring results
