# ♟️ Gambit - Real-Time Chess Platform
A full-stack real-time chess platform built with **.NET 9** and **React** featuring online multiplayer, matchmaking, and live gameplay via SignalR.





---
## 📸 Screenshots
| Lobby | Game Board | Challenge |
|-------|-----------|-----------|
| Players online with challenge system | Real-time chess with live updates | Accept or decline challenges |
---
## ✨ Features
### 🎮 Game Features
- **Real-time multiplayer** via SignalR WebSockets
- **Challenge system** — challenge online players directly
- **Matchmaking** — automatic opponent finding by rating
- **AI opponent** — play against the house engine
- **Local multiplayer** — pass-and-play on same screen
- **Full chess rules** — castling, en passant, promotion, stalemate
- **Move animations** — smooth piece sliding and capture effects
- **Game chat** — communicate with your opponent in-game
### 👤 User System
- JWT authentication with refresh tokens
- User profiles with ratings and statistics
- Online/offline status indicators
- Game history with pagination
- Win/loss/draw statistics
### ⚙️ Backend Features
- Background job processing (game cleanup, matchmaking, timers)
- ELO rating system with K-factor adjustments
- Rate limiting and security middleware
- Health checks for monitoring
- PostgreSQL with Entity Framework Core
- Redis for caching and SignalR backplane
- Swagger API documentation
---
## 🏗️ Architecture
┌─────────────────────────────────────────────────┐ │ Frontend │ │ React + TypeScript │ │ SignalR Client │ Axios │ React Router │ └────────────────────┬────────────────────────────┘ │ WebSocket │ REST │ ┌────────────────────┴────────────────────────────┐ │ Backend │ │ ASP.NET Core 9 │ │ ┌──────────┐ ┌──────────┐ ┌─────────────────┐ │ │ │ Auth API │ │ Game API │ │ Matchmaking API │ │ │ └──────────┘ └──────────┘ └─────────────────┘ │ │ ┌──────────────────────────────────────────┐ │ │ │ SignalR Hubs (Real-time) │ │ │ │ ChessHub │ ChatHub │ │ │ └──────────────────────────────────────────┘ │ │ ┌──────────────────────────────────────────┐ │ │ │ Background Services │ │ │ │ GameCleanup │ Matchmaking │ Connection │ │ │ └──────────────────────────────────────────┘ │ └────────────────────┬────────────────────────────┘ │ ┌──────┴──────┐ │ PostgreSQL │ Redis └─────────────┘
---
## 🚀 Getting Started
### Prerequisites
- [.NET 9.0 SDK](https://dotnet.microsoft.com/download)
- [Node.js 20+](https://nodejs.org/)
- [PostgreSQL 17](https://www.postgresql.org/)
- [Redis 7](https://redis.io/) (optional, for scaling)
### Backend Setup
```bash
# Clone the repository
git clone https://github.com/yourusername/gambit-chess.git
cd gambit-chess
# Navigate to API project
cd src/ChessAPI
# Update connection string in appsettings.json
# "DefaultConnection": "Host=localhost;Database=ChessDB;Username=postgres;Password=yourpassword"
# Restore packages
dotnet restore
# Run database migrations
dotnet ef database update
# Start the API
dotnet run
The API will be available at http://localhost:5000
# Navigate to React project
cd src/chess-client
# Install dependencies
npm install
# Start development server
npm run devThe client will be available at http://localhost:5173
| Password | Role | |
|---|---|---|
| admin@chess.com | Admin123! | Admin |
| demo@chess.com | Demo123! | User |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login |
| POST | /api/auth/refresh |
Refresh token |
| GET | /api/auth/me |
Get current user |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/games |
Create game |
| GET | /api/games/{id} |
Get game details |
| POST | /api/games/{id}/moves |
Make a move |
| POST | /api/games/{id}/resign |
Resign |
| POST | /api/games/{id}/offer-draw |
Offer draw |
| Hub | Path | Description |
|---|---|---|
| ChessHub | /hubs/chess |
Game moves, challenges, matchmaking |
| ChatHub | /hubs/chat |
Lobby and in-game chat |
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=ChessDB;Username=postgres;Password=yourpassword",
"Redis": "localhost:6379"
},
"JwtSettings": {
"SecretKey": "your-secret-key-at-least-32-characters",
"ExpirationInMinutes": 60
},
"GameSettings": {
"DefaultTimeControl": 600,
"InactivityTimeoutMinutes": 30
}
}| Variable | Description | Default |
|---|---|---|
ASPNETCORE_URLS |
API URLs | http://localhost:5000 |
ASPNETCORE_ENVIRONMENT |
Environment | Development |
ChessAPI/
├── src/
│ ├── ChessAPI/ # .NET Backend
│ │ ├── Controllers/ # REST API controllers
│ │ ├── Hubs/ # SignalR hubs
│ │ ├── Models/
│ │ │ ├── Entities/ # Database entities
│ │ │ ├── DTOs/ # Data transfer objects
│ │ │ ├── Enums/ # Enumerations
│ │ │ └── Chess/ # Chess engine
│ │ ├── Services/
│ │ │ ├── Interfaces/ # Service contracts
│ │ │ ├── Implementations/ # Service logic
│ │ │ └── BackgroundServices/ # Background jobs
│ │ ├── Middleware/ # Request pipeline
│ │ ├── Helpers/ # Utility classes
│ │ └── Data/ # DbContext
│ └── chess-client/ # React Frontend
│ ├── src/
│ │ ├── components/ # Reusable UI
│ │ ├── contexts/ # React contexts
│ │ ├── hooks/ # Custom hooks
│ │ ├── pages/ # Page components
│ │ ├── services/ # API & SignalR
│ │ └── store/ # Zustand store
│ └── public/
- ASP.NET Core 9 — Web framework
- Entity Framework Core — ORM
- SignalR — Real-time WebSocket communication
- PostgreSQL — Primary database
- Redis — Caching & SignalR backplane
- JWT — Authentication
- React 18 — UI library
- TypeScript — Type safety
- Vite — Build tool
- Tailwind CSS — Styling
- Zustand — State management
- SignalR Client — Real-time client
- Axios — HTTP client
- Sonner — Toast notifications
# Backend tests
dotnet test
# Frontend tests
npm run testThis project is licensed under the MIT License - see the LICENSE file for details.
- Chess piece symbols from Unicode
- React Chessboard library
- .NET community for excellent documentation
Built with ♟️ by [Your Name]
This README covers:
- Project overview and features
- Architecture diagram
- Setup instructions
- API documentation
- Configuration guide
- Project structure
- Tech stack
- Testing instructions
You can customize the GitHub links, screenshots, and your name at the bottom.