- Overview
- Live Demo
- Features
- Technologies Used
- Getting Started
- Usage
- Architecture
- Development Journey
- Future Enhancements
- Team
FourFury is a sophisticated implementation of the classic Connect Four game, built with modern web technologies. It offers multiple game modes including AI opponents with adjustable difficulty levels and real-time online multiplayer matches.
The project consists of:
- A robust FastAPI backend with Socket.IO for real-time communication
- A responsive Next.js frontend with smooth animations and intuitive controls
- Redis-powered caching and real-time features
- MongoDB for persistent data storage
For detailed technical documentation:
- Multiple game modes:
- Player vs AI with adjustable difficulty (1-5)
- Local multiplayer
- Online multiplayer with real-time updates
- Smart move validation and win detection
- Responsive design works on all devices
- Beautiful animations and visual effects
- Dark/Light theme support
- Anonymous play with persistent sessions
- Real-time game state synchronization
- Player presence tracking
- Automatic forfeit on disconnect
- Rematch system
- Game state preservation on refresh
- Efficient game state management
- Real-time WebSocket communication
- Redis-powered caching system
- Scalable MongoDB backend
- Modern React frontend with Next.js
- Type-safe with TypeScript and Python type hints
For detailed technical specifications and setup instructions, please refer to the respective frontend and backend README files.
- Docker Engine 24.0.0+
- Docker Compose V2 2.20.0+
- For Frontend:
- Node.js 20.0.0+
- npm 10.0.0+ or Yarn 1.22.0+
- For Backend:
- Python 3.10+
- Poetry package manager
- MongoDB 7.0+
- Redis 7.2+
-
Clone the repository:
git clone https://github.com/hackerSa3edy/FourFury.git cd FourFury
-
Configure environment variables:
# For backend # Modify backend/.env.docker if needed (default values should work) # For frontend # Modify frontend/.env.docker if needed (default values should work)
-
Build and start the containers:
docker compose up --build
-
Access the application:
- Frontend: http://localhost
- Backend API: http://localhost/api
-
Clone the repository as shown above
-
Setup Frontend:
cd frontend npm install cp .example.env.local .env.local # Modify .env.local with your configuration npm run build npm start
-
Setup Backend:
cd backend poetry install cp .env.example .env # Modify .env with your configuration poetry run uvicorn src.fourfury.run:app --reload
-
Setup MongoDB and Redis locally
Our docker-compose.yml sets up a complete development environment with five services:
-
nginx (Port 80):
- Reverse proxy handling routing between frontend and backend
- Load balancing and SSL termination (if configured)
- Routes
/api/*
to backend - Routes
/socket.io/*
to backend WebSocket - Routes all other traffic to frontend
- Handles SSL termination (in production)
-
frontend (Next.js):
- Serves the React application
- Automatically rebuilds on code changes
- Connects to backend through nginx proxy
-
backend (FastAPI):
- Handles API requests and WebSocket connections
- Auto-reloads during development
- Configured through .env.docker
-
db (MongoDB):
- Persistent game data storage
- Volume mounted for data persistence
- Accessible to backend service
-
redis (Redis):
- Handles caching and real-time features
- Configured for keyspace notifications
- Persists data through mounted volume
-
Rebuild single service:
docker compose up -d --build [service_name]
-
Reset data (clear volumes):
docker compose down -v
-
Check service status:
docker compose ps
-
If services fail to start:
docker compose down docker compose up --build
-
Check service logs:
docker compose logs [service_name]
-
Verify network connectivity:
docker compose exec [service_name] ping [other_service]
graph TB
Client[Browser Client]
Nginx[Nginx Reverse Proxy]
Frontend[Next.js Frontend]
Backend[FastAPI Backend]
Redis[Redis Cache]
MongoDB[MongoDB Database]
Client --> Nginx
Nginx --> Frontend
Nginx --> Backend
Backend <--> Redis
Backend <--> MongoDB
Client <-.->|WebSocket| Nginx
Nginx <-.->|WebSocket| Backend
FourFury
โโโ .gitignore
โโโ LICENSE
โโโ README.md
โโโ backend
โ โโโ .dockerignore
โ โโโ .env.docker
โ โโโ .env.example
โ โโโ .pre-commit-config.yaml
โ โโโ Dockerfile
โ โโโ Makefile
โ โโโ README.md
โ โโโ docs
โ โโโ poetry.lock
โ โโโ poetry.toml
โ โโโ pyproject.toml
โ โโโ src
โ โโโ tests
โโโ docker-compose.yml
โโโ frontend
โ โโโ .env.docker
โ โโโ .example.env.local
โ โโโ .gitignore
โ โโโ Dockerfile
โ โโโ README.md
โ โโโ eslint.config.mjs
โ โโโ next.config.ts
โ โโโ node_modules
โ โโโ package-lock.json
โ โโโ package.json
โ โโโ postcss.config.mjs
โ โโโ public
โ โโโ src
โ โโโ tailwind.config.ts
โ โโโ tsconfig.json
โโโ media
โ โโโ Connect4_landing-darkMode.png
โ โโโ Connect4_landing-dayMode.png
โโโ nginx
โโโ nginx.conf
Our journey in developing FourFury has been both challenging and rewarding. This section outlines our key milestones, challenges, and learnings.
- Successfully implemented a real-time multiplayer system using Socket.IO
- Created an efficient AI opponent with multiple difficulty levels
- Developed a responsive UI that works seamlessly across all devices
- Achieved sub-100ms move latency in online gameplay
- Built a scalable architecture capable of handling multiple concurrent games
- Implemented a robust game state management system
- Created an efficient winner detection algorithm
- Successfully integrated MongoDB for persistent storage
- Achieved 95%+ test coverage for core game logic
- Implemented efficient board serialization for state management
-
Optimizing winner detection
- Initial naive approach was too CPU-intensive
- Solved by checking only affected rows/columns/diagonals
- Implemented direction-based scanning for efficiency
- Added caching for frequently checked positions
-
Implementing efficient board representation
- Balanced memory usage vs computation speed
- Optimized array operations for move validation
- Implemented efficient serialization for WebSocket transmission
- Created compact state representation for persistence
-
Real-time game synchronization
- Handling network latency and disconnections
- Managing race conditions in move validation
- Implementing reliable state recovery
- Ensuring consistent game state across players
-
AI implementation challenges
- Balancing AI difficulty levels
- Optimizing minimax algorithm performance
- Implementing efficient board evaluation
- Managing computation time constraints
-
Technical Insights
- WebSocket management requires careful error handling
- State management is crucial for real-time applications
- Efficient data structures significantly impact performance
- Test-driven development is essential for game logic
- Type safety prevents many runtime errors
-
Architecture Decisions
- Microservices architecture provides better scalability
- Redis is excellent for real-time features
- MongoDB's flexibility suits game state storage
- Docker simplifies deployment and testing
-
Development Process
- Early performance optimization is sometimes necessary
- Comprehensive testing saves debugging time
- Documentation is crucial for complex game logic
- Regular refactoring keeps code maintainable
-
User Experience
- Responsive design requires careful planning
- Visual feedback is essential for game interactions
- Accessibility cannot be an afterthought
- Performance impacts user engagement
- Implement bitboard representation for faster win detection
- Optimize winner detection to check only around last move
- Add Google sign-in integration
- Implement:
- Playing history
- Leaderboard
- Scoring system for both online and AI modes
- User profiles
- Data persistence for signed-in users
- Role: Full Stack Developer
- Contributions:
- System Architecture Design
- Frontend Development (Next.js/React)
- Backend Development (FastAPI/Python)
- Real-time WebSocket Implementation
- Docker Configuration
- DevOps & Deployment
- Contact:
- GitHub: @hackerSa3edy
- LinkedIn: Abdelrahman Mohamed