A chess game with AI opponent built with Next.js frontend and FastAPI backend.
- Interactive Chess Board: Play chess against an AI opponent
- Color Selection: Choose to play as white or black pieces
- URL State Management: Game state is preserved in the URL for sharing and navigation
- Real-time AI Moves: AI responds to your moves using a neural network backend
- Legal Move Validation: Only legal chess moves are allowed
- Visual Feedback: Selected pieces and legal moves are highlighted
- Node.js 18+
- Python 3.8+
- uv (Python package manager)
- Clone the repository:
git clone <repository-url>
cd chess-bot- Install frontend dependencies:
npm install- Install backend dependencies:
cd backend
uv sync
cd ..- Start the backend server:
npm run backend:dev- In a new terminal, start the frontend:
npm run dev- Open your browser and navigate to
http://localhost:3000
- Start a Game: Click the "Start Game" button on the homepage
- Choose Your Color: Select whether you want to play as white or black
- White goes first
- Black allows the AI to make the first move
- Make Moves:
- Click on one of your pieces to select it
- Click on a legal destination square to move
- Click on the same piece again to deselect it
- Click on another of your pieces to select a different piece
- Game State: The URL updates with each move, allowing you to share game positions
chess-bot/
├── src/
│ ├── app/
│ │ ├── api/move/ # API route for AI moves
│ │ ├── game/[seed]/ # Dynamic game routes
│ │ └── page.tsx # Homepage
│ └── components/
│ ├── ChessBoard.tsx # Main chess game component
│ ├── ChessSquare.tsx # Individual square component
│ └── ColorSelection.tsx # Color selection UI
├── backend/
│ └── main.py # FastAPI backend with AI
└── package.json
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Chess Logic: chess.js library
- Icons: Lucide React
- Backend: FastAPI, Python
- AI: Neural network with PyTorch
POST /api/move: Sends game state to backend AI and returns the AI's move- Request body:
{ fen: string, seed: string } - Response:
{ move: string }
- Request body:
npm run dev: Start frontend development servernpm run backend:dev: Start backend development servernpm run dev:full: Start both frontend and backendnpm run build: Build for productionnpm run lint: Run ESLint