# eitchtee/wygiwyh architecture

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

- Interactive diagram: https://gitdiagram.com/eitchtee/wygiwyh
- Repository: https://github.com/eitchtee/wygiwyh

## Overview

##### Project type and purpose
- Full‑stack single‑code‑base web application
- Opinionated finance tracker with multi‑currency support, DCA tracker, rules engine, and API.
- Backend: Django (with DRF, HTMX, Hyperscript), Procrastinate for async tasks
- Frontend: Webpack bundle (Bootstrap, Tailwind, Alpine.js)

##### File structure
- Top level:
– app/ (Django project and ~15 Django “apps” like accounts, transactions, currencies, import_app, export_app, etc.)
– frontend/ (Webpack config, src application scripts, styles)
– docker‑compose.dev.yml & prod (containers for Django web, Procrastinate worker, Supervisord, Webpack builder)
– requirements.txt (Python dependencies)
- Key configs: app/WYGIWYH/settings.py, docker/*, frontend/webpack/*.js
- Background tasks: app/apps/**/tasks.py, app/apps/rules/signals.py
- API layer: app/apps/api (DRF serializers, views, URLs)

##### README for additional insights
- Built with Django, HTMX, Procrastinate, DRF, Webpack, PostgreSQL
- Dockerized for prod/dev, environment variables for DB, secrets, feature flags
- Web UI + Automation‑ready API + scheduled background jobs (exchange rate fetcher, imports/exports)

##### Main components and interactions
a. Frontend (Browser & Static assets)
– Browser UI: HTML templates (Django + HTMX snippets) + JavaScript (webpack‑bundled scripts: htmx, hyperscript, jQuery, datepicker, etc.) + CSS (Bootstrap, Tailwind)
– Sends HTTP/HTMX requests to Backend
b. Django Web Server
– WSGI/ASGI app (app/WYGIWYH/wsgi.py & asgi.py)
– URL router → Django apps (views, DRF APIView)
– Templates → dynamic HTML + HTMX fragments
– Orchestrates business logic, form processing, rules engine
– Enqueues background jobs (via Procrastinate client)
c. PostgreSQL Database
– Stores users, accounts, transactions, currencies, DCA strategies, rules, import/export profiles, translations, etc.
– Django ORM / SQL queries
d. Background Worker (Procrastinate)
– Listens for enqueued jobs: exchange rate fetcher, import/app tasks, export tasks, recurring transaction generation, cleanup soft‑deleted transactions
– Runs scheduled jobs (cron‑like)
e. External Services
– Exchange rate providers (in app/apps/currencies/exchange_rates/providers.py)
– Translation service for localization (HerokuTranslate or similar)
– Optional integrations via API

##### Architectural patterns & design principles
- Monolithic MVC pattern (Django apps as modules)
- Separation of concerns:
– “apps/api” provides REST endpoints for automation
– “apps/common” holds shared utils, middleware, custom fields
– Each domain feature (accounts, transactions, rules, DCA, insights) in its own app
- HTMX/hyperscript for progressive enhancement—partial views and in‑page interactions
- Asynchronous task queue (Procrastinate) for long‑running or scheduled jobs
- Containerized micro‑services approach: Web, Worker, Build, Supervisord

