# yenchenglai/expense-tracker-v2 architecture

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

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

## Overview

##### Project type and purpose
- This is a full-stack web application (“expense-tracker-v2”) for personal/family expense tracking.
- Frontend: a React (Vite) SPA.
- Backend: two FastAPI microservices (auth-service and expense-service).
- Database: MongoDB.
- Purpose: allow users to sign up/log in, record and view expenses, manage settings.

##### File structure
- Top-level:
- backend/
– auth-service/app: authentication endpoints, user models, database connectivity.
– expense-service/app: expense CRUD endpoints, models, database connectivity.
– generate_hash.py, requirements.txt, makefile: utilities and build scripts.
- frontend/: React app under src/components, Vite config, package.json.
- docs/: architecture.md, deployment notes, requirements.
- Patterns:
- Microservices (auth vs expense).
- Clear separation of frontend vs backend.
- Each service has its own tests, README, and pytest config.
- Likely communicates via HTTP REST + JWT.

##### README for additional insights
- Stack: FastAPI, React, MongoDB.
- README references architecture.md in docs → likely contains more details.
- No monolithic backend: two independent services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        Browser["React SPA"]:::client
        MainJS["main.jsx"]:::client
        AppJS["App.jsx"]:::client
        LoginComp["Login.jsx"]:::client
        SignupComp["Signup.jsx"]:::client
        ForgotComp["ForgotPassword.jsx"]:::client
        ExpensesComp["Expenses.jsx"]:::client
        ConfigVite["vite.config.ts"]:::client
        ConfigPkg["package.json"]:::client
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        subgraph "Auth Service (FastAPI)"
            direction TB
            AuthMain["main.py"]:::service
            AuthEndpoints["auth.py"]:::service
            AuthModels["models.py"]:::service
            AuthDB["db.py"]:::service
        end

        subgraph "Expense Service (FastAPI)"
            direction TB
            ExpMain["main.py"]:::service
            ExpAuth["auth.py"]:::service
            ExpModels["models.py"]:::service
            ExpDB["db.py"]:::service
        end
    end

    %% Database
    subgraph "Data Storage"
        direction TB
        MongoDB[(MongoDB Database)]:::database
    end

    %% External Services
    subgraph "External"
        direction TB
        EmailSvc["Email Service"]:::external
    end

    %% Documentation
    subgraph "Documentation"
        direction TB
        ArchDoc["architecture.md"]:::docs
        MongoDoc["mongodb_setup_summary.md"]:::docs
    end

    %% Utilities
    subgraph "Utilities & Scripts"
        direction TB
        GenHash["generate_hash.py"]:::utils
        Makefile["makefile"]:::utils
        ReqRoot["requirements.txt"]:::utils
        RuffCfg["ruff.toml"]:::utils
    end

    %% Connections
    Browser -->|"loads main"| MainJS
    MainJS --> AppJS
    AppJS --> LoginComp
    AppJS --> SignupComp
    AppJS --> ForgotComp
    AppJS --> ExpensesComp
    Browser -->|"POST /login, /signup"| AuthEndpoints
    AuthEndpoints -->|"user data"| AuthDB
    AuthEndpoints -->|"issues JWT token"| Browser
    Browser -->|"Authorization: Bearer {token}"| ExpAuth
    Browser -->|"CRUD /expenses"| ExpMain
    ExpAuth -.->|"validate token"| AuthEndpoints
    ExpMain -->|"expense data"| ExpDB
    AuthDB --> MongoDB
    ExpDB --> MongoDB
    AuthEndpoints -->|"send reset link"| EmailSvc
    ArchDoc --> MongoDoc

    %% Click Events - Frontend
    click Browser "https://github.com/yenchenglai/expense-tracker-v2/tree/main/frontend/"
    click MainJS "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/src/main.jsx"
    click AppJS "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/src/App.jsx"
    click LoginComp "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/src/components/Login.jsx"
    click SignupComp "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/src/components/Signup.jsx"
    click ForgotComp "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/src/components/ForgotPassword.jsx"
    click ExpensesComp "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/src/components/Expenses.jsx"
    click ConfigVite "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/vite.config.ts"
    click ConfigPkg "https://github.com/yenchenglai/expense-tracker-v2/blob/main/frontend/package.json"

    %% Click Events - Auth Service
    click AuthMain "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/main.py"
    click AuthEndpoints "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/auth.py"
    click AuthModels "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/models.py"
    click AuthDB "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/db.py"
    click AuthMain "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/main.py"
    click AuthEndpoints "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/auth.py"
    click AuthModels "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/models.py"
    click AuthDB "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/db.py"
    click AuthMain "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/main.py"
    click AuthMain "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/main.py"
    click AuthMain "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/auth-service/app/main.py"

    %% Click Events - Expense Service
    click ExpMain "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/expense-service/app/main.py"
    click ExpAuth "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/expense-service/app/auth.py"
    click ExpModels "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/expense-service/app/models.py"
    click ExpDB "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/expense-service/app/db.py"

    %% Click Events - Documentation
    click ArchDoc "https://github.com/yenchenglai/expense-tracker-v2/blob/main/docs/architecture.md"
    click MongoDoc "https://github.com/yenchenglai/expense-tracker-v2/blob/main/docs/mongodb_setup_summary.md"

    %% Click Events - Utilities
    click GenHash "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/generate_hash.py"
    click Makefile "https://github.com/yenchenglai/expense-tracker-v2/tree/main/backend/makefile"
    click ReqRoot "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/requirements.txt"
    click RuffCfg "https://github.com/yenchenglai/expense-tracker-v2/blob/main/backend/ruff.toml"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0366D6,stroke-width:2px
    classDef service fill:#E6FFEA,stroke:#28A745,stroke-width:2px
    classDef database fill:#FFF5E6,stroke:#D2691E,stroke-width:2px,stroke-dasharray: 5 5
    classDef external fill:#FFEFD5,stroke:#FF8C00,stroke-width:2px,stroke-dasharray: 2 2
    classDef docs fill:#F0F0F0,stroke:#666666,stroke-width:1px
    classDef utils fill:#F5F5FF,stroke:#5555AA,stroke-width:1px,stroke-dasharray: 3 3
```
