# lebriton/ihatetobudget architecture

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

- Interactive diagram: https://gitdiagram.com/lebriton/ihatetobudget
- Repository: https://github.com/lebriton/ihatetobudget

## Overview

##### Main Components

a. Frontend Layer:
- Template-based UI (Django Templates)
- Static assets (CSS)
- Organized into main sections: Categories, Sheet, Overview, and History views
- Authentication interface

b. Backend Layer:
- Django Web Application
- URL routing system
- View controllers
- Template processors
- Custom template tags

c. Data Layer:
- SQLite database
- Models for expenses and categories
- Database migrations

d. Background Services:
- Cron jobs for scheduled tasks

**┌─────────────────────────────────────────────┐**
- Client Layer                 │
- (Browser/User Interface)                     │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Web Server (Caddy)              │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Django Application Layer           │
- ┬─────────────┬─────────────────┤
- Templates  │   Views     │     Forms       │

- Base     │ - Sheets    │ - Category     │
- Sheets   │ - Category  │ - Expense      │
- Common   │ - History   │                 │
- ┴─────────────┴─────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Data Layer                     │
- ┬─────────────────────┤
- Models           │      Database       │
- Expenses        │      (SQLite)       │
- Categories      │                     │
- ┴─────────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Background Services               │
- (Cron Jobs)                    │
- ┘

##### Important Details to Highlight

a. Application Structure:
- Main Django app 'ihatetobudget' and the 'sheets' app
- Template inheritance structure
- Authentication boundaries

b. Data Flow:
- User request flow through the layers
- CRUD operations for expenses and categories
- Authentication flow

c. Docker Container Boundary:
- Containerized environment
- Volume mounts for persistence
- Caddy reverse proxy setup

##### Key Relationships to Emphasize

- Template inheritance patterns
- Model-View-Template (MVT) pattern implementation
- URL routing to view functions
- Database migration system
- Static file serving

##### Technical Details

- Python 3.8 runtime environment
- Django framework components
- SQLite database connection
- Cron job scheduling
- Docker containerization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]:::client
    end

    subgraph WebServer
        Caddy["Caddy Reverse Proxy"]:::server
    end

    subgraph DjangoApp["Django Application Layer"]
        direction TB
        
        subgraph URLs["URL Routing"]
            MainURLs["Main URLs"]:::routing
            SheetURLs["Sheet URLs"]:::routing
            click MainURLs "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/urls.py"
            click SheetURLs "https://github.com/lebriton/ihatetobudget/blob/master/sheets/urls.py"
        end

        subgraph Views["View Controllers"]
            MainViews["Main Views"]:::controller
            SheetViews["Sheet Views"]:::controller
            UtilViews["Utility Views"]:::controller
            click MainViews "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/views.py"
            click SheetViews "https://github.com/lebriton/ihatetobudget/blob/master/sheets/views.py"
            click UtilViews "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/utils/views.py"
        end

        subgraph Templates["Template System"]
            MainTemplates["Main Templates"]:::template
            SheetTemplates["Sheet Templates"]:::template
            AuthTemplates["Auth Templates"]:::template
            TemplateProcessors["Template Processors"]:::template
            CustomTags["Custom Template Tags"]:::template
            click MainTemplates "https://github.com/lebriton/ihatetobudget/tree/master/ihatetobudget/template/ihatetobudget/"
            click SheetTemplates "https://github.com/lebriton/ihatetobudget/tree/master/sheets/template/sheets/"
            click AuthTemplates "https://github.com/lebriton/ihatetobudget/tree/master/ihatetobudget/template/registration/"
            click CustomTags "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/templatetags/ihatetobudget_extras.py"
        end

        subgraph Static["Static Assets"]
            CSS["CSS Styles"]:::static
            click CSS "https://github.com/lebriton/ihatetobudget/blob/master/static/styles.css"
        end
    end

    subgraph DataLayer["Data Layer"]
        direction TB
        Models["Data Models"]:::data
        Forms["Forms"]:::data
        SQLite[(SQLite Database)]:::database
        Migrations["Database Migrations"]:::data
        click Models "https://github.com/lebriton/ihatetobudget/blob/master/sheets/models.py"
        click Forms "https://github.com/lebriton/ihatetobudget/blob/master/sheets/forms.py"
        click Migrations "https://github.com/lebriton/ihatetobudget/tree/master/sheets/migrations/"
    end

    subgraph Background["Background Services"]
        CronJobs["Cron Jobs"]:::service
        click CronJobs "https://github.com/lebriton/ihatetobudget/blob/master/sheets/cron.py"
    end

    subgraph Config["Application Configuration"]
        Settings["Settings"]:::config
        WSGI["WSGI Config"]:::config
        ASGI["ASGI Config"]:::config
        click Settings "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/settings.py"
        click WSGI "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/wsgi.py"
        click ASGI "https://github.com/lebriton/ihatetobudget/blob/master/ihatetobudget/asgi.py"
    end

    Browser --> Caddy
    Caddy --> URLs
    URLs --> Views
    Views --> Templates
    Views --> Models
    Templates --> Static
    Models --> SQLite
    Forms --> Models
    Models --> Migrations
    CronJobs --> Models
    Config --> DjangoApp

    %% Style Definitions
    classDef client fill:#2374ab,color:#fff
    classDef server fill:#7d8491,color:#fff
    classDef routing fill:#048ba8,color:#fff
    classDef controller fill:#16db93,color:#000
    classDef template fill:#efea5a,color:#000
    classDef static fill:#f29e4c,color:#000
    classDef data fill:#54478c,color:#fff
    classDef database fill:#2c699a,color:#fff
    classDef service fill:#db3a34,color:#fff
    classDef config fill:#4b4e6d,color:#fff
```
