# pk13055/effective-giggle architecture

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

- Interactive diagram: https://gitdiagram.com/pk13055/effective-giggle
- Repository: https://github.com/pk13055/effective-giggle

## Overview

This project is an online judge system called “Assignment-DOJE” that is used to host programming problems, allow user registrations (as solvers or setters), and process problem submissions with corresponding error/success checks. It is a full-stack web application built primarily using Python (with Flask as its web framework), with static assets (CSS, JavaScript) provided by MaterializeCSS and jQuery. There are also various generator scripts to populate the database with sample users, problems, or comments.

##### Main Components

- Client/Browser Frontend:
- Represents the user-facing interface where users interact.
- Managed by HTML templates (Jinja2 files under app/templates) and static assets such as CSS/JS from MaterializeCSS, jQuery, and Prism.

- Web Server/Reverse Proxy:
- Nginx serves as the front-end web server. It handles incoming HTTPS requests using SSL, serves static files, and forwards dynamic requests to the application server using uWSGI.

- Application Server:
- uWSGI is used to run the Flask application.
- The Flask application structure resides in the “app” directory. Notice submodules (Home, Problem, User, Comments, Checks, and specialized modules like flask_cas for single sign-on support).

- Business Logic Layer:
- The “controllers” and “helper” modules in each subdirectory (app/Home, app/User, app/Problem, etc.) represent the business logic and endpoint handlers.
- There is also a “models.py” that likely defines data relationships.

- Data Storage:
- The SQLite database file (safe.db) stored at the project root acts as the repository for persistent data (users, problems, submissions, etc.).
- Additionally, “Datasets” provide auxiliary data (emails, names, tags) that may be used during problem generation or user creation.

- Code Generation/Seed Scripts:
- Generator scripts (located in the “genrators” directory) such as comment_gen.py, problem_gen.py, and user_gen.py are used to populate the database with sample data.

- File Uploads and User Submitted Data:
- The “uploads” directory handles user submissions, test cases, problem texts, editorials, and solution files.

- External Libraries/Dependencies:
- Static libraries like jQuery, MaterializeCSS, and Prism.
- Flask’s own modules including flask_cas for authentication.

##### Relationships and Interactions

- A user interacts via a browser with the static content (HTML/CSS/JS) rendered using Jinja2 templates.
- The browser sends HTTP(S) requests to Nginx, which routes them:
- Requests for static assets are served directly.
- Dynamic requests are proxied to uWSGI.
- uWSGI runs the Flask app, calling appropriate controller methods (e.g., for Home, User, Problem, Comments).
- Controllers in the app forward business logic calls to helper functions or the problem_maker/user_maker modules to process logic (like generating or solving problems).
- Data read/write interactions are handled through “models.py” by communicating with the safe.db database.
- Separate modules handle problem generation and evaluation (for example, in app/Generators and app/Solver) to compile and run user programs, capture input/output, and error messages.
- The “flask_cas” module facilitates authentication and routing for single sign-on.

##### Architectural Patterns and Design Principles

- Modular Separation: Each functional area is split into its own module (e.g., Home, User, Problem, Comments) with controllers and helpers, promoting separation of concerns.
- MVC Inspiration: While not strictly MVC, the structure divides presentation (templates), business logic (controllers/helpers), and data (models/database).
- Reverse Proxy and Application Server Separation: Using Nginx and uWSGI clearly delineates concerns for security, static asset serving, and request load balancing.
- Extensibility & Configuration:
- The presence of separate generator scripts and clearly identified configuration files (config.py, uuwsgi.ini, uwsgi.ini) support easy scalability and customization.

##### Key Technologies and Frameworks

- Python (with Flask) – primary backend framework.
- uWSGI – for deploying the Flask app.
- Nginx – reverse proxy and static asset server.
- SQLite (or similar relational DB) – for storage (safe.db).
- MaterializeCSS, jQuery, Prism – for frontend UI design.
- Additional components like flask_cas for authentication.

- Clear labels:
- “Browser/Client UI”
- “Nginx (SSL Termination & Static File Server)”
- “uWSGI Application Server”
- “Flask Application” with submodules (Controllers: Home, User, Problem, Comments; Helpers; Models)
- “Database (safe.db)” and “Datasets”
- “Upload Storage” for problem texts, submissions, images
- “Generator Scripts” for seeding users, problems, comments
- “External Libraries” such as MaterializeCSS and jQuery (could be a note or grouped with Browser UI)

