Skip to content

About

Final 42 Common Core project. ft_transcendence is a web-based Pong platform featuring a single-page application, real-time multiplayer, tournament system, and extensible modules for user management, AI, chat, and more.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

371 Commits

Folders and files

Repository files navigation

Ping Pong & Tic Tac Toe Gaming Platform

1. What is this app?

This is a full-stack web-based gaming platform that allows users to play Ping Pong and Tic Tac Toe games with real-time multiplayer functionality. The platform includes:

Core Features

  • Ping Pong Game: Classic arcade-style ping pong with multiple play modes

    • Remote Multiplayer: Play against opponents across the internet in real-time
    • Local Multiplayer: Two players can play on the same device
    • Tournament Mode: Competitive tournament system for multiple players
  • Tic Tac Toe Game: Strategic turn-based game with matchmaking

  • Real-Time Chat: Socket.io-based chat system for player communication

  • User Authentication System:

    • User registration and login
    • Two-Factor Authentication (2FA) for enhanced security
    • JWT (JSON Web Token) based session management
    • Secure logout functionality
  • Matchmaking System: Automated player matching for both Ping Pong and Tic Tac Toe games

Technology Stack

Frontend

  • Next.js (React framework with TypeScript)
  • TypeScript for type safety
  • Tailwind CSS for styling

Backend

  • Fastify (high-performance Node.js web framework)
  • SQLite database for data persistence
  • JWT for authentication
  • WebSocket for Ping Pong real-time gameplay
  • Socket.io for chat functionality

Monitoring & Observability

  • ELK Stack (Elasticsearch, Logstash, Kibana) for centralized logging
  • Prometheus for metrics collection
  • Grafana for metrics visualization and dashboards

2. How does it work?

Application Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         CLIENT LAYER                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚   Next.js Frontend (TypeScript + Tailwind CSS)            โ”‚   โ”‚
โ”‚  โ”‚   - Game UI (Ping Pong, Tic Tac Toe)                     โ”‚   โ”‚
โ”‚  โ”‚   - Authentication Forms (Login, Signup, 2FA)            โ”‚   โ”‚
โ”‚  โ”‚   - Chat Interface                                        โ”‚   โ”‚
โ”‚  โ”‚   - Tournament Dashboard                                  โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ†“ โ†‘
                    HTTPS / WebSocket / Socket.io
                              โ†“ โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         SERVER LAYER                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚   Fastify Backend Server                                  โ”‚   โ”‚
โ”‚  โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚   โ”‚
โ”‚  โ”‚   โ”‚ REST API     โ”‚ WebSocket    โ”‚ Socket.io        โ”‚     โ”‚   โ”‚
โ”‚  โ”‚   โ”‚ - Auth       โ”‚ - Pong Game  โ”‚ - Chat           โ”‚     โ”‚   โ”‚
โ”‚  โ”‚   โ”‚ - Users      โ”‚ - Matchmakingโ”‚ - Notifications  โ”‚     โ”‚   โ”‚
โ”‚  โ”‚   โ”‚ - Tournamentsโ”‚ - Game State โ”‚                  โ”‚     โ”‚   โ”‚
โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                              โ†“ โ†‘                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚   SQLite Database                                         โ”‚   โ”‚
โ”‚  โ”‚   - User accounts & profiles                             โ”‚   โ”‚
โ”‚  โ”‚   - Game history & statistics                            โ”‚   โ”‚
โ”‚  โ”‚   - Tournament data                                       โ”‚   โ”‚
โ”‚  โ”‚   - Chat messages                                         โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ†“ โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     MONITORING LAYER                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”‚
โ”‚  โ”‚   ELK Stack         โ”‚  โ”‚   Prometheus + Grafana        โ”‚     โ”‚
โ”‚  โ”‚   - Elasticsearch   โ”‚  โ”‚   - Metrics Collection        โ”‚     โ”‚
โ”‚  โ”‚   - Logstash        โ”‚  โ”‚   - Performance Dashboards    โ”‚     โ”‚
โ”‚  โ”‚   - Kibana          โ”‚  โ”‚   - Alerting                  โ”‚     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Application Flow

