# abdeladim-fadlane/42cursus-ft_transcendence architecture

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

- Interactive diagram: https://gitdiagram.com/abdeladim-fadlane/42cursus-ft_transcendence
- Repository: https://github.com/abdeladim-fadlane/42cursus-ft_transcendence

## Overview

##### Main Components
- Client (Browser): Represents the end-user’s interface where the game, chat, and authentication flows occur.
- Web Server (Frontend Layer):
– Located in the “WebServer” folder.
– Consists of static assets (HTML, CSS, JavaScript) and an Nginx configuration (nginx.conf) for routing.
– Acts as the entry point for users, providing the game’s landing pages and handling asset delivery.
- Authentication Service:
– Found under the “auth” directory.
– A Django project responsible for user authentication, registration, and authorization.
– Uses RESTful APIs and connects to a SQL database (PostgreSQL as noted in the README).
- Chat Service:
– Located in the “chat” folder (subdirectories “chatApp” and “chatlive”).
– Handles real-time chat functionality through Django Channels (WebSocket consumers) for in-game communication.
- Game Service:
– Found in the “game” folder.
– This service manages the core game logic, real-time multiplayer interactions (likely involving WebSockets), and game state.
- Tracking / Analytics Service:
– Found in the “track” folder.
– Monitors game events or user activity, further enhancing the interactive elements of the game.
- Additional Infrastructure:
– Docker Compose (docker-compose.yml) to orchestrate services.
– Individual Dockerfiles under “WebServer”, “auth”, and scripts in “chat”, “game”, and “track” to containerize each service.
– CI/CD configuration using GitHub workflows to build Docker images.

##### Out the Relationships and Interactions
- Client interacts with the Web Server (Nginx) which serves the static assets.
- The Web Server acts as a reverse proxy:
– Routes API calls to the Authentication Service for managing user data.
– Establishes WebSocket connections to the Chat and Game services for real-time communication.
- The Authentication Service uses SQL (PostgreSQL) for persisting user and game-related data.
- The Chat Service and Game Service communicate real-time data flows (players chatting and game state updates) typically via asynchronous channels enabled by Django Channels.
- The Tracking Service observes and records events happening in other services for game analytics and may interact with the database as required.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Each core function (authentication, chat, game logic, tracking) is separated into its own service.
- Containerization: Use of Docker and docker-compose to deploy isolated services.
- Asynchronous Communication: Use of WebSockets and Django Channels in chat and game services to manage real-time data.
- RESTful Design: APIs for handling authentication and potentially other data exchanges between services.
- Load Balancing & Scalability: Nginx is leveraged not only for serving static assets but also for directing traffic to microservices, ensuring smooth scalability.
- Security: Incorporation of robust authentication methods (OAuth 2.0 with 42 API integration) and secure API gateways.

##### Technologies, Frameworks, and External Links
- Django & Django Channels for backend logic and real-time functionality.
- PostgreSQL as the database management system.
- Nginx for routing and serving static content.
- Docker and docker-compose for containerization and orchestration.
- Additional dependencies such as Django Rest Framework are implied by the authentication and API components.
- Referenced links in the README provide further context on each technology’s role.

##### Final Detailed Architecture Breakdown
- Top Layer: Clients (Browsers) interacting via HTTPS.
- Middle Layer: Nginx-based Web Server handling static content and acting as a reverse proxy.
- Data Layer: PostgreSQL database supporting persistent storage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client / Browser"]:::clientStyle

    WebServer["Web Server (Nginx & Static Assets)"]:::webStyle

    subgraph "Backend Services"
        Auth["Authentication Service (Django - auth)"]:::serviceStyle
        Chat["Chat Service (Django Channels - chat)"]:::serviceStyle
        Game["Game Service (Django - game)"]:::serviceStyle
        Tracking["Tracking Service (Django - track)"]:::serviceStyle
    end

    DB["Database (PostgreSQL)"]:::dbStyle

    subgraph "Infrastructure"
        Container["Containerization (Docker)"]:::infraStyle
        CICD["CI/CD Pipeline"]:::infraStyle
    end

    %% Client to Web Server
    Client -->|"HTTPS"| WebServer

    %% Web Server routing to backend services
    WebServer -->|"REST_API"| Auth
    WebServer -->|"WebSocket"| Chat
    WebServer -->|"WebSocket"| Game
    WebServer -->|"Monitor"| Tracking

    %% Backend services connecting to Database
    Auth -->|"SQL"| DB
    Tracking -->|"Analytics"| DB

    %% Real-time asynchronous communication between Chat and Game services
    Chat -.->|"async"| Game
    Game -.->|"async"| Chat

    %% Infrastructure deploying services
    Container -->|"Deploys"| WebServer
    Container -->|"Deploys"| Auth
    Container -->|"Deploys"| Chat
    Container -->|"Deploys"| Game
    Container -->|"Deploys"| Tracking
    CICD -->|"Triggers"| Container

    %% Click Events for component mapping
    click WebServer "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/tree/main/WebServer/"
    click Auth "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/tree/main/auth/"
    click Chat "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/tree/main/chat/"
    click Game "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/tree/main/game/"
    click Tracking "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/tree/main/track/"
    click Container "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/blob/main/docker-compose.yml"
    click CICD "https://github.com/abdeladim-fadlane/42cursus-ft_transcendence/tree/main/.github/workflows/"

    %% Styling
    classDef clientStyle fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef webStyle fill:#F7D6AD,stroke:#333,stroke-width:2px;
    classDef serviceStyle fill:#FFF79A,stroke:#333,stroke-width:2px;
    classDef dbStyle fill:#C8FACC,stroke:#333,stroke-width:2px;
    classDef infraStyle fill:#D3C0EB,stroke:#333,stroke-width:2px;
```