- From Browser to Nginx (requests for both static and dynamic content).
- From Nginx to uWSGI (dynamic request forwarding).
- Between Flask controllers and the Database.
- Between Flask modules and external authentication & file services.

- Visual Distinctions:

##### Detailed Execution

- “Uploads” directory as a shared resource accessible by the Flask app.
- Optionally, sketch out how generator scripts tie into the database seeding process (these are typically run as one-off commands).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side Layer
    A["Browser/Client UI"]:::client
    B["HTML Templates"]:::template
    C["Static Assets"]:::static

    %% Web Server Layer
    D["Nginx (SSL Termination & Static File Server)"]:::web

    %% Deployment Configuration Layer
    subgraph "Deployment Config"
        D1["Deployment Config 1"]:::config
        D2["Deployment Config 2"]:::config
    end

    %% Application Server Layer
    E["uWSGI Application Server"]:::appserver
    F["Flask Application"]:::flask

    %% Flask Submodules
    subgraph "Flask Modules"
        F1["Home Module"]:::module
        F2["User Module"]:::module
        F3["Problem Module"]:::module
        F4["Comments Module"]:::module
        F5["Checks Module"]:::module
        F6["Authentication Module"]:::module
        F7["Business Logic (Models)"]:::module
        F8["Solver Module"]:::module
    end

    %% Data Storage and File Uploads
    G["Database (safe.db)"]:::database
    H["Datasets"]:::database
    I["Uploads Directory"]:::storage

    %% Code Generation / Seed Scripts
    J["Generator Scripts"]:::script
    K["Sample Problem Generator"]:::script

    %% Connections for Client Layer
    A -->|"requests"| D
    D -->|"forwards"| D1
    D1 --> D2
    D2 -->|"routes to"| E
    E -->|"runs"| F

    %% Flask Application interactions
    F -->|"executes"| F1
    F -->|"executes"| F2
    F -->|"executes"| F3
    F -->|"executes"| F4
    F -->|"executes"| F5
    F -->|"executes"| F6
    F -->|"accesses"| F7
    F -->|"triggers"| F8

    %% Data Layer interactions
    F7 -->|"queries/updates"| G
    F8 -->|"reads files"| I

    %% Generator scripts seeding data
    J -->|"populates"| G
    K -->|"populates"| G
    G --- H

    %% Flask Application serves content to Browser via templates and assets
    F -->|"renders"| B
    F -->|"serves"| C
    B -->|"displayed on"| A
    C -->|"displayed on"| A

    %% Click Events
    click B "https://github.com/pk13055/effective-giggle/tree/master/app/templates"
    click C "https://github.com/pk13055/effective-giggle/tree/master/app/static"
    click D1 "https://github.com/pk13055/effective-giggle/blob/master/uuwsgi.ini"
    click D2 "https://github.com/pk13055/effective-giggle/blob/master/uwsgi.ini"
    click F "https://github.com/pk13055/effective-giggle/tree/master/app"
    click F1 "https://github.com/pk13055/effective-giggle/tree/master/app/Home"
    click F2 "https://github.com/pk13055/effective-giggle/tree/master/app/User"
    click F3 "https://github.com/pk13055/effective-giggle/tree/master/app/Problem"
    click F4 "https://github.com/pk13055/effective-giggle/tree/master/app/Comments"
    click F5 "https://github.com/pk13055/effective-giggle/tree/master/app/Checks"
    click F6 "https://github.com/pk13055/effective-giggle/tree/master/app/flask_cas"
    click F7 "https://github.com/pk13055/effective-giggle/blob/master/app/models.py"
    click G "https://github.com/pk13055/effective-giggle/blob/master/safe.db"
    click H "https://github.com/pk13055/effective-giggle/tree/master/Datasets"
    click J "https://github.com/pk13055/effective-giggle/tree/master/genrators"
    click K "https://github.com/pk13055/effective-giggle/tree/master/app/Generators"
    click I "https://github.com/pk13055/effective-giggle/tree/master/uploads"
    click F8 "https://github.com/pk13055/effective-giggle/tree/master/app/Solver"

    %% Styles
    classDef client fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef template fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef static fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef web fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef config fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef appserver fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef flask fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef module fill:#fefefe,stroke:#818182,stroke-width:2px;
    classDef database fill:#d6d8db,stroke:#343a40,stroke-width:2px;
    classDef storage fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef script fill:#c3e6cb,stroke:#155724,stroke-width:2px;
```