1. User Authentication Flow

User โ†’ Frontend (Login/Signup) โ†’ Backend API (JWT Generation)
                                       โ†“
                              Verify Credentials (SQLite)
                                       โ†“
                              Generate JWT Token + 2FA
                                       โ†“
                              Return Token to Frontend
                                       โ†“
                              Store Token (Client Side)

2. Ping Pong Game Flow (Remote Multiplayer)

Player 1 โ†’ Request Match โ†’ Backend Matchmaking System
                                    โ†“
                          Find Available Opponent
                                    โ†“
Player 2 โ† Match Found โ†โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ†“
Both Players Connect via WebSocket
            โ†“
Game State Synchronized in Real-Time
            โ†“
Player Input โ†’ Backend โ†’ Game Physics โ†’ Broadcast to Both Players
            โ†“
Game Ends โ†’ Save Results to SQLite โ†’ Update Player Stats

3. Tic Tac Toe Game Flow

Player โ†’ Request Match โ†’ Matchmaking โ†’ Find Opponent
                              โ†“
                    Create Game Session
                              โ†“
                    Players Take Turns
                              โ†“
            Move Validation โ†’ Update Game State
                              โ†“
                    Check Win/Draw Condition
                              โ†“
                    Game End โ†’ Save Results

4. Chat Flow

User โ†’ Type Message โ†’ Frontend
                         โ†“
              Send via Socket.io
                         โ†“
              Backend Receives
                         โ†“
         Broadcast to Connected Users
                         โ†“
         Save to SQLite (History)

5. Tournament Flow

Admin โ†’ Create Tournament โ†’ Register Players โ†’ Generate Brackets
                                                      โ†“
                                            Schedule Matches
                                                      โ†“
                                            Players Compete
                                                      โ†“
                                        Track Results & Rankings
                                                      โ†“
                                            Declare Winner

Component Communication

WebSocket (Ping Pong)

  • Real-time bidirectional communication
  • Low latency for fast-paced gameplay
  • Handles paddle movements, ball physics, and score updates

Socket.io (Chat)

  • Event-based communication
  • Automatic reconnection
  • Room-based messaging

REST API

  • User authentication endpoints
  • Game history and statistics
  • Tournament management
  • Profile updates

Monitoring & Logging Flow

Application Logs โ†’ Logstash โ†’ Elasticsearch โ†’ Kibana (Visualization)

Application Metrics โ†’ Prometheus โ†’ Grafana (Dashboards)
                                        โ†“
                                   Alerts & Notifications

3. How do I run it?

Prerequisites

Ensure you have the following installed:

  • Docker and Docker Compose
  • Make (for running Makefile commands)
  • Node.js (for local development)

Environment Configuration

Backend Environment Variables

Create a .env file in the ./backend directory:

PORT=8080
COOKIE_SECRET="your_cookie_secret"
ACCESS_TOKEN_SECRET="your_access_token_secre"
REFRESH_TOKEN_SECRET="your_refresh_token_secre"
SMTP_FROM="marouanegaming3@gmail.com"
SMTP_PASS="yxvg lhpn lymj kjau"
SMTP_USER="marouanegaming3@gmail.com"
SMTP_PORT="587"
SMTP_HOST="smtp.gmail.com"
IP_ADDRESS="IPADDRESS"

Important:

  • Replace your_cookie_secret, your_access_token_secret, and your_refresh_token_secret with strong random strings
  • For Gmail SMTP, generate an App Password
  • Replace YOUR_SERVER_IP with your actual server IP address

Frontend Environment Variables

Create a .env.local file in the ./frontend/source directory:

NEXT_PUBLIC_BACKEND_URL=https://YOUR_IP:8443
NEXT_PUBLIC_WSS_URL=wss://YOUR_IP:8443/ws

