# astrocamp/19th-fitcal architecture

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

- Interactive diagram: https://gitdiagram.com/astrocamp/19th-fitcal
- Repository: https://github.com/astrocamp/19th-fitcal

## Overview

##### Project type and purpose
- This is a full-stack web application (“FitCal”) built on Django (Python) with a JavaScript/CSS asset pipeline.
- Purpose: a calorie-balanced meal-ordering platform with separate domains (members, products, carts, orders, stores, pages, users).

##### File structure
- Top-level Django project folder:
- fitcal/ (ASGI, WSGI, settings, root URLs)
- manage.py, main.py
- Seven Django “apps” under root: carts, members, orders, pages, products, stores, users
- A “templates” directory mirroring each app for server-rendered HTML
- A src/ directory for front-end assets:
- src/scripts (flatpickr date-picker integration, input.js)
- src/styles (Tailwind CSS config & custom CSS files)
- Build and config files: package.json, tailwind.config.js, pyproject.toml, Makefile, `.env-example`
- PostgreSQL as the backing database

##### README for additional insights
- Python 3.13, Node.js ≥20
- Uses “uv” for virtual env, formatter, and running Django commands
- Front-end build/watch via `npm run dev` (esbuild & Tailwind)
- Database: PostgreSQL 17.4, configured via `DATABASE_URL` in `.env`

##### Main components and relationships
a. Client (Browser):
- Sends HTTP requests for pages, forms, assets
- Receives server-rendered HTML, CSS, JS
b. Front-end build pipeline (Node.js + esbuild + Tailwind):
- Takes src/scripts and src/styles → outputs bundled JS/CSS in static directory
- Run in watch mode (`npm run dev`) or one-off via Makefile/npm scripts
c. Django Application Server (ASGI):
- Entry point: fitcal/asgi.py
- URL router: fitcal/urls.py dispatches to each app’s urls.py
- Apps implement MVC pattern: models.py ←→ database, views.py ←→ templates, forms.py for validation
- Utilities, templatetags, and middleware in users/
d. Data store:
- PostgreSQL database
- Django ORM maps models in each app to relational tables under migrations/
e. Optional reverse proxy / load balancer (e.g., Nginx) in front of ASGI server for production (not in repo but standard)

##### Architectural patterns and design principles
- Monolithic, domain-driven Django MVC
- Separation of concerns by Django “apps” as bounded contexts
- Build pipeline loosely coupled: static assets built separately, then served by Django (or a CDN)
- Use of ASGI for async capabilities but primarily synchronous views

##### Detail
- Call out key config files (tailwind.config.js, package.json, pyproject.toml).
- Migrations folder under each app as part of the data layer evolution.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Browser
    Browser["Browser"]:::browser

    %% Reverse Proxy
    Proxy["Reverse Proxy / Load Balancer"]:::server

    %% Django ASGI Application Server
    subgraph "Django ASGI Application Server"
        direction TB
        ASGI["ASGI Entrypoint"]:::server
        Router["URL Router"]:::server
        subgraph "Apps"
            direction TB
            Carts["carts App"]:::server
            Members["members App"]:::server
            Orders["orders App"]:::server
            Pages["pages App"]:::server
            Products["products App"]:::server
            Stores["stores App"]:::server
            Users["users App"]:::server
        end
        TemplatesEng["Templates Engine"]:::server
        FormsVal["Forms & Validation"]:::server
        Middleware["Middleware & Utilities"]:::server
    end

    %% Database
    Database[(PostgreSQL)]:::db

    %% Front-end Build Pipeline
    subgraph "Front-end Build Pipeline"
        direction TB
        SrcScripts["src/scripts/"]:::build
        SrcStyles["src/styles/"]:::build
        Toolchain["Node.js + esbuild + Tailwind"]:::build
        StaticJS["static/js"]:::artifact
        StaticCSS["static/css"]:::artifact
    end

    %% Relationships
    Browser -->|"HTTP(S) requests/responses"| Proxy
    Proxy -->|"HTTP(S) requests/responses"| ASGI
    ASGI -->|"dispatch via URLconf"| Router
    Router -->|"routes to"| Carts
    Router -->|"routes to"| Members
    Router -->|"routes to"| Orders
    Router -->|"routes to"| Pages
    Router -->|"routes to"| Products
    Router -->|"routes to"| Stores
    Router -->|"routes to"| Users
    Carts -->|"renders via Templates"| TemplatesEng
    Members -->|"renders via Templates"| TemplatesEng
    Orders -->|"renders via Templates"| TemplatesEng
    Pages -->|"renders via Templates"| TemplatesEng
    Products -->|"renders via Templates"| TemplatesEng
    Stores -->|"renders via Templates"| TemplatesEng
    Users -->|"renders via Templates"| TemplatesEng
    Carts -->|"uses Forms & Validation"| FormsVal
    Members -->|"uses Forms & Validation"| FormsVal
    Orders -->|"uses Forms & Validation"| FormsVal
    Pages -->|"uses Forms & Validation"| FormsVal
    Products -->|"uses Forms & Validation"| FormsVal
    Stores -->|"uses Forms & Validation"| FormsVal
    Users -->|"uses Forms & Validation"| FormsVal
    Users -->|"middleware & utils"| Middleware
    Orders -->|"middleware & utils"| Middleware
    ASGI -->|"ORM queries"| Database
    SrcScripts -->|"build input"| Toolchain
    SrcStyles -->|"build input"| Toolchain
    Toolchain -->|"emit bundles"| StaticJS
    Toolchain -->|"emit bundles"| StaticCSS
    StaticJS -->|"HTTP(S) static files"| Browser
    StaticCSS -->|"HTTP(S) static files"| Browser

    %% Click Events
    click ASGI "https://github.com/astrocamp/19th-fitcal/blob/dev/fitcal/asgi.py"
    click Router "https://github.com/astrocamp/19th-fitcal/blob/dev/fitcal/urls.py"
    click Carts "https://github.com/astrocamp/19th-fitcal/tree/dev/carts/"
    click Members "https://github.com/astrocamp/19th-fitcal/tree/dev/members/"
    click Orders "https://github.com/astrocamp/19th-fitcal/tree/dev/orders/"
    click Pages "https://github.com/astrocamp/19th-fitcal/tree/dev/pages/"
    click Products "https://github.com/astrocamp/19th-fitcal/tree/dev/products/"
    click Stores "https://github.com/astrocamp/19th-fitcal/tree/dev/stores/"
    click Users "https://github.com/astrocamp/19th-fitcal/tree/dev/users/"
    click SrcScripts "https://github.com/astrocamp/19th-fitcal/tree/dev/src/scripts/"
    click SrcStyles "https://github.com/astrocamp/19th-fitcal/tree/dev/src/styles/"

    %% Styles
    classDef browser fill:#cce5ff,stroke:#0366d6,color:#0366d6
    classDef server fill:#d4edda,stroke:#28a745,color:#155724
    classDef db fill:#ffe5b4,stroke:#f0ad4e,color:#8a6d3b
    classDef build fill:#e6ccff,stroke:#6f42c1,color:#4e2a84
    classDef artifact fill:#e2e3e5,stroke:#6c757d,color:#343a40
```
