# nomitrwt/mad1 architecture

> Architecture diagram of the GitHub repository nomitrwt/mad1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nomitrwt/mad1
- Repository: https://github.com/nomitrwt/mad1

## Overview

Summary of project type and purpose
- This is a small monolithic full‑stack web application (server‑rendered) built with Python/Flask:
- app.py implements the Flask application / HTTP routes.
- model.py holds data models / DB access logic.
- templates/ contains server-side HTML templates (Jinja2).
- static/ contains static assets (CSS).
- instance/project.db is a local SQLite database used by the app.
- The README confirms this is a student project for a Modern Application Development course; more run/setup details are in Project Report.pdf.

How I analyzed the structure
- Top level shows a single application folder (Code) with app.py and model.py (backend) plus templates and static (frontend).
- Presence of instance/project.db → embedded SQLite database; instance folder indicates Flask instance config.
- Template names (index, product, cart, admin, login, register, search) show typical e‑commerce features and authentication/authorization.
- No separate frontend (React/Angular) or microservices folders; no Dockerfiles or cloud deployment manifests visible.

- Client → Reverse proxy / Load balancer : HTTP(S) GET/POST
- Reverse proxy → WSGI server (gunicorn) : proxied HTTP
- WSGI server → Flask app (app.py) : in‑process routing
- Flask app (controllers) → Templates : render HTML (server side)
- Flask app → model.py (ORM/SQL) → SQLite DB : SQL queries (SELECT/INSERT/UPDATE/DELETE)
- Flask app → Static files : GET static assets (served either by Flask or by nginx/CDN)
- Admin actions: Admin browser → routes → DB (update product/category)
- User actions (checkout/cart): routes → DB (persist cart/session)
- Optional: Flask app → External services (email/payment) : API calls over HTTPS
- Optional: Flask app → Redis : read/write session or cache

##### Important architectural patterns and design principles to call out
- Monolithic MVC-ish layout:
- Controllers: routes in app.py
- Models: model.py
- Views: templates/ (server-side rendering)
- Single process / single database (SQLite) — suitable for dev and single‑user testing, not for horizontal scaling.
- Separation of concerns: presentation (templates/static) separated from business logic (model.py/app.py).
- Statefulness: SQLite + server-side sessions (likely) implies state tied to instance — note scaling implications.

##### Relevant technologies / libs to annotate
- Python, Flask (app.py)
- Jinja2 templates (templates/)
- SQLite (instance/project.db) — highlight as dev DB
- CSS (static/style.css)
- WSGI server (gunicorn/uwsgi) — recommended in production
- Reverse proxy / nginx / CDN — recommended for production assets and TLS termination
- Optional: PostgreSQL/MySQL, Redis, Celery, Docker, systemd / orchestration layer

- Use this for an executive summary slide.
- HTTP layer (routes in app.py)
- Business logic (functions in app.py + model.py)
- Templating engine + templates/
- Static file serving
- Database access (SQLite file)
- Authentication module (login/register/admin template & routes)
- Sequence/Flow examples: add 2–3 sequence flows to show typical interactions:
- Browse product: Browser → GET /product → Flask route → Query DB (model.py) → render template → Response to Browser
- To cart / checkout: Browser → POST /cart → Flask validates → update DB/session → Response
- Admin update product: Admin Browser → POST /admin/product_update → Flask authorizes → DB update → Confirmation rendered
- Deployment/Scaling (optional but recommended):
- Recommended production architecture: Browser → CDN/nginx → Gunicorn → Flask app → PostgreSQL + Redis → Background workers
- SQLite as “development only / single instance storage”.

