# kunalsambyal/expense-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/kunalsambyal/expense-tracker
- Repository: https://github.com/kunalsambyal/expense-tracker

## Overview

This is a full-stack, multi-user expense tracker: users register or sign in, manage categories and expenses, then review spending summaries and optional AI-generated advice in a Streamlit dashboard. The backend exposes FastAPI endpoints, applies user-scoped services and validation, and persists records through async SQLAlchemy. The README documents analytics and local Ollama integration, but the expense endpoint and AI orchestration source were not excerpted; those links are shown as unverified rather than asserted as inspected.

Main entry points: [`backend/main.py`](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/main.py) (FastAPI app), [`backend/app/api/v1/endpoints/auth.py`](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/auth.py) (Auth endpoints), [`backend/app/api/v1/endpoints/categories.py`](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/categories.py) (Category endpoints), [`backend/app/api/v1/endpoints/expenses.py`](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/expenses.py) (Expense endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Streamlit client"]
  node_frontend["Dashboard UI<br/>[main.py]"]
  node_client_api["HTTP API client<br/>[api_client.py]"]
end

subgraph group_api["API and identity"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_auth_api["Auth endpoints<br/>[auth.py]"]
  node_users_api["User endpoints<br/>[users.py]"]
  node_categories_api["Category endpoints<br/>[categories.py]"]
  node_expenses_api["Expense endpoints<br/>[expenses.py]"]
  node_user_service["User service<br/>[user_service.py]"]
  node_security["JWT and hashing<br/>[security.py]"]
  node_schemas["Request and response schemas"]
  node_exceptions["API error handling<br/>[exceptions.py]"]
end

subgraph group_domain["Expense domain"]
  node_category_service["Category service"]
  node_expense_service["Expense service<br/>[expense_service.py]"]
  node_ai_service["AI advisor<br/>[ai_service.py]"]
end

subgraph group_data["Persistence and insights"]
  node_session["Async DB session<br/>[session.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_models["User, category, expense models"]
  node_database[("PostgreSQL database")]
end

node_user(("User"))
node_ollama{{"Local Ollama"}}

node_user -->|"uses"| node_frontend
node_frontend -->|"calls"| node_client_api
node_client_api -->|"sends HTTP"| node_fastapi
node_fastapi -->|"mounts"| node_auth_api
node_fastapi -->|"mounts"| node_users_api
node_fastapi -->|"mounts"| node_categories_api
node_fastapi -->|"mounts"| node_expenses_api
node_fastapi -->|"configures"| node_exceptions
node_auth_api -->|"calls"| node_user_service
node_auth_api -->|"creates token"| node_security
node_user_service -->|"hashes passwords"| node_security
node_categories_api -->|"calls"| node_category_service
node_categories_api -->|"gets session"| node_session
node_user_service -->|"queries"| node_session
node_category_service -->|"reads and writes"| node_models
node_expense_service -->|"reads and writes"| node_models
node_user_service -->|"queries"| node_models
node_session -->|"reads settings"| node_config
node_fastapi -->|"opens database"| node_session
node_models -->|"maps records"| node_database
node_auth_api -->|"validates and returns"| node_schemas
node_categories_api -->|"uses schemas"| node_schemas
node_expenses_api -.->|"delegates"| node_expense_service
node_expenses_api -.->|"uses schemas"| node_schemas
node_expenses_api -.->|"requests insights"| node_ai_service
node_ai_service -->|"requests advice"| node_ollama
node_ai_service -.->|"uses aggregations"| node_expense_service

click node_frontend "https://github.com/kunalsambyal/expense-tracker/blob/main/frontend/main.py"
click node_client_api "https://github.com/kunalsambyal/expense-tracker/blob/main/frontend/api_client.py"
click node_fastapi "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/main.py"
click node_auth_api "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/auth.py"
click node_users_api "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/users.py"
click node_categories_api "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/categories.py"
click node_expenses_api "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/expenses.py"
click node_user_service "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/user_service.py"
click node_category_service "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/category_service.py"
click node_expense_service "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/expense_service.py"
click node_security "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/core/security.py"
click node_schemas "https://github.com/kunalsambyal/expense-tracker/tree/main/backend/app/schemas"
click node_session "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/db/session.py"
click node_config "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/core/config.py"
click node_models "https://github.com/kunalsambyal/expense-tracker/tree/main/backend/app/models"
click node_exceptions "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/core/exceptions.py"
click node_ai_service "https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/ai_service.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_frontend,node_client_api,node_user toneBlue
class node_fastapi,node_auth_api,node_users_api,node_categories_api,node_expenses_api,node_user_service,node_security,node_schemas,node_exceptions toneAmber
class node_category_service,node_expense_service,node_ai_service toneMint
class node_session,node_config,node_models,node_database toneRose
class node_ollama toneIndigo
```

## Components

### Streamlit client

- [Dashboard UI](https://github.com/kunalsambyal/expense-tracker/blob/main/frontend/main.py): `frontend/main.py`
- [HTTP API client](https://github.com/kunalsambyal/expense-tracker/blob/main/frontend/api_client.py): `frontend/api_client.py`

### API and identity

- [FastAPI app](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/main.py): `backend/main.py`
- [Auth endpoints](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/auth.py): `backend/app/api/v1/endpoints/auth.py`
- [User endpoints](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/users.py): `backend/app/api/v1/endpoints/users.py`
- [Category endpoints](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/categories.py): `backend/app/api/v1/endpoints/categories.py`
- [Expense endpoints](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/api/v1/endpoints/expenses.py): `backend/app/api/v1/endpoints/expenses.py`
- [User service](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/user_service.py): `backend/app/services/user_service.py`
- [JWT and hashing](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Request and response schemas](https://github.com/kunalsambyal/expense-tracker/tree/main/backend/app/schemas): `backend/app/schemas`
- [API error handling](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/core/exceptions.py): `backend/app/core/exceptions.py`

### Expense domain

- [Category service](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/category_service.py): `backend/app/services/category_service.py`
- [Expense service](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/expense_service.py): `backend/app/services/expense_service.py`
- [AI advisor](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/services/ai_service.py): `backend/app/services/ai_service.py`

### Persistence and insights

- [Async DB session](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/db/session.py): `backend/app/db/session.py`
- [Runtime configuration](https://github.com/kunalsambyal/expense-tracker/blob/main/backend/app/core/config.py): `backend/app/core/config.py`
- [User, category, expense models](https://github.com/kunalsambyal/expense-tracker/tree/main/backend/app/models): `backend/app/models`
- **PostgreSQL database**

### Other components

- **User**
- **Local Ollama**

## Connections

- User → Dashboard UI: uses (evidence: `README.md`)
- Dashboard UI → HTTP API client: calls (evidence: `frontend/main.py`)
- HTTP API client → FastAPI app: sends HTTP (evidence: `frontend/api_client.py`)
- FastAPI app → Auth endpoints: mounts (evidence: `backend/main.py`)
- FastAPI app → User endpoints: mounts (evidence: `backend/main.py`)
- FastAPI app → Category endpoints: mounts (evidence: `backend/main.py`)
- FastAPI app → Expense endpoints: mounts (evidence: `backend/main.py`)
- FastAPI app → API error handling: configures (evidence: `backend/main.py`)
- Auth endpoints → User service: calls (evidence: `backend/app/api/v1/endpoints/auth.py`)
- Auth endpoints → JWT and hashing: creates token (evidence: `backend/app/api/v1/endpoints/auth.py`)
- User service → JWT and hashing: hashes passwords (evidence: `backend/app/services/user_service.py`)
- Category endpoints → Category service: calls (evidence: `backend/app/api/v1/endpoints/categories.py`)
- Category endpoints → Async DB session: gets session (evidence: `backend/app/api/v1/endpoints/categories.py`)
- User service → Async DB session: queries (evidence: `backend/app/services/user_service.py`)
- Category service → User, category, expense models: reads and writes (evidence: `backend/app/services/category_service.py`)
- Expense service → User, category, expense models: reads and writes (evidence: `backend/app/services/expense_service.py`)
- User service → User, category, expense models: queries (evidence: `backend/app/services/user_service.py`)
- Async DB session → Runtime configuration: reads settings (evidence: `backend/app/db/session.py`)
- FastAPI app → Async DB session: opens database (evidence: `backend/main.py`)
- User, category, expense models → PostgreSQL database: maps records (evidence: `README.md`)
- Auth endpoints → Request and response schemas: validates and returns (evidence: `backend/app/api/v1/endpoints/auth.py`)
- Category endpoints → Request and response schemas: uses schemas (evidence: `backend/app/api/v1/endpoints/categories.py`)
- Expense endpoints → Expense service: delegates
- Expense endpoints → Request and response schemas: uses schemas
- Expense endpoints → AI advisor: requests insights
- AI advisor → Local Ollama: requests advice (evidence: `README.md`)
- AI advisor → Expense service: uses aggregations
