# r-argentina-programa/kahoot-clone architecture

> Architecture diagram of the GitHub repository r-argentina-programa/kahoot-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/r-argentina-programa/kahoot-clone
- Repository: https://github.com/r-argentina-programa/kahoot-clone

## Overview

##### Project type and purpose
- This is a full-stack, real-time “Kahoot” clone built with React (front-end), Node.js/Express + Socket.IO (back-end), and a relational database managed via CLI migrations/seeders.
- Core features: Hosts select and run quizzes; Users join games; real-time question delivery and score updates via WebSockets; persistent storage for trivias, questions, answers, players, games, and player answers.

##### File structure
- Monorepo with two top-level apps:
- back-end/ – Node.js service
- front-end/ – React app with Cypress e2e tests
- back-end layers under src/:
- config/ (DI setup)
- controller/ (HTTP + Socket.IO handlers)
- service/ (business logic)
- repository/ (data access abstraction)
- model/entity/mapper (ORM models, domain entities, DTO mapping)
- cli/ (DB migrations & seeders)
- front-end under src/:
- pages/ (route components for Host and User flows)
- components/ (UI widgets)
- assets, styles, index.js (app bootstrap)
- cypress/ (E2E tests)
- Key config/build files: package.json at root, back-end/.env.dist, front-end/public, etc.

##### README for additional insights
- Specifies real-time interaction via Socket.IO
- “npm run dev” concurrently runs Express (port 3001) and React dev server (port 3000)
- Host and User UIs communicate with the same back-end

##### Main components and interactions
a. Components:
1. Browser (Hosts and Users)
2. React Front-end (SPA served from Node or static build)
3. Node.js Back-end (Express + Socket.IO server)
4. Relational Database (PostgreSQL or similar via Sequelize)
5. CLI Tool (for migrations & seeding)
6. External Services (optional: Codeship CI)
b. Relationships & Data Flows:
- Browser ↔ React Front-end (served as JS/CSS/HTML)
- React ↔ Back-end via:
- REST HTTP API (for listing trivias, initial game setup)
- WebSocket channel (Socket.IO) for real-time question push, answer submissions, score broadcasts
- Back-end layers: Controller → Service → Repository → Database
- CLI Tool → Database (migrations/seeders)
- CI Server → GitHub → Auto-run tests (back-end unit tests, front-end Cypress e2e)
c. Architectural patterns & design principles:
- Layered MVC-style server architecture with clear separation: HTTP handlers (controllers), business logic (services), persistence (repositories), and domain mapping (mappers/entities/models)
- Dependency Injection configured in config/di.js
- Real-time event bus with Socket.IO integrated into Express controllers
- Monorepo organizing client & server side by domain
d. Key technologies:
- Front-end: React, React Router, CSS modules, Cypress for e2e
- Back-end: Node.js, Express, Socket.IO, Sequelize (migrations, models), Jest for unit tests
- CI: Codeship

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Front-end Layer
    subgraph "Front-end Layer"
        direction TB
        Browser["Browser (Host/User)"]:::frontend
        ReactApp["React SPA"]:::frontend
        subgraph "Front-end Source"
            direction TB
            Pages["Pages (Host/User flows)"]:::frontend
            Components["UI Components"]:::frontend
        end
        Cypress["Cypress E2E Tests"]:::cli
    end

    %% Back-end Layer
    subgraph "Back-end Layer"
        direction TB
        Express["Express + Socket.IO Server"]:::backend
        subgraph "Server Layers"
            direction TB
            DI["Dependency Injection (config/di.js)"]:::backend
            Controllers["HTTP & WebSocket Controllers"]:::backend
            Services["Business Logic Services"]:::backend
            Repositories["Data Repositories"]:::backend
            subgraph "Models & Entities"
                direction TB
                ORMModels["ORM Models"]:::backend
                Entities["Domain Entities"]:::backend
                Mappers["DTO & Entity Mappers"]:::backend
            end
        end
        ServerMock["Socket.IO Server Mock"]:::backend
        PublicHTML["Back-end Static HTML"]:::frontend
    end

    %% Database & Tools
    Database["Relational Database"]:::db
    CLI["CLI Tool (migrations & seeders)"]:::cli
    subgraph "CLI Resources"
        direction TB
        Migrations["Database Migrations"]:::cli
        Seeders["Database Seeders"]:::cli
    end

    %% CI Pipeline
    CI["CI Pipeline"]:::external

    %% Connections
    Browser -->|"loads SPA"| ReactApp
    ReactApp -->|"HTTP REST API"| Express
    ReactApp -->|"WebSocket (Socket.IO)"| Express
    Express -->|uses| DI
    DI -->|injects into| Controllers
    Controllers -->|"calls"| Services
    Services -->|"queries"| Repositories
    Repositories -->|"ORM queries"| Database
    Controllers -->|"emits/listens"| ServerMock
    CLI -->|"runs migrations"| Migrations
    CLI -->|"runs seeders"| Seeders
    Migrations -->|applies to| Database
    Seeders -->|applies to| Database
    CLI -->|initializes DB| Database
    Express -->|"serves SPA"| PublicHTML
    CI -->|tests| Express
    CI -->|tests| ReactApp

    %% Click Events
    click ReactApp "https://github.com/r-argentina-programa/kahoot-clone/blob/master/front-end/src/App.js"
    click PublicHTML "https://github.com/r-argentina-programa/kahoot-clone/blob/master/front-end/public/index.html"
    click Pages "https://github.com/r-argentina-programa/kahoot-clone/tree/master/front-end/src/pages/"
    click Components "https://github.com/r-argentina-programa/kahoot-clone/tree/master/front-end/src/components/"
    click Cypress "https://github.com/r-argentina-programa/kahoot-clone/tree/master/front-end/cypress/"
    click Express "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/server.js"
    click ServerMock "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/serverMock.js"
    click DI "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/src/config/di.js"
    click Controllers "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/src/controller/controller.js"
    click Services "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/src/service/service.js"
    click Repositories "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/src/repository/repository.js"
    click ORMModels "https://github.com/r-argentina-programa/kahoot-clone/tree/master/back-end/src/model/"
    click Entities "https://github.com/r-argentina-programa/kahoot-clone/tree/master/back-end/src/entity/"
    click Mappers "https://github.com/r-argentina-programa/kahoot-clone/tree/master/back-end/src/mapper/"
    click CLI "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/src/cli/init.db.js"
    click Migrations "https://github.com/r-argentina-programa/kahoot-clone/tree/master/back-end/src/cli/migrations/"
    click Seeders "https://github.com/r-argentina-programa/kahoot-clone/tree/master/back-end/src/cli/seeders/"
    click PublicHTML "https://github.com/r-argentina-programa/kahoot-clone/blob/master/back-end/public/index.html"

    %% Styles
    classDef frontend fill:#1E90FF,stroke:#000,color:#fff
    classDef backend fill:#32CD32,stroke:#000,color:#000
    classDef db fill:#FFA500,stroke:#000,color:#000
    classDef cli fill:#D3D3D3,stroke:#000,color:#000
    classDef external fill:#EEE,stroke-dasharray: 5 5,stroke:#000,color:#000
```
