# karthiganesun/expense-tracker-api architecture

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

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

## Overview

This is a small FastAPI expense-tracking API. Clients submit expenses or request lists, extrema, individual records, updates, and monthly totals with category breakdowns. Route handlers in main.py delegate operations to CRUD functions; those functions validate and query through SQLAlchemy models, while Pydantic schemas shape request and response data. database.py configures SQLite sessions and the declarative base. The README describes MySQL, but the sampled configuration uses SQLite. Relationships below are limited to routes and calls visible in the excerpts.

Main entry points: [`main.py`](https://github.com/karthiganesun/expense-tracker-api/blob/main/main.py) (Route handlers), [`models.py`](https://github.com/karthiganesun/expense-tracker-api/blob/main/models.py) (Expense model), [`crud.py`](https://github.com/karthiganesun/expense-tracker-api/blob/main/crud.py) (Expense CRUD), [`database.py`](https://github.com/karthiganesun/expense-tracker-api/blob/main/database.py) (Session and engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_routes["Route handlers<br/>[main.py]"]
end

subgraph group_domain["Expense operations"]
  node_crud["Expense CRUD<br/>[crud.py]"]
  node_reports["Expense queries<br/>[crud.py]"]
end

subgraph group_persistence["Persistence and schemas"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
  node_model["Expense model<br/>[models.py]"]
  node_db["Session and engine<br/>[database.py]"]
end

node_client(("API client"))
node_sqlite[("SQLite database")]

node_client -->|"sends requests"| node_routes
node_routes -->|"delegates writes"| node_crud
node_routes -->|"delegates queries"| node_reports
node_routes -->|"injects session"| node_db
node_routes -->|"declares response models"| node_schemas
node_routes -->|"creates tables"| node_model
node_crud -->|"creates and updates"| node_model
node_crud -->|"accepts input"| node_schemas
node_reports -->|"queries expenses"| node_model
node_model -->|"uses declarative base"| node_db
node_db -->|"connects to"| node_sqlite

click node_routes "https://github.com/karthiganesun/expense-tracker-api/blob/main/main.py"
click node_crud "https://github.com/karthiganesun/expense-tracker-api/blob/main/crud.py"
click node_reports "https://github.com/karthiganesun/expense-tracker-api/blob/main/crud.py"
click node_schemas "https://github.com/karthiganesun/expense-tracker-api/blob/main/schemas.py"
click node_model "https://github.com/karthiganesun/expense-tracker-api/blob/main/models.py"
click node_db "https://github.com/karthiganesun/expense-tracker-api/blob/main/database.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_routes,node_client toneBlue
class node_crud,node_reports,node_sqlite toneAmber
class node_schemas,node_model,node_db toneMint
```

## Components

### API layer

- [Route handlers](https://github.com/karthiganesun/expense-tracker-api/blob/main/main.py): `main.py`

### Expense operations

- [Expense CRUD](https://github.com/karthiganesun/expense-tracker-api/blob/main/crud.py): `crud.py`
- [Expense queries](https://github.com/karthiganesun/expense-tracker-api/blob/main/crud.py): `crud.py`

### Persistence and schemas

- [Request and response schemas](https://github.com/karthiganesun/expense-tracker-api/blob/main/schemas.py): `schemas.py`
- [Expense model](https://github.com/karthiganesun/expense-tracker-api/blob/main/models.py): `models.py`
- [Session and engine](https://github.com/karthiganesun/expense-tracker-api/blob/main/database.py): `database.py`

### Other components

- **API client**
- **SQLite database**

## Connections

- API client → Route handlers: sends requests (evidence: `main.py`)
- Route handlers → Expense CRUD: delegates writes (evidence: `main.py`)
- Route handlers → Expense queries: delegates queries (evidence: `main.py`)
- Route handlers → Session and engine: injects session (evidence: `main.py`)
- Route handlers → Request and response schemas: declares response models (evidence: `main.py`)
- Route handlers → Expense model: creates tables (evidence: `main.py`)
- Expense CRUD → Expense model: creates and updates (evidence: `crud.py`)
- Expense CRUD → Request and response schemas: accepts input (evidence: `crud.py`)
- Expense queries → Expense model: queries expenses (evidence: `crud.py`)
- Expense model → Session and engine: uses declarative base (evidence: `models.py`)
- Session and engine → SQLite database: connects to (evidence: `database.py`)
