# contacthachami/2pi_teacher_dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/contacthachami/2pi_teacher_dashboard
- Repository: https://github.com/contacthachami/2pi_teacher_dashboard

## Overview

##### Project type and purpose
- This is a full-stack web application (“2pi Dashboard”) that provides teachers with an interactive math quiz platform.
- Frontend: React-based SPA (Vite, TailwindCSS, React Context, React Router).
- Backend: Laravel REST API (Eloquent models, controllers, Sanctum authentication).

##### File structure
- Top-level directories:
- FrontEnd/ — React project directories (public, src/components, src/context, src/services, src/hooks, src/pages, src/translations)
- BackEnd/ — Laravel project directories (app/Http/Controllers, app/Models, config/, database/migrations & seeders, routes/, resources/, storage/)
- Patterns:
- Backend uses MVC: Controllers ←→ Models → Database (migrations/seeders).
- Frontend uses component-based UI + Context providers for cross-cutting state (Auth, Theme, Language, Notifications, Loading).
- RESTful routes (api.php) exposed by Laravel, consumed via Axios in src/services/api.js.
- Config & deployment: .env.example files, webpack/Vite config (vite.config.js), Tailwind configuration, public/index.html (FE), public/index.php (BE).

##### README for additional insights
- Key features: Quiz creation, levels, question types, progress tracking, internationalization, theming.
- Tech stack details: React18, Vite6, Laravel, Sanctum, MySQL/PostgreSQL.
- Data flows: Auth flow, quiz creation flow, management flow, user settings flow.

