How mkadri66/ft_transcendence works
Project Type and Purpose
– This is a full-stack, containerized web application built for the 42 curriculum. Its primary feature is a local-multiplayer Pong game wrapped in an SPA, with user authentication (Google Sign-In + MFA), JWT-secured REST APIs, and persistent data storage in SQLite.
Top-Level Architecture from the File Tree
a. “frontend” directory
• Vite-based SPA (HTML/CSS/JavaScript/TypeScript + Tailwind).
• Implements router.ts, view components (home, dashboard, game, profile, etc.).
b. “backend” directory
• Fastify server (server.js) exposing REST endpoints (routes/…).
• MVC-style folder layout:
– config (db.js, env.js)
– controllers (authController.js, mfaController.js)
– middlewares (cors, helmet)
– routes (auth, mfa, tournament, profile, etc.)
c. “db” directory
• SQLite file (database.sqlite).
d. Orchestration files
• docker-compose.yml (defines “frontend” and “backend” services + shared volume for uploads/db)
• Dockerfiles in both sub-projects.
– Client (Browser)
• SPA served by the frontend container on port X
• Contains Router, View Layer, Pong Game Canvas
– Frontend Container (Node + Vite)
• Bundles TS/JS/CSS, serves index.html, static assets
– Backend Container (Node + Fastify)
• REST API Layer (routes → controllers → services)
• Auth subsystem (Google OAuth, JWT issuance)
• MFA subsystem (TOTP QR-code generation + validation)
• File upload handler for avatars (uploads/)
– Database (SQLite)
• Persistent store for users, sessions, tournament results
– External Service
• Google OAuth 2.0 endpoints
Interactions and Data Flow
• Client ↔ Frontend: HTTP GET/WS (if used) to fetch static assets and run the SPA
• Client ↔ Backend: HTTPS POST/GET for user flows (login, register, JWT validation, game state if server-backed)
• Backend ↔ SQLite: SQL queries via db.js
• Backend ↔ Google OAuth: OAuth2 token exchange
• Orchestration: Docker-Compose network connecting frontend & backend; shared volumes for uploads and DB
Architectural Patterns & Design Principles
– Separation of Concerns: clear split between UI (frontend) and business logic (backend)
– MVC-style in backend: route definitions → controller logic → data/config layers
– Containerization: each major component lives in its own Docker container, orchestrated via docker-compose
– Security First: cors.js, helmet.js, JWT, MFA