How a-boudoun/ft_transcendence works
Project Type and Purpose
• This is a full-stack, real-time web application (“ft_transcendence”) that lets users authenticate via OAuth (42 or Google), chat in channels or direct messages, manage friends, and play live multiplayer Pong games or offline AI matches.
• Frontend: Next.js + React + Tailwind + Redux.
• Backend: NestJS (REST + WebSocket gateways) + TypeORM + JWT + 2FA.
• Database: PostgreSQL.
• Deployment: Docker Compose coordinates three containers (frontend, backend, database).
High-Level Architecture Components
a. Frontend Application
• UI Layer (Next.js pages/app router, React components)
• Client-side State (Redux store + React hooks)
• HTTP Client Module (Axios)
• WebSocket Client (chatSocket.ts / gameSocket)
b. Backend Application
• Auth Module (OAuth strategies, JWT guards, 2FA)
• Users Module (profile, settings, friendships)
• Chat Module (channels, channel owner/admin logic)
• Game Module (matchmaking, engine service, simulation)
• Room & UserGateway (real-time presence/status)
• TypeORM Entities (User, Channel, Friendship, GameHistory)
• REST Controllers (HTTP APIs)
• WebSocket Gateways (chat.gateway.ts, game.gateway.ts, room.gateway.ts, user.gateway.ts)
c. Database
• PostgreSQL storing all entities
d. External Services
• 42 OAuth API
• Google OAuth API
e. Infrastructure
• Docker Compose network linking frontend, backend, and Postgres
• Environment variables (.env, .env.local)
Relationships and Data Flows
1. User opens browser → Next.js UI components (React)
2. UI dispatches HTTP requests (Axios) → NestJS REST endpoints for:
– Authentication (OAuth handshake → JWT token issuance)
– Profile data, settings, friendship/channel CRUD
3. Upon successful login → Client stores JWT in cookie or local storage
4. Client establishes WebSocket connections (with JWT) to:
– Chat Gateway for channel messages, DMs, moderation events
– Game Gateway for matchmaking events, real-time game state updates
– Room Gateway for room/ownership events
– User Gateway for presence/status updates
5. Backend WebSocket gateways process events via their services, persist updates to Postgres, then broadcast messages back to subscribed clients
6. Backend services use TypeORM to read/write PostgreSQL
Architectural Patterns and Principles
• Layered architecture: UI → Application/API layer → Business logic (services) → Data access (ORM)
• Modular design (NestJS modules per domain) for separation of concerns
• CQRS-style split: REST for resource operations, WebSockets for real-time events
• Authentication via OAuth2 + JWT + optional 2FA
• State management in frontend (Redux) to unify UI, HTTP, and WebSocket data