# bharat-panchal15/flask-expense-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/bharat-panchal15/flask-expense-tracker
- Repository: https://github.com/bharat-panchal15/flask-expense-tracker

## Overview

##### Project type and purpose
- This is a full-stack web application built with Python’s Flask framework.
- Purpose: provide a budgeting and expense-tracking interface (static JS + Jinja templates on the front end, RESTful API and server-rendered routes on the back end, persistent storage via a relational database managed with Alembic migrations).

##### File structure
Top-level files and directories:
- run.py – application entry point
- config.py – configuration (database URL, secret keys, environment flags)
- requirements.txt – Python dependencies (Flask, Flask-SQLAlchemy, Flask-Migrate, etc.)
- app/ – core application package
– __init__.py – app factory, initialize extensions
– extensions.py – instantiate SQLAlchemy, Migrate, JWT, etc.
– models.py – ORM models (User, Expense, Budget)
– api/ – programmatic API layer for budgets and expenses
- resources.py – defined API resources/endpoints
- budget_utils.py / utils.py – shared business logic
– routes/ – server-rendered (non-API) routes and views
– static/ – JavaScript modules for front-end interactivity (dashboard.js, budgets.js, etc.)
– templates/ – Jinja2 templates for HTML views
- migrations/ – Alembic scripts for database version control

##### README
- (No content provided, so inference is based on file structure and naming conventions.)

##### Components
a. Main components
1. Client (Browser): requests HTML pages, makes XHR/fetch calls to API
2. Web Server (Flask app – run.py + app factory)
3. Routing Layer:
- Server-Rendered Routes (app/routes)
- REST API Endpoints (app/api/resources.py)
4. Business Logic Layer (budget_utils.py, utils.py, models.py)
5. Persistence Layer (Relational Database)
6. Migration Service (Alembic via Flask-Migrate)
7. Configuration & Extensions (Flask extensions: SQLAlchemy, Migrate, JWT, etc.)
b. Relationships & Interactions
- Client ↔ Server-Rendered Routes: initial page loads (templates + static assets)
- Client ↔ REST API: JSON payloads for CRUD on budgets/expenses
- Routes & Resources → Business Logic → Models → Database
- Migrations → Database (version control for schema changes)
c. Architectural patterns / design principles
- Application Factory pattern for Flask initialization
- Layered architecture: Presentation (templates + JS), API, Business Logic, Data Access
- Separation of concerns: app/api vs. app/routes vs. app/models vs. app/static vs. app/templates
- DB migrations for schema evolution
d. Key technologies/frameworks
- Flask
- Flask-SQLAlchemy
- Flask-Migrate (Alembic)
- Jinja2 templates
- Vanilla JS modules in app/static

## Diagram (Mermaid)

```mermaid
flowchart TD
    client["Client / Browser"]:::frontend

    subgraph "Presentation Layer"
        templates["Templates"]:::frontend
        static["Static JS"]:::frontend
    end

    client -->|"Page Requests"| runpy
    runpy -->|"initializes"| init

    subgraph "Flask App"
        runpy["run.py"]:::backend
        init["__init__.py"]:::backend
    end

    subgraph "Configuration & Extensions"
        config["config.py"]:::config
        extensions["extensions.py"]:::config
    end

    init --> config
    init --> extensions

    subgraph "Routing Layer"
        routes["Server-Rendered Routes"]:::backend
        api["REST API Endpoints"]:::backend
    end

    init --> routes
    init --> api

    routes --> templates
    routes --> static

    client -->|"API Calls"| api

    subgraph "Business Logic"
        utils["app/utils.py"]:::logic
        budget_utils["app/api/budget_utils.py"]:::logic
        api_utils["app/api/utils.py"]:::logic
        models["app/models.py"]:::logic
    end

    api --> budget_utils
    api --> api_utils
    budget_utils --> models
    api_utils --> models
    models --> db

    subgraph "Database & Migrations"
        db["Relational Database"]:::db
        subgraph "Migration Service"
            mig_dir["migrations/"]:::db
            mig_env["env.py"]:::db
            mig_ini["alembic.ini"]:::db
            mig_ver["versions/"]:::db
        end
    end

    mig_dir --> mig_env
    mig_dir --> mig_ini
    mig_dir --> mig_ver
    mig_dir --> db

    click templates "https://github.com/bharat-panchal15/flask-expense-tracker/tree/main/app/templates/"
    click static "https://github.com/bharat-panchal15/flask-expense-tracker/tree/main/app/static/"
    click runpy "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/run.py"
    click init "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/__init__.py"
    click config "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/config.py"
    click extensions "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/extensions.py"
    click routes "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/routes/routes.py"
    click api "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/api/resources.py"
    click utils "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/utils.py"
    click budget_utils "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/api/budget_utils.py"
    click api_utils "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/api/utils.py"
    click models "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/app/models.py"
    click mig_dir "https://github.com/bharat-panchal15/flask-expense-tracker/tree/main/migrations/"
    click mig_env "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/migrations/env.py"
    click mig_ini "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/migrations/alembic.ini"
    click mig_ver "https://github.com/bharat-panchal15/flask-expense-tracker/blob/main/migrations/versions/*.py"

    classDef frontend fill:#E8F1FC,stroke:#3174AF,color:#3174AF
    classDef backend fill:#D6EAF8,stroke:#21618C,color:#21618C
    classDef config fill:#FCF3CF,stroke:#B7950B,color:#B7950B
    classDef logic fill:#E8F8F5,stroke:#148F77,color:#148F77
    classDef db fill:#FADBD8,stroke:#922B21,color:#922B21
```
