# linhhatrannha/expense-management architecture

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

- Interactive diagram: https://gitdiagram.com/linhhatrannha/expense-management
- Repository: https://github.com/linhhatrannha/expense-management

## Overview

##### Project Type & Purpose
- FinMan is a full-stack web application focused on personal finance management. It provides key features like expense tracking, spending limits, savings goals, and financial reporting.
- The architecture is fairly straightforward with a backend powered by Python/Flask, a PostgreSQL database, and a frontend using HTML templates styled with CSS and enhanced by JavaScript.

##### Analyzing the File Structure
- Top-level Python files (app.py, models.py, forms.py, database.py) indicate that the core business logic, routing, data models, and database connection logic are implemented in these files.
- The Procfile is used for deployment configuration (likely on platforms like Heroku).
- The requirements.txt file lists dependencies that hint at the Flask ecosystem and database drivers.
- The static/ directory contains CSS and JS files (as well as images) which form the client-side assets.
- The templates/ folder holds HTML files, which are the views rendered by the Flask backend.
- Overall, the separation of concerns is clear, implementing a modular design with clear delineations between presentation (templates, static assets), business logic (app.py, forms.py, models.py), and data persistence (database.py).

a. Main Components:
- Web Browser/Client: Represents the end-user’s interface interacting with the application.
- Frontend Layer: Consisting of HTML templates and static assets (CSS, JS, images) that define the user interface.
- Flask Application Server: Acts as the backend, where app.py handles routing and requests. Within this layer, forms.py manages form handling/validation, models.py defines data models, and database.py manages database connections.
- PostgreSQL Database: Serves as the data storage, holding user data, transactions, and financial records.
- (Optionally) External services for notifications (e.g., if there’s an email service integration for spending alerts) although these are not explicitly mentioned, they might be considered if the alerting mechanism grows.

b. Relationships & Interactions:
- The user interacts with the web browser which sends HTTP requests to the Flask backend.
- The Flask server processes these requests (using routes defined in app.py), uses forms for input validation via forms.py, and manages data operations through models.py which in turn communicate with the PostgreSQL database (via database.py).
- The server renders HTML templates populated with data, and static files are served for the frontend.
- Requests flow from the browser to the Flask server.
- The Flask application interacts with the database.
- Responses are returned back to the browser via rendered templates.

c. Architectural Patterns & Design Principles:
- MVC-like Separation: Although not a strict MVC framework, the division between templates (views), models (data/business logic), and controllers (app.py handling routing) is clearly visible.
- Clear separation between client-side (static files and templates) and server-side concerns.
- The system is modular, with each component (forms, models, database handling) isolated in different files for maintainability.

d. Relevant Technologies & Frameworks:
- Flask (backend web framework)
- PostgreSQL (relational database)
- HTML/CSS/JavaScript (frontend technologies)
- Procfile (used for deployment configuration, e.g., Heroku)

##### Elements
- Optionally, you might add minor details like the configuration file (e.g., Procfile) to demonstrate deployment aspects.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    Browser["Web Browser"]:::client

    %% Backend Layer: Flask Application Server
    subgraph "Flask Application Server"
        A1["app.py"]:::backend
        A2["forms.py"]:::backend
        A3["models.py"]:::backend
        A4["database.py"]:::backend
    end

    %% Frontend Assets Layer
    subgraph "Frontend Assets"
        T["Templates"]:::frontend
        S["Static Files"]:::frontend
    end

    %% Database
    DB["PostgreSQL Database"]:::database

    %% Deployment Configuration
    Deployment["Procfile"]:::deployment

    %% Connections
    Browser -->|"HTTP_Request"| A1
    A1 -->|"Uses_forms"| A2
    A1 -->|"Uses_models"| A3
    A1 -->|"Calls_DB"| A4
    A4 -->|"Executes_Queries"| DB
    A1 -->|"Serves_Templates"| T
    A1 -->|"Serves_Static_Files"| S
    Deployment -->|"Configures"| A1

    %% Click Events
    click T "https://github.com/linhhatrannha/expense-management/tree/main/templates/"
    click S "https://github.com/linhhatrannha/expense-management/tree/main/static/"
    click A1 "https://github.com/linhhatrannha/expense-management/blob/main/app.py"
    click A2 "https://github.com/linhhatrannha/expense-management/blob/main/forms.py"
    click A3 "https://github.com/linhhatrannha/expense-management/blob/main/models.py"
    click A4 "https://github.com/linhhatrannha/expense-management/blob/main/database.py"
    click Deployment "https://github.com/linhhatrannha/expense-management/tree/main/Procfile"

    %% Styles
    classDef client fill:#fdebd0,stroke:#e67e22,stroke-width:2px;
    classDef backend fill:#d6eaf8,stroke:#3498db,stroke-width:2px;
    classDef frontend fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef database fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef deployment fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
```