a. Main components
- Frontend SPA (React app hosted via Vite/public)
- API Gateway (Laravel controllers exposed under /api)
- Business Logic (Laravel services, Controllers)
- Data Layer (Eloquent Models → MySQL/PostgreSQL)
- Stateless Auth (Sanctum issuing & validating tokens)
- Storage (Laravel storage/app for assets, logs)
- External Services (SMTP for password reset emails, optional analytics/monitoring)
b. Relationships & interactions
- Browser → React SPA → Axios HTTP calls → Laravel API
- API Controllers → Eloquent Models → Database
- AuthContext in front → /api/login, /api/register, token storage in localStorage → subsequent API calls with Bearer token
- Quiz flows: Create/Read/Update/Delete via POST/GET/DELETE endpoints
- Notification flow: Polling or push via GET/POST notification endpoints
c. Architectural patterns & principles
- Separation of concerns: Presentation (React components) vs. API (Laravel controllers) vs. Data (models & migrations)
- Component-based UI + Context for global state
- RESTful design for CRUD operations
- MVC on backend, SPA on frontend
- Environment-driven configuration (.env)
d. Relevant technologies/frameworks
- Frontend: React, Vite, TailwindCSS, Axios, React Router, Zod, react-hot-toast, framer-motion
- Backend: Laravel, Sanctum, Eloquent ORM, MySQL/PostgreSQL, PHPUnit for tests, Mailer for emails

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User[/"User (Browser)"/]:::user

    %% Client Side
    subgraph "React App"
        UIComp["UI Components"]:::frontend
        AuthCtx["AuthContext"]:::context
        ThemeCtx["ThemeContext"]:::context
        LangCtx["LanguageContext"]:::context
        NotifCtx["NotificationContext"]:::context
        LoadingCtx["LoadingContext"]:::context
        APIService["api.js"]:::service
        AuthService["auth.js"]:::service
        Hooks["Custom Hooks"]:::frontend
        Pages["Pages/Routes"]:::frontend
        Trans["Internationalization"]:::frontend
        Config["Build & Entry Config"]:::frontend
    end

    %% Server Side
    subgraph "Laravel App"
        subgraph "API Controllers"
            AuthController["AuthController"]:::backend
            GameController["GameController"]:::backend
            GetGamesController["GetGamesController"]:::backend
            RemoveGameController["RemoveGameController"]:::backend
            NotificationController["NotificationController"]:::backend
        end
        Routes["API Routes"]:::backend
        ServiceProv["AppServiceProvider"]:::backend
        subgraph "Eloquent Models"
            User["User"]:::model
            Game["Game"]:::model
            Level["Level"]:::model
            BalloonType["BalloonType"]:::model
            BalloonAnswer["BalloonAnswer"]:::model
            BoxQuestionAnswer["BoxQuestionAnswer"]:::model
            NotificationModel["Notification"]:::model
            LoginModel["Login"]:::model
        end
        Migrations["Database Migrations"]:::backend
        Seeders["Seeders & Factories"]:::backend
        AuthConfig["Sanctum Config"]:::backend
        MailConfig["Mail & Templates"]:::backend
        Storage["Storage"]:::backend
        BackPublic["Public Assets"]:::backend
        EnvConfig["Env & Config"]:::backend
        Tests["Testing"]:::backend
    end

    %% Database & External
    Database[(Database)]:::database
    SMTP["SMTP Service"]:::external

    %% Flows
    User --> UIComp
    UIComp --> AuthCtx
    UIComp --> ThemeCtx
    UIComp --> LangCtx
    UIComp --> NotifCtx
    UIComp --> LoadingCtx
    UIComp --> Pages
    AuthCtx --> APIService
    AuthCtx --> AuthService
    APIService -->|"HTTP/HTTPS"| Routes
    AuthService --> Routes
    Pages --> APIService
    Hooks --> APIService
    Trans --> APIService
    Config --> UIComp

    Routes --> AuthController
    Routes --> GameController
    Routes --> GetGamesController
    Routes --> RemoveGameController
    Routes --> NotificationController

    AuthController --> ServiceProv
    GameController --> ServiceProv
    GetGamesController --> ServiceProv
    RemoveGameController --> ServiceProv
    NotificationController --> ServiceProv

    ServiceProv --> User
    ServiceProv --> Game
    ServiceProv --> Level
    ServiceProv --> BalloonType
    ServiceProv --> BalloonAnswer
    ServiceProv --> BoxQuestionAnswer
    ServiceProv --> NotificationModel
    ServiceProv --> LoginModel

    User --> Database
    Game --> Database
    Level --> Database
    BalloonType --> Database
    BalloonAnswer --> Database
    BoxQuestionAnswer --> Database
    NotificationModel --> Database
    LoginModel --> Database

    AuthController --> AuthConfig
    AuthController --> MailConfig
    NotificationController --> SMTP

    Migrations --> Database
    Seeders --> Database

    BackPublic --> AuthController
    EnvConfig -.-> AuthController
    Tests --> AuthController

    %% Click Events - Frontend
    click UIComp "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/components"
    click AuthCtx "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/context"
    click ThemeCtx "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/context"
    click LangCtx "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/context"
    click NotifCtx "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/context"
    click LoadingCtx "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/context"
    click APIService "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/FrontEnd/src/services/api.js"
    click AuthService "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/FrontEnd/src/services/auth.js"
    click Hooks "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/hooks"
    click Pages "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/pages"
    click Trans "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/FrontEnd/src/translations"
    click Config "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/FrontEnd/src/main.jsx"

    %% Click Events - Backend
    click AuthController "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Http/Controllers/AuthController.php"
    click GameController "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Http/Controllers/GameController.php"
    click GetGamesController "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Http/Controllers/GetGamesController.php"
    click RemoveGameController "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Http/Controllers/RemoveGameController.php"
    click NotificationController "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Http/Controllers/NotificationController.php"
    click Routes "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/routes/api.php"
    click ServiceProv "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Providers/AppServiceProvider.php"
    click User "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/User.php"
    click Game "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/Game.php"
    click Level "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/Level.php"
    click BalloonType "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/BalloonType.php"
    click BalloonAnswer "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/BalloonAnswer.php"
    click BoxQuestionAnswer "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/BoxQuestionAnswer.php"
    click NotificationModel "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/Notification.php"
    click LoginModel "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/app/Models/Login.php"
    click Migrations "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/BackEnd/database/migrations"
    click Seeders "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/database/seeders/DatabaseSeeder.php"
    click AuthConfig "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/config/sanctum.php"
    click MailConfig "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/config/mail.php"
    click Storage "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/BackEnd/storage/app"
    click BackPublic "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/public/index.php"
    click EnvConfig "https://github.com/contacthachami/2pi_teacher_dashboard/blob/main/BackEnd/.env.example"
    click Tests "https://github.com/contacthachami/2pi_teacher_dashboard/tree/main/BackEnd/tests/Feature"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#DFFFD0,stroke:#228B22,color:#228B22
    classDef model fill:#FFE0B2,stroke:#EF6C00,color:#EF6C00
    classDef database fill:#C8E6C9,stroke:#388E3C,color:#388E3C
    classDef external fill:#F0F0F0,stroke:#888888,color:#888888
    classDef user fill:#FFF9C4,stroke:#FBC02D,color:#F57F17
    classDef service fill:#E1BEE7,stroke:#8E24AA,color:#6A1B9A
    classDef context fill:#FFCDD2,stroke:#E53935,color:#B71C1C
```
