# hoaian2/college-quiz-app architecture

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

- Interactive diagram: https://gitdiagram.com/hoaian2/college-quiz-app
- Repository: https://github.com/hoaian2/college-quiz-app

## Overview

##### Main Components
- Frontend – the React application. Note the clear separation into pages, components, API modules, hooks, contexts, and styles. This represents the presentation layer.
- Backend – the Laravel application, which is organized into multiple areas:
– Controllers (both API and Web controllers) that receive the requests and respond.
– Models and Migrations: representing the data structure (as seen in the migrations for users, exams, roles, etc.) which together form the data access layer.
– Console Commands and Helper modules: supporting cron jobs (e.g., cleanup, exam cancellations) and maintenance tasks.
– Middleware, Requests, and Validation rules tailored to secure and standardize API interactions.
- Database – MySQL / MariaDB. Although it is assumed to be hosted externally or via Docker (depending on the deployment mode), it is critical to illustrate its place as the persistent data store.
- Cron Job/System Tasks – indicated by the scheduled Laravel commands and the docker/crontab configuration. This area handles recurring data cleanup and maintenance tasks.
- Docker & Deployment Environment – include a containerized deployment option with Docker files and docker-compose. Also, include components like Nginx and php-fpm, which are configured in the docker directory, as well as Redis mentioned in the Docker deployment setup.

##### Relationships and Interactions
- Internal backend processes such as scheduled tasks (cron jobs) that are configured either as Docker cron jobs or via Laravel’s scheduler.
- How Docker and other deployment configurations (Nginx, php-fpm) facilitate production deployment by connecting the containerized services.

##### Architectural Patterns and Design Principles
- MVC pattern in the backend is clear: Controllers, Models, and Views (or API responses and mail templates, for example).
- The separation of concerns is evident between the frontend and backend.
- Adoption of RESTful API principles; the frontend’s API modules correspond with backend API controllers.
- In addition, the project’s docker configuration prioritizes modularity of deployment by separating web server, php-fpm, and cron job concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Frontend Layer"
        fMain["Frontend (React UI) <br>React 19, TypeScript"]:::frontend
        fAPI["API Modules"]:::frontend
        fPages["Pages"]:::frontend
    end

    subgraph "Backend Layer"
        bMain["Backend (Laravel API & Business Logic) <br>Laravel 12, PHP 8.2+"]:::backend
        bAPI["API Controllers"]:::backend
        bWeb["Web Controllers"]:::backend
        bModels["Models"]:::backend
        bMigrations["Database Migrations"]:::backend
        bMiddleware["Middleware"]:::backend
        bRequests["Requests"]:::backend
        bConsole["Console Commands"]:::backend
    end

    subgraph "Deployment & Infrastructure"
        db["Database (MySQL/MariaDB)"]:::db
        cDockerCron["Docker Cronjob"]:::cron
        cLaravelCron["Laravel Scheduler"]:::cron
        dDocker["Docker Configuration"]:::docker
        dCompose["Docker Compose"]:::docker
        bBackup["Backup Service (NodeJS MySQL backup)"]:::backup
    end

    %% Relationships
    fMain -->|"HTTP_calls"| bAPI

    %% Frontend internal grouping (optional)
    fAPI --> fMain
    fPages --> fMain

    %% Backend internal relationships
    bMain --> bAPI
    bMain --> bWeb
    bMain --> bModels
    bMain --> bMigrations
    bMain --> bMiddleware
    bMain --> bRequests
    bMain --> bConsole

    %% Backend interacts with Database
    bModels -->|"Data_access"| db
    bMigrations --> db

    %% Scheduled tasks triggering backend commands
    cDockerCron -->|"Triggers"| bConsole
    cLaravelCron -->|"Triggers"| bConsole

    %% Docker components deploy the backend
    dDocker -->|"Hosts"| bMain
    dCompose -->|"Orchestrates"| dDocker

    %% Backup service interacts with Database
    bBackup -->|"Backs_up"| db

    %% Click Events for Frontend
    click fMain "https://github.com/hoaian2/college-quiz-app/tree/main/frontend/"
    click fAPI "https://github.com/hoaian2/college-quiz-app/tree/main/frontend/src/api"
    click fPages "https://github.com/hoaian2/college-quiz-app/tree/main/frontend/src/pages"

    %% Click Events for Backend
    click bMain "https://github.com/hoaian2/college-quiz-app/tree/main/backend/"
    click bAPI "https://github.com/hoaian2/college-quiz-app/tree/main/backend/app/Http/Controllers/Api"
    click bWeb "https://github.com/hoaian2/college-quiz-app/tree/main/backend/app/Http/Controllers/Web"
    click bModels "https://github.com/hoaian2/college-quiz-app/tree/main/backend/app/Models"
    click bMigrations "https://github.com/hoaian2/college-quiz-app/tree/main/backend/database/migrations"
    click bMiddleware "https://github.com/hoaian2/college-quiz-app/tree/main/backend/app/Http/Middleware"
    click bRequests "https://github.com/hoaian2/college-quiz-app/tree/main/backend/app/Http/Requests"
    click bConsole "https://github.com/hoaian2/college-quiz-app/tree/main/backend/app/Console/Commands"

    %% Click Events for Docker & Deployment
    click dDocker "https://github.com/hoaian2/college-quiz-app/tree/main/docker/"
    click dCompose "https://github.com/hoaian2/college-quiz-app/blob/main/docker-compose.yml"
    click cDockerCron "https://github.com/hoaian2/college-quiz-app/tree/main/docker/cronjob"
    click cLaravelCron "https://github.com/hoaian2/college-quiz-app/blob/main/backend/routes/console.php"

    %% Classes
    classDef frontend fill:#a0d8f1,stroke:#005f99,stroke-width:2px;
    classDef backend fill:#f1a0a0,stroke:#990000,stroke-width:2px;
    classDef db fill:#f7e7a7,stroke:#997a00,stroke-width:2px;
    classDef cron fill:#d3f7a7,stroke:#669900,stroke-width:2px;
    classDef docker fill:#c0a0f1,stroke:#5d0099,stroke-width:2px;
    classDef backup fill:#d8a0f8,stroke:#990099,stroke-width:2px;
```
