# aalluinmar/expense-tracker-api architecture

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

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

## Overview

Expense Tracker API is a FastAPI service for registering users, issuing JWT bearer tokens, and managing expenses. A client reaches the mounted auth and expense routers; request handlers validate payloads, apply authentication where required, and use SQLAlchemy sessions to read or change PostgreSQL data. Authentication and expense handling are distinct domain stages, supported by shared security, schemas, models, and database configuration. The README describes the overall router-to-view-to-database architecture; source excerpts show the concrete calls and imports. Unsampled configuration and runtime details are not expanded.

Main entry points: [`app/database.py`](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/database.py) (Database sessions), [`app/views/auth.py`](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/views/auth.py) (Auth handlers), [`app/security.py`](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/security.py) (Authentication security), [`app/main.py`](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API routing"]
  node_application["FastAPI application<br/>[main.py]"]
  node_auth_router["Auth router<br/>[auth.py]"]
  node_expense_router["Expense router<br/>[expenses.py]"]
end

subgraph group_domain["Request handling"]
  node_auth_handlers["Auth handlers<br/>[auth.py]"]
  node_expense_handlers["Expense handlers<br/>[expenses.py]"]
end

subgraph group_shared["Shared services"]
  node_schemas["Request schemas<br/>[schemas.py]"]
  node_security["Authentication security<br/>[security.py]"]
  node_configuration["Environment settings<br/>[config.py]"]
end

subgraph group_persistence["Persistence"]
  node_database["Database sessions<br/>[database.py]"]
  node_models["User and expense models<br/>[models.py]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_application
node_application -->|"mounts routes"| node_auth_router
node_application -->|"mounts routes"| node_expense_router
node_application -->|"creates tables"| node_database
node_auth_router -->|"registers handlers"| node_auth_handlers
node_expense_router -->|"registers handlers"| node_expense_handlers
node_expense_router -->|"requires user"| node_security
node_auth_handlers -->|"gets session"| node_database
node_auth_handlers -->|"queries users"| node_models
node_auth_handlers -->|"validates payloads"| node_schemas
node_auth_handlers -->|"hashes and issues tokens"| node_security
node_expense_handlers -->|"gets session"| node_database
node_expense_handlers -->|"reads and changes"| node_models
node_expense_handlers -->|"validates payloads"| node_schemas
node_security -->|"gets session"| node_database
node_security -->|"looks up user"| node_models
node_security -->|"uses token settings"| node_configuration
node_database -->|"loads connection settings"| node_configuration
node_models -->|"uses declarative base"| node_database
node_database -->|"connects to"| node_postgres

click node_application "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/main.py"
click node_auth_router "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/routers/auth.py"
click node_expense_router "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/routers/expenses.py"
click node_auth_handlers "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/views/auth.py"
click node_expense_handlers "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/views/expenses.py"
click node_schemas "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/schemas.py"
click node_security "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/security.py"
click node_configuration "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/config.py"
click node_database "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/database.py"
click node_models "https://github.com/aalluinmar/expense-tracker-api/blob/main/app/models.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_application,node_auth_router,node_expense_router,node_client toneBlue
class node_auth_handlers,node_expense_handlers,node_postgres toneAmber
class node_schemas,node_security,node_configuration toneMint
class node_database,node_models toneRose
```

## Components

### API routing

- [FastAPI application](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/main.py): `app/main.py`
- [Auth router](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/routers/auth.py): `app/routers/auth.py`
- [Expense router](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/routers/expenses.py): `app/routers/expenses.py`

### Request handling

- [Auth handlers](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/views/auth.py): `app/views/auth.py`
- [Expense handlers](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/views/expenses.py): `app/views/expenses.py`

### Shared services

- [Request schemas](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/schemas.py): `app/schemas.py`
- [Authentication security](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/security.py): `app/security.py`
- [Environment settings](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/config.py): `app/config.py`

### Persistence

- [Database sessions](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/database.py): `app/database.py`
- [User and expense models](https://github.com/aalluinmar/expense-tracker-api/blob/main/app/models.py): `app/models.py`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → FastAPI application: sends requests (evidence: `README.md`)
- FastAPI application → Auth router: mounts routes (evidence: `app/main.py`)
- FastAPI application → Expense router: mounts routes (evidence: `app/main.py`)
- FastAPI application → Database sessions: creates tables (evidence: `app/main.py`)
- Auth router → Auth handlers: registers handlers (evidence: `app/routers/auth.py`)
- Expense router → Expense handlers: registers handlers (evidence: `app/routers/expenses.py`)
- Expense router → Authentication security: requires user (evidence: `app/routers/expenses.py`)
- Auth handlers → Database sessions: gets session (evidence: `app/views/auth.py`)
- Auth handlers → User and expense models: queries users (evidence: `app/views/auth.py`)
- Auth handlers → Request schemas: validates payloads (evidence: `app/views/auth.py`)
- Auth handlers → Authentication security: hashes and issues tokens (evidence: `app/views/auth.py`)
- Expense handlers → Database sessions: gets session (evidence: `app/views/expenses.py`)
- Expense handlers → User and expense models: reads and changes (evidence: `app/views/expenses.py`)
- Expense handlers → Request schemas: validates payloads (evidence: `app/views/expenses.py`)
- Authentication security → Database sessions: gets session (evidence: `app/security.py`)
- Authentication security → User and expense models: looks up user (evidence: `app/security.py`)
- Authentication security → Environment settings: uses token settings (evidence: `app/security.py`)
- Database sessions → Environment settings: loads connection settings (evidence: `app/database.py`)
- User and expense models → Database sessions: uses declarative base (evidence: `app/models.py`)
- Database sessions → PostgreSQL: connects to (evidence: `README.md`)
