# xdarksyderx/ft_transcendence architecture

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

- Interactive diagram: https://gitdiagram.com/xdarksyderx/ft_transcendence
- Repository: https://github.com/xdarksyderx/ft_transcendence

## Overview

##### Project Type and Purpose
- This project (“ft_transcendence”) is built as a multi-microservice application.
- Its structure indicates support for multiple games (chess and pong) along with user authentication (“auth”), social features (“social”), and notifications.
- There’s a dedicated frontend component, and a gateway (likely based on Nginx) to route external requests.
- The overall purpose is to provide a full-featured online platform integrating interactive games with social and notification functionalities.

##### File Structure to Determine Architectural Components
- Main services are organized in individual directories:
– auth: Handles authentication and user management (login, logout, registration, OAuth callbacks, etc.).
– chess: Contains game logic for chess (multiple game modes and pieces logic).
– pong: Implements gameplay functionality for the pong game.
– social: Manages social interactions, including chat, friends, and related API endpoints.
– notifications: Provides asynchronous notifications and messaging features (with Celery tasks, RabbitMQ integration, and event handling).
- Separate frontend directory: Contains the web client’s assets like HTML, CSS, and JavaScript. It has its own Docker support (and reference to a lightweight web server via “lighttpd.conf”).
- Gateway directory: Contains configuration for a reverse proxy setup (using an Nginx configuration), which is key for routing incoming requests to the appropriate backend services.
- Each service contains its own configuration, Dockerfile, entrypoint scripts, and dev container setups ensuring isolation and independent deployment.

##### Key Components and Their Relationships
- Frontend:
– Acts as the client-facing part of the system.
– Communicates with the backend through API calls routed by the gateway.
- API Gateway:
– Serves as the reverse proxy, directing incoming HTTP/HTTPS requests to the correct microservice (auth, chess, pong, social, notifications).
– Manages security and may perform load balancing.
- Auth Service:
– Manages user authentication, OAuth logins, token management, and possibly session handling.
– Other services likely depend on it for verifying user identities and permissions.
- Game Services (Chess & Pong):
– Implement game logic, manage sessions/matches, and include various game modes.
– Use messaging (RabbitMQ) to notify other components or trigger tasks.
- Social Service:
– Provides features for chat, managing friends, and social interactions among users.
– Uses WebSockets or similar real-time communication mechanisms.
- Notifications Service:
– Centralizes the delivery of system notifications.
– Uses asynchronous tasks (Celery) and event-driven communication, as indicated by tasks and messaging utilities.
- Shared Infrastructure:
– RabbitMQ clients appear in several services (auth, chess, notifications, pong, social) suggesting a message-bus for asynchronous events.
– Each service has its own configuration (ASGI, WSGI, Celery apps) which may hint at a common framework (like Django or similar) used across the services.

##### Architectural Patterns and Design Principles
- Microservices Architecture:
– Each service is independently deployed, containerized (via Docker and devcontainer setups), and likely communicates over well-defined APIs.
– Use of a gateway emphasizes separation of concerns and decouples the frontend from backend service implementations.
- API-driven and Event-driven Communication:
– The presence of REST API endpoints, async messaging (RabbitMQ) and worker tasks (Celery) implies that services communicate both synchronously (via HTTP) and asynchronously.
- Containerization for Isolation:
– Dockerfiles in every major directory and a compose.yaml file indicate orchestration of multiple containers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend and Gateway
    FE["Frontend Client"]:::frontend
    GW["API Gateway"]:::gateway

    %% Backend Microservices
    A["Auth Service"]:::service
    CH["Chess Service"]:::service
    PO["Pong Service"]:::service
    SO["Social Service"]:::service
    NO["Notifications Service"]:::service

    %% Shared Infrastructure
    MQ(["RabbitMQ Message Broker"]):::shared

    %% Interactions: Client to Gateway to Services
    FE -->|"HTTP/API"| GW
    GW -->|"Route_to_Auth"| A
    GW -->|"Route_to_Chess"| CH
    GW -->|"Route_to_Pong"| PO
    GW -->|"Route_to_Social"| SO
    GW -->|"Route_to_Notifications"| NO

    %% Asynchronous Messaging via RabbitMQ
    A -->|"async_events"| MQ
    CH -->|"async_tasks"| MQ
    PO -->|"async_events"| MQ
    SO -->|"async_messages"| MQ
    NO -->|"celery_tasks"| MQ

    %% Click Events for Components
    click FE "https://github.com/xdarksyderx/ft_transcendence/tree/main/frontend/"
    click GW "https://github.com/xdarksyderx/ft_transcendence/blob/main/gateway/config/nginx.conf"
    click A "https://github.com/xdarksyderx/ft_transcendence/tree/main/auth/"
    click CH "https://github.com/xdarksyderx/ft_transcendence/tree/main/chess/"
    click PO "https://github.com/xdarksyderx/ft_transcendence/tree/main/pong/"
    click SO "https://github.com/xdarksyderx/ft_transcendence/tree/main/social/"
    click NO "https://github.com/xdarksyderx/ft_transcendence/tree/main/notifications/"

    %% Styles
    classDef frontend fill:#d4f4dd,stroke:#087f23,stroke-width:2px;
    classDef gateway fill:#d0e1f9,stroke:#1a75ff,stroke-width:2px;
    classDef service fill:#fff7d1,stroke:#e6ac00,stroke-width:2px;
    classDef shared fill:#e8d7f3,stroke:#a64ca6,stroke-width:2px;
```
