# ttt3216/quiz_cs402 architecture

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

- Interactive diagram: https://gitdiagram.com/ttt3216/quiz_cs402
- Repository: https://github.com/ttt3216/quiz_cs402

## Overview

##### Project type and purpose
- This is a lightweight, full-stack web application built in Python (likely using Flask) that serves a quiz to users via HTML templates.
- Key indicators: a single Python script (`q2.py`), a `templates/` folder with HTML files, `words.json` for quiz data, a `requirements.txt` for dependencies, and a `Procfile` (suggesting deployment on Heroku or a similar PaaS).

##### File structure
- Top-level files:
- `q2.py`: the main application entry point (defines routes, quiz logic, data loading)
- `requirements.txt`: Python packages (Flask, etc.)
- `Procfile`: process declaration for deployment
- `words.json`: quiz questions/answers datastore
- `templates/`: directory containing view templates (`index.html`, `quiz.html`, `log.html`, `confirm_quit.html`)
- There are no separate “frontend” and “backend” folders; instead, this is a monolithic web app where Python code serves HTML.

##### README
- Very minimal (# quiz_cs402). No architecture notes, so we infer from file names and conventions: routing → template rendering → data store access.

a. Main components:
- Client Browser (User Interface)
- Web Server / WSGI Container (e.g., Gunicorn, Flask built-in)
- Flask Application (`q2.py`)
- Template Engine (Jinja2, built into Flask)
- Data Store (`words.json`)
- Logging Component (could be a log file or database)
- Deployment Platform (Heroku dyno or equivalent)
b. Relationships / Interactions:
1. User (Client) sends HTTP request → Web Server
2. Web Server forwards request → Flask App
3. Flask App reads `words.json` (data store) to generate quiz content
4. Flask App uses Template Engine to render HTML with data
5. Flask App returns HTTP response → Web Server → Client
6. Flask App writes user responses / quiz logs to a log file or database (if implemented)
7. Web Server / Procfile indicates how the application is run on the Deployment Platform
c. Architectural patterns / design principles:
- MVC-style separation:
- Model: `words.json` and log storage
- View: HTML templates in `templates/`
- Controller: route handlers in `q2.py`
- Single-page flow with multiple routes (`/`, `/quiz`, `/log`, `/confirm_quit`)
d. Key technologies / frameworks:
- Python 3.x, Flask (HTTP routing + template rendering), Jinja2 (templating), JSON file as simple datastore, Gunicorn or Flask dev server, deployed via Heroku (Procfile).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client Browser"]:::external
    subgraph "Deployment Platform"
        Dyno["Heroku Dyno"]:::external
        Procfile["Procfile"]:::config
        Requirements["requirements.txt"]:::config
    end
    WebServer["Web Server/WSGI Container"]:::app
    subgraph "Application Layer"
        FlaskApp["Flask Application (q2.py)"]:::app
        TemplateEngine["Template Engine (Jinja2)"]:::app
        subgraph "View Templates"
            Index["index.html"]:::view
            QuizTemplate["quiz.html"]:::view
            LogTemplate["log.html"]:::view
            ConfirmQuit["confirm_quit.html"]:::view
        end
    end
    subgraph "Data Layer"
        Words["words.json"]:::datastore
        LogFile["Quiz Log File"]:::datastore
    end

    Client -->|"HTTP Request"| Dyno
    Dyno -->|"Executes Procfile"| WebServer
    WebServer -->|"Forwards request"| FlaskApp
    FlaskApp -->|"Loads quiz data"| Words
    FlaskApp -->|"Renders template"| TemplateEngine
    TemplateEngine --> Index
    TemplateEngine --> QuizTemplate
    TemplateEngine --> LogTemplate
    TemplateEngine --> ConfirmQuit
    FlaskApp -->|"Writes logs"| LogFile
    FlaskApp -->|"Sends response"| WebServer
    WebServer -->|"HTTP Response"| Client

    click FlaskApp "https://github.com/ttt3216/quiz_cs402/blob/main/q2.py"
    click Index "https://github.com/ttt3216/quiz_cs402/blob/main/templates/index.html"
    click QuizTemplate "https://github.com/ttt3216/quiz_cs402/blob/main/templates/quiz.html"
    click LogTemplate "https://github.com/ttt3216/quiz_cs402/blob/main/templates/log.html"
    click ConfirmQuit "https://github.com/ttt3216/quiz_cs402/blob/main/templates/confirm_quit.html"
    click Words "https://github.com/ttt3216/quiz_cs402/blob/main/words.json"
    click Procfile "https://github.com/ttt3216/quiz_cs402/tree/main/Procfile"
    click Requirements "https://github.com/ttt3216/quiz_cs402/blob/main/requirements.txt"

    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef app fill:#90EE90,stroke:#333,stroke-width:1px
    classDef view fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
```