- Rectangles (rounded) for application components (Flask app, templates, model)
- Clouds for external services (email/payment)
- Diamonds (or labeled shield) for security/authentication concerns
- Annotations: annotate each component with file references, e.g.:
- Flask App → app.py (routes/controllers)
- Data Models → model.py (DB access)
- Templates → templates/*.html (UI)
- DB → instance/project.db (SQLite)
- Levels of detail:

2. Expand App Server into subcomponents: HTTP routing (app.py), Business logic (app.py + model.py), Template renderer, Static assets, Auth module.
##### Production layers optionally: nginx (TLS), Gunicorn, PostgreSQL, Redis.

Extra advice and things to emphasize
- Authentication & admin flows: show auth checks between routes and DB.
- Error handling & logging in the architecture (e.g., exception handler -> log sink).

- Clear labels for each component (map to file names: app.py, model.py, templates/, static/, instance/project.db).

Files→Component mapping (explicit, to avoid ambiguity)
- app.py → HTTP routes / controllers / application entry
- model.py → data access layer / business models / DB interaction
- templates/*.html → server-rendered views (Jinja2 templates)
- static/style.css → static UI assets
- instance/project.db → SQLite database file (persistence)

Tools and final output recommendations

Concluding note

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Context Diagram (Top)
    subgraph "Context Diagram" 
        direction TB
        Browser["Browser (Web Client)"]:::ui
        ReverseProxy["Reverse Proxy / nginx (TLS, static offload)"]:::infra
        AppServer["WSGI Server (gunicorn/uwsgi)"]:::app
        FlaskApp["Flask Application\n(app.py)"]:::app
        DB["SQLite Database\n(instance/project.db)"]:::db
    end

    %% Context connections
    Browser -->|"HTTP(S) GET/POST"| ReverseProxy
    ReverseProxy -->|"Proxy HTTP"| AppServer
    AppServer -->|"WSGI Request"| FlaskApp
    FlaskApp -->|"SQL: SELECT/INSERT/UPDATE/DELETE"| DB
    ReverseProxy -->|"Serve static (optional)"| StaticFiles["Static Files\n(static/)"]:::static

    %% Component / Container Diagram (Middle)
    subgraph "Monolith - Application Container (Project Root Folder/Code/)" 
        direction TB
        subgraph "HTTP & Routing"
            direction TB
            Routes["Routes / Controllers\napp.py"]:::app
        end

        subgraph "Business Logic & Models"
            direction TB
            Models["Data Models / DB Access\nmodel.py"]:::logic
            Auth["Auth / Session Logic\n(login/register/admin)"]:::security
        end

        subgraph "Presentation"
            direction TB
            Templates["Jinja2 Templates\ntemplates/"]:::ui
            Static["Static Assets\nstatic/style.css"]:::static
        end

        subgraph "Persistence"
            direction TB
            SQLite["SQLite File\ninstance/project.db"]:::db
        end

        subgraph "Ops & Docs"
            direction TB
            README["README.md"]:::doc
            Report["Project Report.pdf"]:::doc
        end
    end

    %% Component connections
    Routes -->|"calls / delegates"| Models
    Routes -->|"renders"| Templates
    Routes -->|"serves or delegates static"| Static
    Models -->|"reads/writes (SQL)"| SQLite
    Auth -->|"verifies / persists session"| Models
    Routes -.->|"logs/errors ->"| Logs["App Logs / Error Tracking (Sentry)"]:::ops
    FlaskApp --- Routes
    FlaskApp --- Models
    FlaskApp --- Templates

    %% Annotations for dev vs prod
    DevNote["Note: SQLite = development-only\n(prod: PostgreSQL/MySQL)"]:::note
    SQLite --> DevNote

    %% Sequence Examples (Bottom)
    subgraph "Sequence Flows (Example User Interactions)"
        direction TB
        %% Browse product sequence
        seq1_Browser["Browser"]:::ui2
        seq1_Proxy["nginx"]:::infra
        seq1_Gunicorn["Gunicorn (WSGI)"]:::app
        seq1_Flask["Flask Route: GET /product"]:::app
        seq1_Model["model.py -> SQL Query"]:::logic
        seq1_DB["SQLite (instance/project.db)"]:::db

        seq1_Browser -->|"GET /product"| seq1_Proxy
        seq1_Proxy -->|"Proxy"| seq1_Gunicorn
        seq1_Gunicorn -->|"WSGI call"| seq1_Flask
        seq1_Flask -->|"SELECT product by id"| seq1_Model
        seq1_Model -->|"SQL SELECT"| seq1_DB
        seq1_DB -->|"rows"| seq1_Model
        seq1_Model -->|"product data"| seq1_Flask
        seq1_Flask -->|"render product.html (Jinja2)"| seq1_Browser

        %% Add to cart sequence
        seq2_Browser["Browser (Add to Cart)"]:::ui2
        seq2_Flask["Flask Route: POST /cart"]:::app
        seq2_Model["model.py (update cart/session)"]:::logic
        seq2_DB["SQLite"]:::db

        seq2_Browser -->|"POST /cart"| seq1_Proxy
        seq1_Proxy -->|"Proxy"| seq1_Gunicorn
        seq1_Gunicorn -->|"WSGI call"| seq2_Flask
        seq2_Flask -->|"validate input / auth"| Auth
        Auth -->|"authorized?"| seq2_Flask
        seq2_Flask -->|"UPDATE cart"| seq2_Model
        seq2_Model -->|"SQL UPDATE/INSERT"| seq2_DB
        seq2_DB -->|"ACK"| seq2_Model
        seq2_Flask -->|"200 OK / redirect"| seq2_Browser

        %% Admin update sequence
        seq3_Browser["Admin Browser"]:::ui2
        seq3_Flask["Flask Route: POST /admin/product_update"]:::app
        seq3_Auth["Auth check (admin)"]:::security
        seq3_Model["model.py (update product)"]:::logic
        seq3_DB["SQLite"]:::db

        seq3_Browser -->|"POST /admin/product_update"| seq1_Proxy
        seq1_Proxy -->|"Proxy"| seq1_Gunicorn
        seq1_Gunicorn -->|"WSGI call"| seq3_Flask
        seq3_Flask -->|"authorize admin"| seq3_Auth
        seq3_Auth -->|"ok"| seq3_Flask
        seq3_Flask -->|"UPDATE product"| seq3_Model
        seq3_Model -->|"SQL UPDATE"| seq3_DB
        seq3_DB -->|"ACK"| seq3_Model
        seq3_Flask -->|"render admin confirmation"| seq3_Browser
    end

    %% Legend and Notes (Right side stacked vertically)
    subgraph "Legend & Notes"
        direction TB
        L1["Shapes: Rounded rectangle = Component\nCylinder = Persistent Store\nCloud = External Service"]:::legend
        L2["Colors: UI=Blue, App=Green, Data=Orange, External=Gray"]:::legend
        L3["Files referenced (click to open):"]:::legend
        Click_APP["app.py (Routes)"]:::clickable
        Click_MODEL["model.py (Data Models)"]:::clickable
        Click_TEMPLATES["templates/ (Jinja2 views)"]:::clickable
        Click_STATIC["static/style.css"]:::clickable
        Click_DB["instance/project.db (SQLite)"]:::clickable
        Click_REPORT["Project Report.pdf"]:::clickable
        Click_README["README.md"]:::clickable
    end

    %% Click events mapping to component paths
    click Routes "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/app.py"
    click Models "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/model.py"
    click Templates "https://github.com/nomitrwt/mad1/tree/main/Project Root Folder/Code/templates/"
    click Static "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/static/style.css"
    click SQLite "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/instance/project.db"
    click DevNote "https://github.com/nomitrwt/mad1/tree/main/Project Root Folder/Code/instance/"
    click Click_APP "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/app.py"
    click Click_MODEL "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/model.py"
    click Click_TEMPLATES "https://github.com/nomitrwt/mad1/tree/main/Project Root Folder/Code/templates/"
    click Click_STATIC "https://github.com/nomitrwt/mad1/tree/main/Project Root Folder/Code/static/"
    click Click_DB "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Code/instance/project.db"
    click Click_REPORT "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/Project Report.pdf"
    click Click_README "https://github.com/nomitrwt/mad1/blob/main/Project Root Folder/README.md"

    %% Styling / Classes
    classDef ui fill:#D0E8FF,stroke:#0B6FA4,color:#022C43;
    classDef ui2 fill:#E8F4FF,stroke:#0B6FA4,color:#022C43;
    classDef app fill:#DFF7E0,stroke:#2E8B57,color:#013220;
    classDef logic fill:#E6F2FF,stroke:#1E90FF,color:#032B4D;
    classDef static fill:#FFF4D9,stroke:#D4A017,color:#5A3E00;
    classDef db fill:#FFE6D6,stroke:#D9732A,color:#4A2C0A;
    classDef infra fill:#F0F0F0,stroke:#8A8A8A,color:#333333;
    classDef security fill:#FFE9F0,stroke:#D14A7F,color:#4A1330;
    classDef ops fill:#F5F5FF,stroke:#6B6BDB,color:#0F1133;
    classDef doc fill:#F0FFF0,stroke:#59A96A,color:#0B3D17;
    classDef note fill:#FFF8E1,stroke:#E0B000,color:#6B4A00;
    classDef legend fill:#FFFFFF,stroke:#CCCCCC,color:#000000;
    classDef clickable fill:#FFFFFF,stroke:#BBBBBB,color:#111111;

    %% Ensure vertical layout preference by grouping major sections vertically
    class Browser ui
    class ReverseProxy infra
    class AppServer app
    class FlaskApp app
    class DB db
    class Routes app
    class Models logic
    class Templates ui
    class Static static
    class SQLite db

    %% End of diagram
```
