# fissionlife/expencetracker architecture

> Architecture diagram of the GitHub repository fissionlife/expencetracker, 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/fissionlife/expencetracker
- Repository: https://github.com/fissionlife/expencetracker

## Overview

WalletLedger is a Telegram-first expense tracker: people send plain-language transactions or statements, the bot’s agent interprets requests and uses ledger tools, and deterministic guardrails check actions and replies. The same ledger powers analytics, charts, and a signed-link dashboard; onboarding and user-managed AI keys support setup. The graph also shows database and encryption layers. Some connections are documented only by the README or SOURCE INDEX; unsampled implementation details are not inferred.

Main entry points: [`app/services/ledger.py`](https://github.com/fissionlife/expencetracker/blob/main/app/services/ledger.py) (Ledger operations), [`app/bot/agent.py`](https://github.com/fissionlife/expencetracker/blob/main/app/bot/agent.py) (Conversation agent), [`app/bot/main.py`](https://github.com/fissionlife/expencetracker/blob/main/app/bot/main.py) (Message router), [`app/db.py`](https://github.com/fissionlife/expencetracker/blob/main/app/db.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App entry and bot"]
  node_telegram["Telegram adapter<br/>[telegram.py]"]
  node_bot["Message router<br/>[main.py]"]
  node_onboarding["Onboarding<br/>[onboarding.py]"]
  node_app["FastAPI app<br/>[main.py]"]
end

subgraph group_ai["AI and controls"]
  node_agent["Conversation agent<br/>[agent.py]"]
  node_guardrails["Guardrails<br/>[guardrails.py]"]
  node_keys["AI key management<br/>[keys.py]"]
  node_gateway["LLM gateway<br/>[ai_gateway.py]"]
  node_parser["Statement parser"]
  node_toolclient["Tool client<br/>[tool_client.py]"]
  node_mcp["MCP tool server<br/>[mcp_server.py]"]
end

subgraph group_finance["Ledger and insights"]
  node_ledger["Ledger operations<br/>[ledger.py]"]
  node_analytics["Financial analytics<br/>[analytics.py]"]
  node_views["Bot screens and charts<br/>[views.py]"]
  node_dashboard["Web dashboard<br/>[dashboard.py]"]
end

subgraph group_platform["Data and security"]
  node_db[("Database access<br/>[db.py]")]
  node_models["Finance and user models<br/>[models.py]"]
  node_crypto["Encryption at rest<br/>[crypto.py]"]
  node_config["Configuration<br/>[config.py]"]
end

node_person(("Telegram user"))
node_external_llm{{"AI providers"}}

node_person -->|"sends messages"| node_telegram
node_telegram -->|"routes updates"| node_bot
node_bot -->|"handles messages"| node_agent
node_bot -->|"parses statements"| node_parser
node_bot -->|"starts setup"| node_onboarding
node_agent -->|"checks actions"| node_guardrails
node_agent -->|"requests completions"| node_gateway
node_agent -->|"calls tools"| node_toolclient
node_agent -->|"uses ledger"| node_ledger
node_keys -->|"manages keys"| node_gateway
node_gateway -.->|"calls models"| node_external_llm
node_toolclient -.->|"calls over stdio"| node_mcp
node_toolclient -->|"runs direct tools"| node_ledger
node_mcp -->|"dispatches tools"| node_ledger
node_ledger -->|"reads and writes"| node_db
node_analytics -->|"queries records"| node_db
node_views -->|"builds reports"| node_analytics
node_views -->|"reads balances"| node_ledger
node_dashboard -->|"builds reports"| node_analytics
node_dashboard -->|"reads ledger"| node_ledger
node_app -->|"starts adapter"| node_telegram
node_app -->|"mounts router"| node_bot
node_app -->|"mounts router"| node_dashboard
node_app -->|"initializes database"| node_db
node_db -->|"creates tables"| node_models
node_models -->|"encrypts fields"| node_crypto
node_config -->|"configures database"| node_db
node_config -->|"supplies secret"| node_crypto
node_gateway -->|"protects API keys"| node_crypto

click node_telegram "https://github.com/fissionlife/expencetracker/blob/main/app/bot/telegram.py"
click node_bot "https://github.com/fissionlife/expencetracker/blob/main/app/bot/main.py"
click node_onboarding "https://github.com/fissionlife/expencetracker/blob/main/app/bot/onboarding.py"
click node_agent "https://github.com/fissionlife/expencetracker/blob/main/app/bot/agent.py"
click node_guardrails "https://github.com/fissionlife/expencetracker/blob/main/app/bot/guardrails.py"
click node_keys "https://github.com/fissionlife/expencetracker/blob/main/app/bot/keys.py"
click node_gateway "https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/ai_gateway.py"
click node_parser "https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/transaction_parser.py"
click node_toolclient "https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/tool_client.py"
click node_mcp "https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/mcp_server.py"
click node_ledger "https://github.com/fissionlife/expencetracker/blob/main/app/services/ledger.py"
click node_analytics "https://github.com/fissionlife/expencetracker/blob/main/app/services/analytics.py"
click node_views "https://github.com/fissionlife/expencetracker/blob/main/app/bot/views.py"
click node_dashboard "https://github.com/fissionlife/expencetracker/blob/main/app/web/dashboard.py"
click node_app "https://github.com/fissionlife/expencetracker/blob/main/main.py"
click node_db "https://github.com/fissionlife/expencetracker/blob/main/app/db.py"
click node_models "https://github.com/fissionlife/expencetracker/blob/main/app/models.py"
click node_crypto "https://github.com/fissionlife/expencetracker/blob/main/app/crypto.py"
click node_config "https://github.com/fissionlife/expencetracker/blob/main/app/config.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_telegram,node_bot,node_onboarding,node_app,node_person toneBlue
class node_agent,node_guardrails,node_keys,node_gateway,node_parser,node_toolclient,node_mcp toneAmber
class node_ledger,node_analytics,node_views,node_dashboard toneMint
class node_db,node_models,node_crypto,node_config toneRose
class node_external_llm toneIndigo
```

## Components

### App entry and bot

- [Telegram adapter](https://github.com/fissionlife/expencetracker/blob/main/app/bot/telegram.py): `app/bot/telegram.py`
- [Message router](https://github.com/fissionlife/expencetracker/blob/main/app/bot/main.py): `app/bot/main.py`
- [Onboarding](https://github.com/fissionlife/expencetracker/blob/main/app/bot/onboarding.py): `app/bot/onboarding.py`
- [FastAPI app](https://github.com/fissionlife/expencetracker/blob/main/main.py): `main.py`

### AI and controls

- [Conversation agent](https://github.com/fissionlife/expencetracker/blob/main/app/bot/agent.py): `app/bot/agent.py`
- [Guardrails](https://github.com/fissionlife/expencetracker/blob/main/app/bot/guardrails.py): `app/bot/guardrails.py`
- [AI key management](https://github.com/fissionlife/expencetracker/blob/main/app/bot/keys.py): `app/bot/keys.py`
- [LLM gateway](https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/ai_gateway.py): `app/services_ai/ai_gateway.py`
- [Statement parser](https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/transaction_parser.py): `app/services_ai/transaction_parser.py`
- [Tool client](https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/tool_client.py): `app/services_ai/tool_client.py`
- [MCP tool server](https://github.com/fissionlife/expencetracker/blob/main/app/services_ai/mcp_server.py): `app/services_ai/mcp_server.py`

### Ledger and insights

- [Ledger operations](https://github.com/fissionlife/expencetracker/blob/main/app/services/ledger.py): `app/services/ledger.py`
- [Financial analytics](https://github.com/fissionlife/expencetracker/blob/main/app/services/analytics.py): `app/services/analytics.py`
- [Bot screens and charts](https://github.com/fissionlife/expencetracker/blob/main/app/bot/views.py): `app/bot/views.py`
- [Web dashboard](https://github.com/fissionlife/expencetracker/blob/main/app/web/dashboard.py): `app/web/dashboard.py`

### Data and security

- [Database access](https://github.com/fissionlife/expencetracker/blob/main/app/db.py): `app/db.py`
- [Finance and user models](https://github.com/fissionlife/expencetracker/blob/main/app/models.py): `app/models.py`
- [Encryption at rest](https://github.com/fissionlife/expencetracker/blob/main/app/crypto.py): `app/crypto.py`
- [Configuration](https://github.com/fissionlife/expencetracker/blob/main/app/config.py): `app/config.py`

### Other components

- **Telegram user**
- **AI providers**

## Connections

- Telegram user → Telegram adapter: sends messages
- Telegram adapter → Message router: routes updates (evidence: `app/bot/telegram.py`)
- Message router → Conversation agent: handles messages (evidence: `app/bot/main.py`)
- Message router → Statement parser: parses statements (evidence: `app/bot/main.py`)
- Message router → Onboarding: starts setup (evidence: `app/bot/main.py`)
- Conversation agent → Guardrails: checks actions (evidence: `app/bot/agent.py`)
- Conversation agent → LLM gateway: requests completions (evidence: `app/bot/agent.py`)
- Conversation agent → Tool client: calls tools (evidence: `app/bot/agent.py`)
- Conversation agent → Ledger operations: uses ledger (evidence: `app/bot/agent.py`)
- AI key management → LLM gateway: manages keys (evidence: `app/bot/keys.py`)
- LLM gateway → AI providers: calls models
- Tool client → MCP tool server: calls over stdio (evidence: `app/services_ai/tool_client.py`)
- Tool client → Ledger operations: runs direct tools (evidence: `app/services_ai/tool_client.py`)
- MCP tool server → Ledger operations: dispatches tools (evidence: `app/services_ai/mcp_server.py`)
- Ledger operations → Database access: reads and writes (evidence: `app/services/ledger.py`)
- Financial analytics → Database access: queries records (evidence: `app/services/analytics.py`)
- Bot screens and charts → Financial analytics: builds reports (evidence: `app/bot/views.py`)
- Bot screens and charts → Ledger operations: reads balances (evidence: `app/bot/views.py`)
- Web dashboard → Financial analytics: builds reports (evidence: `app/web/dashboard.py`)
- Web dashboard → Ledger operations: reads ledger (evidence: `app/web/dashboard.py`)
- FastAPI app → Telegram adapter: starts adapter (evidence: `main.py`)
- FastAPI app → Message router: mounts router (evidence: `main.py`)
- FastAPI app → Web dashboard: mounts router (evidence: `main.py`)
- FastAPI app → Database access: initializes database (evidence: `main.py`)
- Database access → Finance and user models: creates tables (evidence: `app/db.py`)
- Finance and user models → Encryption at rest: encrypts fields (evidence: `app/models.py`)
- Configuration → Database access: configures database (evidence: `app/db.py`)
- Configuration → Encryption at rest: supplies secret (evidence: `app/crypto.py`)
- LLM gateway → Encryption at rest: protects API keys (evidence: `app/services_ai/ai_gateway.py`)
