A real-time multiplayer ping pong game built with Django, WebSockets, and vanilla JavaScript. This project features online matchmaking, tournaments, user authentication with 2FA, and comprehensive game statistics tracking.
- 1v1 Matches: Real-time ping pong matches between two players
- Tournament Mode: Multi-player tournaments with bracket system
- Spectator Mode: Watch ongoing matches in real-time
- Friend System: Add friends, view online status, and challenge them directly
- User Profiles: Detailed statistics, match history, and performance tracking
- Leaderboards: Rankings based on wins, losses, and performance metrics
- OAuth2 Integration: Login with external providers
- Two-Factor Authentication (2FA): Enhanced security with TOTP support
- JWT Token Management: Secure session handling
- Multi-factor Authentication: QR code generation for authenticator apps
- Match History: Complete record of all played games
- Performance Metrics: Win rates, average rally length, score tracking
- Statistical Analysis: Charts and graphs showing player progression
- Tournament Results: Bracket visualization and results tracking
- WebSocket Integration: Real-time game updates and communication
- Live Matchmaking: Automatic player matching system
- Online Status: Real-time friend online/offline status
- Live Game Updates: Ball position, scores, and game state synchronization
- Django 5.1.2: Web framework and API
- Django REST Framework: RESTful API development
- Django Channels: WebSocket support for real-time features
- PostgreSQL: Primary database
- Socket.IO: Real-time bidirectional communication
- JWT Authentication: Secure token-based authentication
- Docker: Containerization and deployment
- Vanilla JavaScript: Pure JS implementation without frameworks
- CSS Modules: Modular styling approach
- WebSocket Client: Real-time communication with backend
- Responsive Design: Mobile and desktop compatibility
- Docker Compose: Multi-container orchestration
- Nginx: Reverse proxy and static file serving
- SSL/TLS: HTTPS security implementation
- Environment Configuration: Separate development and production settings
pingpong/
โโโ backend/ # Django backend application
โ โโโ api/ # Main API endpoints
โ โโโ users/ # User authentication and management
โ โ โโโ accounts/ # User accounts and OAuth2
โ โ โโโ friends/ # Friend system implementation
โ โ โโโ status/ # Online status tracking
โ โโโ ingame/ # Game logic and mechanics
โ โโโ matchmaking/ # Player matching system
โ โโโ tournament/ # Tournament management
โ โโโ pingpong_history/ # Game history and statistics
โโโ frontend/ # Vanilla JavaScript frontend
โ โโโ src/
โ โ โโโ Components/ # Reusable UI components
โ โ โโโ Pages/ # Application pages
โ โ โโโ Controller/ # API communication logic
โ โ โโโ Utils/ # Utility functions
โ โโโ css/ # Styling and CSS modules
โโโ docker-compose.yml # Container orchestration
-
Clone the repository
git clone <repository-url> cd pingpong
-
Backend Setup
cd backend python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt python manage.py migrate python manage.py runserver
-
Frontend Setup
cd frontend # Serve static files (development server needed)
-
Start all services
docker-compose -f docker-compose.develop.yml up --build
-
Access the application
- Frontend:
http://localhost:3000 - Backend API:
http://localhost:8000 - Admin Panel:
http://localhost:8000/admin
- Frontend:
-
Build and deploy
docker-compose up -d --build
-
Configure SSL certificates
- Place your SSL certificates as
cert.crtandcert.key - Nginx is configured for HTTPS
- Place your SSL certificates as
The project includes comprehensive API documentation:
- Swagger UI: Available at
/api/schema/swagger-ui/ - ReDoc: Available at
/api/schema/redoc/ - OpenAPI Schema: Available at
/api/schema/
- Physics-based ball movement and collision detection
- Paddle controls with mouse or keyboard input
- Power-ups and special ball effects
- Adjustable game settings (ball speed, paddle size, etc.)
- Skill-based player matching
- Queue management for fair matches
- Tournament bracket generation
- Spectator room management
- Traditional ping pong scoring rules
- Rally counting and statistics
- Performance metrics calculation
- Ranking system based on ELO-like algorithm
cd backend
pytest# Authentication tests
pytest users/accounts/two_factor_auth/tests/
# Game logic tests
pytest ingame/tests.py
# Tournament tests
pytest tournament/tests/- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Create a .env file in the backend directory:
DEBUG=True
SECRET_KEY=your-secret-key
DATABASE_URL=postgresql://user:password@localhost:5432/pingpong
ALLOWED_HOSTS=localhost,127.0.0.1
CORS_ALLOWED_ORIGINS=http://localhost:3000This project is licensed under the MIT License - see the LICENSE file for details.
- Built as part of a web development learning project
- Inspired by classic ping pong arcade games
- Uses modern web technologies for real-time gaming experience