##### Final checklist
[ ] Components labeled (Browser, Frontend Assets, Django Web, DB, Worker, External APIs)
[ ] Groupings for domain apps vs. shared/common code
[ ] Note key technologies next to each component (e.g., “Django + DRF + HTMX”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    Browser["Browser"]:::ui
    subgraph "Frontend Layer"
        direction TB
        FrontendAssets["Frontend Bundle\n(webpack, Bootstrap, Tailwind, Alpine.js)"]:::ui
    end
    Browser -->|"HTTP/HTMX"| FrontendAssets

    %% Backend Layer
    subgraph "Django Web (uWSGI/ASGI)\n(Django + DRF + HTMX)" 
        direction TB
        Settings["settings.py"]:::backend
        WSGI["wsgi.py"]:::backend
        ASGI["asgi.py"]:::backend
        URLRouter["urls.py"]:::backend
        Templates["Templates & HTMX\n(HTML + fragments)"]:::backend
        API["DRF API\n(serializers, views, urls)"]:::backend
        Common["Common Utils\n(middleware, decorators, tasks)"]:::backend
        DomainLogic["Domain Apps\n(accounts, transactions, currencies, import_app, export_app, rules, dca, insights)"]:::backend
    end
    FrontendAssets -->|"HTTP/HTMX or REST"| Settings
    Settings --> WSGI
    Settings --> ASGI
    WSGI --> URLRouter
    ASGI --> URLRouter
    URLRouter --> Templates
    URLRouter --> API
    URLRouter --> DomainLogic
    URLRouter --> Common

    %% Data Layer
    subgraph "PostgreSQL Database" 
        DB[(PostgreSQL)]:::data
    end
    Settings -->|"DB Config"| DB
    URLRouter -->|"SQL queries"| DB

    %% Background Worker
    subgraph "Background Worker\n(Procrastinate)" 
        Worker["Worker\n(Procrastinate)"]:::jobs
    end
    DomainLogic -->|"Enqueue tasks"| Worker
    Common -->|"Tasks definitions"| Worker
    Worker -->|"SQL queries"| DB

    %% External Services
    subgraph "External Services"
        direction TB
        Exchange["Exchange Rate Providers"]:::external
        Translation["Translation Service"]:::external
    end
    Worker -->|"HTTP"| Exchange
    Worker -->|"HTTP"| Translation

    %% Docker Deployment
    subgraph "Dockerized Deployment"
        direction TB
        DevCompose["docker-compose.dev.yml"]:::backend
        ProdCompose["docker-compose.prod.yml"]:::backend
    end
    DevCompose --> Settings
    ProdCompose --> Settings

    %% Click Events
    click FrontendAssets "https://github.com/eitchtee/wygiwyh/tree/main/frontend/webpack"
    click FrontendAssets "https://github.com/eitchtee/wygiwyh/tree/main/frontend/src/application"
    click FrontendAssets "https://github.com/eitchtee/wygiwyh/tree/main/frontend/src/styles"
    click FrontendAssets "https://github.com/eitchtee/wygiwyh/tree/main/frontend/assets"
    click DevCompose "https://github.com/eitchtee/wygiwyh/blob/main/docker-compose.dev.yml"
    click ProdCompose "https://github.com/eitchtee/wygiwyh/blob/main/docker-compose.prod.yml"
    click Settings "https://github.com/eitchtee/wygiwyh/blob/main/app/WYGIWYH/settings.py"
    click WSGI "https://github.com/eitchtee/wygiwyh/blob/main/app/WYGIWYH/wsgi.py"
    click ASGI "https://github.com/eitchtee/wygiwyh/blob/main/app/WYGIWYH/asgi.py"
    click URLRouter "https://github.com/eitchtee/wygiwyh/blob/main/app/WYGIWYH/urls.py"
    click API "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/api"
    click Common "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/common"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/accounts"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/transactions"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/currencies"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/import_app"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/export_app"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/rules"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/dca"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/tree/main/app/apps/insights"
    click Common "https://github.com/eitchtee/wygiwyh/blob/main/app/apps/common/middleware/htmx.py"
    click Common "https://github.com/eitchtee/wygiwyh/blob/main/app/apps/common/decorators/htmx.py"
    click Common "https://github.com/eitchtee/wygiwyh/blob/main/app/apps/common/tasks.py"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/blob/main/app/apps/import_app/tasks.py"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/blob/main/app/apps/rules/tasks.py"
    click DomainLogic "https://github.com/eitchtee/wygiwyh/blob/main/app/apps/currencies/exchange_rates/providers.py"

    %% Styles
    classDef ui fill:#D6EFFF,stroke:#0366D6,stroke-width:2px
    classDef backend fill:#E6FFEA,stroke:#28A745,stroke-width:2px
    classDef data fill:#FFE8A1,stroke:#D19A00,stroke-width:2px
    classDef jobs fill:#F3E6FF,stroke:#6F42C1,stroke-width:2px
    classDef external fill:#F0F0F0,stroke:#6A737D,stroke-width:2px
```