Replace YOUR_IP with your server's IP address.

Running the Application

Option 1: Run Everything (Recommended)

This will start the entire stack including backend, frontend, and monitoring services:

make all

This command will:

  1. Create a Docker network (devops-net)
  2. Build and start the backend service
  3. Build and start the frontend service
  4. Start the ELK stack (Elasticsearch, Logstash, Kibana)
  5. Start Prometheus and Grafana

Option 2: Run Components Individually

Start Backend Only:

make backend

Start Frontend Only:

make frontend

Start ELK Stack:

make elk

Start Prometheus & Grafana:

make prometheus grafana

Stop All Services

make down

Rebuild and Restart Everything

make re

Accessing the Application

Once running, you can access:

Service URL Default Credentials
Frontend http://localhost:3000 N/A
Backend API https://YOUR_IP:8443 N/A
Kibana (Logs) http://localhost:5601 N/A
Grafana (Metrics) http://localhost:3000 admin / admin
Prometheus http://localhost:9090 N/A

Monitoring Setup

ELK Stack (Logging)

The ELK stack is automatically configured when you run make elk. It includes:

Elasticsearch

  • Stores and indexes application logs
  • Accessible at http://localhost:9200

Logstash

  • Collects logs from the application
  • Processes and forwards to Elasticsearch

Kibana

  • Web interface for viewing and analyzing logs
  • Access at http://localhost:5601
  • Create dashboards to visualize log patterns
  • Set up alerts for error conditions

How to use:

  1. Navigate to Kibana at http://localhost:5601
  2. Go to "Discover" to view real-time logs
  3. Create visualizations and dashboards for monitoring
  4. Set up alerts for critical errors

Prometheus & Grafana (Metrics)

Prometheus and Grafana are started with make prometheus grafana.

Prometheus

  • Scrapes metrics from backend and frontend
  • Stores time-series data
  • Access at http://localhost:9090

Grafana

  • Visualizes metrics in beautiful dashboards
  • Access at http://localhost:3000
  • Default login: admin / admin

How to use:

  1. Access Grafana at http://localhost:3000
  2. Log in with default credentials (admin/admin)
  3. Add Prometheus as a data source:
    • Go to Configuration โ†’ Data Sources
    • Add Prometheus
    • URL: http://prometheus:9090
  4. Import or create dashboards to monitor:
    • Active users and game sessions
    • API response times
    • WebSocket connections
    • Database queries
    • System resources (CPU, memory)

Troubleshooting

Docker Network Error: If you see "network exists" warning, this is normal and can be ignored.

Port Conflicts: Ensure ports 3000, 8080, 8443, 5601, 9090 are not in use by other applications.

ELK Stack Permissions: The Makefile automatically sets up permissions for Elasticsearch data directories.

Services Not Starting: Check Docker logs:

docker-compose logs -f

Clean Start: To completely reset and restart:

make down
make all

Project Structure

.
โ”œโ”€โ”€ backend/                    # Fastify backend
โ”‚   โ”œโ”€โ”€ .env                   # Backend environment variables
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ frontend/                   # Next.js frontend
โ”‚   โ””โ”€โ”€ source/
โ”‚       โ”œโ”€โ”€ .env.local         # Frontend environment variables
โ”‚       โ””โ”€โ”€ ...
โ”œโ”€โ”€ elk-stack/                 # ELK configuration
โ”‚   โ””โ”€โ”€ docker-compose.yaml
โ”œโ”€โ”€ prometheus-grafana/        # Monitoring configuration
โ”‚   โ””โ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ docker-compose.yaml        # Main services
โ”œโ”€โ”€ Makefile                   # Build and run commands
โ””โ”€โ”€ README.md                  # This file

Happy Gaming! ๐ŸŽฎ๐Ÿ“

About

Final 42 Common Core project. ft_transcendence is a web-based Pong platform featuring a single-page application, real-time multiplayer, tournament system, and extensible modules for user management, AI, chat, and more.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages