ChessAI
Chess AI with 3 engines: Alpha-Beta pruning, Iterative Deepening + TT, and advanced SEE evaluation.
Install / Use
/learn @hnagnurtme/ChessAIREADME
Chess Bot API
A chess engine application with three different bot difficulty levels and a React-based frontend interface.
Project Structure
- Backend: FastAPI-based REST API with three chess engines
- Frontend: React + Vite with chess.js and react-chessboard
Features
Chess Engines
- Bot V1: Simple alpha-beta pruning engine
- Bot V2: Enhanced with iterative deepening, transposition tables, and late move reduction
- Bot VIP: Advanced engine with static exchange evaluation, aspiration windows, and pawn hash tables
Quick Start with Docker
Local Development
docker-compose up -d
Services will be available at:
- Backend API: http://localhost:8000/docs
- Frontend: http://localhost:5000
Production Deployment
- Create production environment file:
cp .env.prod.example .env.prod
- Configure environment variables in
.env.prod:
# Docker Hub credentials
DOCKERHUB_USERNAME=your_dockerhub_username
# Frontend API URL - IMPORTANT!
# Use relative path /api for nginx reverse proxy setup
VITE_API_URL=/api
# Or use full URL if not using reverse proxy:
# VITE_API_URL=https://your-domain.com/api
- Build images with production config:
# Use the build script (recommended)
./scripts/build-prod.sh
# Or manually with docker-compose
docker-compose -f docker-compose.prod.yml build
# Or build directly with docker
docker build --build-arg VITE_API_URL=/api -t username/chess-bot-frontend:latest ./Frontend
- Deploy: ./scripts/deploy.sh
> **Note**: `VITE_API_URL` is a build-time variable for Vite. If you change it, you must rebuild the frontend image.
### Stop Services
```bash
docker-compose down
View Logs
docker-compose logs -f
Manual Setup
Backend
- Navigate to Backend folder:
cd Backend
- Install dependencies:
pip install -r requirements.txt
- Run the server:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
API documentation: http://localhost:8000/docs
Frontend
- Navigate to Frontend folder:
cd Frontend
- Setup environment variables:
cp .env.example .env
Edit .env to configure API URL:
VITE_API_URL=http://localhost:8000
- Install dependencies:
5pm install
- Run development server:
npm run dev
Application: http://localhost:5173
- Build for production:
npm run build
API Endpoints
Get Best Move
POST /api/v1/best-move
POST /api/v2/best-move
POST /api/vip/best-move
Request body:
{
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"depth": 4
}
Response:
{
"move": "e2e4",
"eval": 0.5
}
Development
Run Tests
Backend:
cd Backend
pytest
Frontend:
cd Frontend
npm run lint
Technology Stack
Backend
- FastAPI
- python-chess
- uvicorn
- numpy
- pydantic-settings
Frontend
- React 19
- Vite
- chess.js
- react-chessboard
- axios
Docker Images
- Backend: Python 3.11-slim based (approximately 150-200MB)
- Frontend: Multi-stage Nginx Alpine based (approximately 25-35MB)
🚀 CI/CD Deployment
This project includes automated CI/CD pipeline for deploying to Google Cloud Platform.
Quick Setup
- Docker Hub: Create account and access token
- GCP VM: Setup Ubuntu VM with Docker installed
- GitHub Secrets: Configure deployment secrets
- Nginx: Setup reverse proxy on GCP
- Deploy: Push to GitHub → Auto deploy!
Documentation
- CI/CD Quick Start - 10-step setup guide
- Complete Deployment Guide - Detailed documentation with monitoring and troubleshooting
GitHub Actions Workflow
Pipeline automatically:
- ✅ Builds Docker images
- ✅ Pushes to Docker Hub with version tags
- ✅ Deploys to GCP via SSH
- ✅ Runs health checks
Triggers on:
- Push to
mainorprodbranch - Manual workflow dispatch
Required GitHub Secrets
| Secret | Description |
|--------|-------------|
| DOCKERHUB_USERNAME | Docker Hub username |
| DOCKERHUB_TOKEN | Docker Hub access token |
| GCP_HOST | GCP VM public IP |
| GCP_USERNAME | SSH username |
| GCP_SSH_KEY | SSH private key |
Production URLs
After deployment, access your application:
- Frontend:
http://YOUR_GCP_IP/ - API Docs:
http://YOUR_GCP_IP/docs - API Endpoint:
http://YOUR_GCP_IP/api/
License
[Add your license here]
