# mtlks/ft_transcendence architecture

> Architecture diagram of the GitHub repository mtlks/ft_transcendence, 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/mtlks/ft_transcendence
- Repository: https://github.com/mtlks/ft_transcendence

## Overview

##### Overall Project Type & Purpose
- This is a full-stack application that appears to be a social/gaming platform. The backend is built using NestJS (as seen by files like nest-cli.json, multiple modules, and extensive use of controllers, services, and DTOs) while the frontend is a React application created with Vite.
- The project supports features such as user authentication (including Google OAuth and two-factor authentication), live chat (with dedicated chat gateways and controllers), gaming functionalities (entities and components for game rooms, players, and real-time game events for Pong and related mini-games), friend management, matchmaking, and leaderboards.
- Deployment is supported via Docker and docker-compose, which implies containerization is part of the overall strategy.

##### Analyzing the File Structure for Architectural Clues
- Top-level Directories:
– “backend”: Contains the NestJS server code with modules for auth, chat, friendship, game, leaderboard, match, status, TFA, and user-related functionalities. Notice a clear modular design for different application domains.
– “frontend”: Contains a React/Vite codebase set up with TypeScript. It includes dedicated directories for pages, components, widgets, and game logic, clearly separating presentation and business logic.
– Other directories include configuration files (e.g., .github, db_admin, Dockerfile, docker-compose.yml), which support CI/CD and local development.
- Architectural Patterns:
– The backend follows NestJS’s modular architecture (using modules, controllers, services, DTOs, and entities). The presence of Gateway files in modules like chat, friendship, game, and status suggests the use of WebSockets for real-time communication.
– The frontend structure separates UI components, API integration, contexts, and even specialized game logic, which reflects a component-based and context-driven design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FE["React Frontend (Vite, Tailwind CSS)"]:::frontend
        ChatW["Chat Widget"]:::frontend
        FriendW["Friends Widget"]:::frontend
        GameUI["Game Module UI"]:::frontend
        LeadW["Leaderboard Widget"]:::frontend
        Profile["Profile Component"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        NS["NestJS Server (Entry)"]:::backend
        Auth["Auth Module (Google OAuth, TFA)"]:::backend
        TFA["TFA Module"]:::backend
        ChatB["Chat Module (WebSocket Gateway)"]:::backend
        FriendB["Friendship Module (WebSocket Gateway)"]:::backend
        GameB["Game Module (Real-time Gameplay)"]:::backend
        Match["Match Module"]:::backend
        LeadB["Leaderboard Module"]:::backend
        Status["Status Module (WebSocket Gateway)"]:::backend
        UserMan["User Management Module"]:::backend
    end

    %% Persistence Subgraph
    subgraph "Persistence"
        DB["Database (TypeORM Entities)"]:::database
    end

    %% Deployment & External Subgraph
    subgraph "Deployment & External"
        Ext["External Services (OAuth, Mailer)"]:::external
        Dep["Docker, CI/CD, Config"]:::external
    end

    %% Interactions between Frontend and Backend
    FE -->|"REST_API"| NS
    FE -->|"WS"| ChatB
    FE -->|"WS"| GameB
    FE -->|"WS"| Status

    %% Routing within the Backend
    NS -->|"Routes_to"| Auth
    NS -->|"Routes_to"| TFA
    NS -->|"Routes_to"| ChatB
    NS -->|"Routes_to"| FriendB
    NS -->|"Routes_to"| GameB
    NS -->|"Routes_to"| Match
    NS -->|"Routes_to"| LeadB
    NS -->|"Routes_to"| UserMan

    %% Authorization dependency
    Auth -->|"Secures"| ChatB
    Auth -->|"Secures"| FriendB
    Auth -->|"Secures"| GameB
    Auth -->|"Secures"| Match
    Auth -->|"Secures"| LeadB
    Auth -->|"Secures"| UserMan

    %% Module interactions with the Persistence Layer
    Auth --> DB
    TFA --> DB
    ChatB --> DB
    FriendB --> DB
    GameB --> DB
    Match --> DB
    LeadB --> DB
    Status --> DB
    UserMan --> DB

    %% External services interaction
    Auth -->|"OAuth/Mailer"| Ext

    %% Deployment connections
    Dep --> FE
    Dep --> NS

    %% Style classes
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C7F9CC,stroke:#333,stroke-width:2px;
    classDef database fill:#F7D6AD,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#D3C0CD,stroke:#333,stroke-width:2px;
```
