A fully-featured chess game built with React, TypeScript, Zustand, and Firebase. Play locally on the same device or challenge friends online with real-time synchronization. This application implements complete chess rules including check, checkmate, stalemate, and special moves like pawn promotion.
- ๐ Local Multiplayer - Play with a friend on the same device
- ๐ Online Multiplayer - Challenge friends remotely with shareable game links
- โ๏ธ Complete Chess Rules - Check, checkmate, stalemate, pawn promotion, and all standard moves
- ๐ Real-time Sync - Moves update instantly across all connected players
- ๐พ Game History - Track your active games with automatic reconnection
- ๐ฑ Responsive Design - Works on desktop and mobile devices
- ๐จ Multiple Themes - Light and dark mode support
This application follows a clean architecture pattern with clear separation of concerns:
- State Management: Zustand stores for different domains
- Component Structure: Atomic design with reusable components
- Business Logic: Separated utility functions for game rules
- Type Safety: Full TypeScript implementation with strict typing
app/
โโโ components/ # React components organized by feature
โ โโโ board/ # Chess board related components
โ โ โโโ ChessBoard.tsx # Main board container
โ โ โโโ BoardTile.tsx # Individual tile component
โ โ โโโ PieceDisplay.tsx # Chess piece rendering
โ โ
โ โโโ game/ # Game status and information
โ โ โโโ GameStatus.tsx # Current turn and check status
โ โ โโโ CapturedPieces.tsx # Display of captured pieces
โ โ
โ โโโ modals/ # Modal dialogs
โ โ โโโ Modal.tsx # Reusable modal wrapper
โ โ โโโ GameModeSelection.tsx # Local vs Online mode selection
โ โ โโโ PlayerNameInput.tsx # Player setup (local/online)
โ โ โโโ OnlineWaitingRoom.tsx # Waiting for opponent
โ โ โโโ MyGames.tsx # Game history display
โ โ โโโ OptionsModal.tsx # Game settings
โ โ โโโ GameEndModal.tsx # Checkmate/stalemate display
โ โ โโโ PawnPromotionModal.tsx # Pawn promotion interface
โ โ
โ โโโ ui/ # UI elements
โ โ โโโ TurnIndicator.tsx # Visual turn indicator
โ โ โโโ DraggingCursor.tsx # Drag feedback
โ โ โโโ Navigation.tsx # Top navigation bar
โ โ
โ โโโ Game.tsx # Main game orchestrator component
โ
โโโ stores/ # Zustand state management
โ โโโ types.ts # Shared TypeScript types
โ โโโ gameStore.ts # Game flow state (turns, check, checkmate)
โ โโโ boardStore.ts # Board state and piece positions
โ โโโ playerStore.ts # Player information
โ โโโ uiStore.ts # UI state (selections, modals, preferences)
โ โโโ onlineGameStore.ts # Online multiplayer state and Firestore sync
โ
โโโ utils/ # Business logic and utilities
โ โโโ chessRules.ts # Check, checkmate, stalemate detection
โ โโโ pieceMovement.ts # Movement calculation and validation
โ โโโ movementRules.ts # Piece-specific movement patterns
โ โโโ boardSetup.ts # Initial board configuration
โ โโโ boardSetupPresets.ts # Test positions and scenarios
โ โโโ gameHistory.ts # LocalStorage game history management
โ โโโ constants.ts # Game constants
โ
โโโ hooks/ # Custom React hooks
โ โโโ useOnlineGameSync.ts # Firestore real-time sync and reconnection
โ
โโโ firebase.client.ts # Firebase/Firestore configuration
โโโ routes/ # React Router routes
โโโ _index.tsx # Main route
app/utils/chessRules.ts- Core chess rules implementationapp/utils/pieceMovement.ts- How pieces move and captureapp/stores/boardStore.ts- Board state management and move execution
app/stores/onlineGameStore.ts- Online game state and Firestore operationsapp/hooks/useOnlineGameSync.ts- Real-time synchronization logicONLINE_MULTIPLAYER.md- Detailed online multiplayer documentationSECURITY.md- Security architecture and validation
app/components/Game.tsx- Main game component with URL parameter handlingapp/components/board/ChessBoard.tsx- Chess board rendering and interactionapp/components/modals/GameModeSelection.tsx- Mode selection screen
app/stores/types.ts- All TypeScript type definitionsapp/stores/gameStore.ts- Game flow and statusapp/stores/uiStore.ts- UI state and user preferencesapp/stores/onlineGameStore.ts- Online game state and Firestore sync
- React 19 - UI framework
- TypeScript - Type safety
- Zustand - State management
- Firebase/Firestore - Real-time database for online multiplayer
- React Router - Routing and navigation
- Tailwind CSS v4 - Styling
- Vite - Build tool
- Two players on the same device
- No internet connection required
- Instant gameplay
- Perfect for quick matches with friends
- Play with friends remotely
- Shareable game links
- Real-time move synchronization
- Automatic reconnection
- Game history tracking
- Works across different devices
- All standard chess moves
- Legal move validation
- Check and checkmate detection
- Stalemate detection
- Pawn promotion
- Move history tracking
- Drag and drop piece movement
- Visual move indicators
- Turn indicators with player names
- Captured pieces display
- Dark/light theme support
- Responsive design for all screen sizes
- Game mode selection screen
- Player name customization
- Waiting room with shareable link
- "My Games" history viewer
- Automatic reconnection after refresh
- Real-time opponent move updates
- Connection status tracking
- Node.js 18+ installed
- Firebase project (for online multiplayer)
# Install dependencies
npm install
# Start Firestore emulator (for local development)
npm run emulators
# In a separate terminal, start development server
npm run dev
# Build for production
npm run build
# Type checking
npm run typecheck
# Linting
npm run lint- Create a Firebase project at https://console.firebase.google.com
- Enable Firestore Database
- Update
app/firebase.client.tswith your Firebase config - Deploy Firestore security rules:
firebase deploy --only firestore:rules
- Visit the app homepage
- Click "Online Game"
- Enter your name
- Share the generated link with your friend
- Wait for them to join
- Click the game link your friend shared
- Enter your name
- Start playing immediately!
- Visit homepage
- Click "My Games" button
- Select your active game from the list
- Automatically reconnects you to the game
We use multiple Zustand stores to separate concerns:
- gameStore: Manages game flow, turns, and win conditions
- boardStore: Handles board state and piece movements (with Firestore sync in online mode)
- playerStore: Tracks player information
- uiStore: Controls UI state and user preferences
- onlineGameStore: Manages online multiplayer state and Firestore operations
This separation allows for:
- Better code organization
- Easier testing
- Independent state updates
- Clear domain boundaries
- Separation of local and online game logic
Components are organized by feature/domain rather than type:
- board/: Everything related to the chess board
- game/: Game status and information display
- modals/: All modal dialogs
- ui/: Reusable UI elements
All chess rules and game logic are extracted into utility functions:
- Pure functions for easier testing
- Reusable across different components
- Clear separation from UI logic
- Components: Functional components with hooks
- State: Zustand stores with clear action names
- Types: Comprehensive TypeScript types in
stores/types.ts - Styling: Tailwind CSS with occasional inline styles for dynamic values
- File Naming: PascalCase for components, camelCase for utilities
The application includes preset board configurations for testing:
- Normal: Standard chess starting position
- Pawn Pre-Promotion: Test pawn promotion scenarios
- Endgame Practice: Minimal piece endgame
- Check Practice: Test check/checkmate scenarios
Access these through the Options modal in the game.
- README.md - This file, project overview and setup
- ONLINE_MULTIPLAYER.md - Online multiplayer implementation details
- SECURITY.md - Security architecture and best practices
The online multiplayer mode implements defense-in-depth security:
- Multi-layer validation for all game actions
- Firestore as the single source of truth
- Player identity verification on every move
- LocalStorage used only for UI convenience, never for authorization
See SECURITY.md for detailed security documentation.
When contributing to this codebase:
- Follow the existing file structure
- Add types to
stores/types.ts - Keep components focused and single-purpose
- Extract complex logic to utility functions
- Update relevant Zustand stores for state changes
- For online features, always validate against Firestore (see SECURITY.md)
- Update documentation when adding new features
For junior engineers learning this codebase:
-
Start with Types (
src/stores/types.ts)- Understand the data structures
- Learn the domain terminology
-
Follow a User Action
- Start at
BoardTile.tsxclick handler - Trace through to
boardStore.movePiece() - See how state updates propagate
- Start at
-
Understand Game Rules
- Read
chessRules.tsfor rule implementation - Check
pieceMovement.tsfor movement logic
- Read
-
Explore State Management
- See how different stores interact
- Understand the separation of concerns
-
Review Component Hierarchy
- Start with
Game.tsx - Follow the component tree down
- Start with
- No time controls/chess clock (yet)
- No game chat (yet)
- No spectator mode (yet)
- No move undo/takeback (yet)
- No draw offers or resignation (yet)
- Add chess clock/time controls
- Implement game chat
- Add spectator mode
- Add move notation (PGN export)
- Implement game replay from move history
- Add draw offers and resignation
- Add game statistics/leaderboards
- Implement proper Firebase Authentication
- Add email game invitations
- Add push notifications for opponent moves
For questions about the codebase architecture or implementation decisions, please open an issue in the repository.
This project is open source and available under the MIT License.