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:
-
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
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
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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 โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
User โ Frontend (Login/Signup) โ Backend API (JWT Generation)
โ
Verify Credentials (SQLite)
โ
Generate JWT Token + 2FA
โ
Return Token to Frontend
โ
Store Token (Client Side)
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
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
User โ Type Message โ Frontend
โ
Send via Socket.io
โ
Backend Receives
โ
Broadcast to Connected Users
โ
Save to SQLite (History)
Admin โ Create Tournament โ Register Players โ Generate Brackets
โ
Schedule Matches
โ
Players Compete
โ
Track Results & Rankings
โ
Declare Winner
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
Application Logs โ Logstash โ Elasticsearch โ Kibana (Visualization)
Application Metrics โ Prometheus โ Grafana (Dashboards)
โ
Alerts & Notifications
Ensure you have the following installed:
- Docker and Docker Compose
- Make (for running Makefile commands)
- Node.js (for local development)
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, andyour_refresh_token_secretwith strong random strings - For Gmail SMTP, generate an App Password
- Replace
YOUR_SERVER_IPwith your actual server IP address
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/wsReplace YOUR_IP with your server's IP address.
This will start the entire stack including backend, frontend, and monitoring services:
make allThis command will:
- Create a Docker network (
devops-net) - Build and start the backend service
- Build and start the frontend service
- Start the ELK stack (Elasticsearch, Logstash, Kibana)
- Start Prometheus and Grafana
Start Backend Only:
make backendStart Frontend Only:
make frontendStart ELK Stack:
make elkStart Prometheus & Grafana:
make prometheus grafanamake downmake reOnce 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 |
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:
- Navigate to Kibana at
http://localhost:5601 - Go to "Discover" to view real-time logs
- Create visualizations and dashboards for monitoring
- Set up alerts for critical errors
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:
- Access Grafana at
http://localhost:3000 - Log in with default credentials (admin/admin)
- Add Prometheus as a data source:
- Go to Configuration โ Data Sources
- Add Prometheus
- URL:
http://prometheus:9090
- Import or create dashboards to monitor:
- Active users and game sessions
- API response times
- WebSocket connections
- Database queries
- System resources (CPU, memory)
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 -fClean Start: To completely reset and restart:
make down
make all.
โโโ 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! ๐ฎ๐