A full-featured chess application built with .NET 10, Blazor Server, and Clean Architecture. Supports local (hot-seat) and online (network) play with real-time communication via SignalR.
- Full chess rules implementation (all piece moves, castling, en passant, pawn promotion)
- Check, checkmate, and stalemate detection
- 50-move rule and threefold repetition draw detection
- Insufficient material draw detection
- Draw by agreement
- Resignation
- Local (offline) two-player mode
- Online (network) two-player mode over LAN
- Interactive board with piece selection, valid move highlights, and drag support
- Move history panel
- Captured pieces display
- Board flip for black player perspective
ZCodeProject/
├── Chess.Backend/ # Backend solution (Clean Architecture)
│ ├── src/
│ │ ├── Chess.Domain/ # Domain layer — core chess logic
│ │ ├── Chess.Application/ # Application layer — CQRS commands/queries
│ │ ├── Chess.Infrastructure/ # Infrastructure layer — persistence, SignalR
│ │ └── Chess.Api/ # API layer — REST controllers + SignalR hub
│ └── tests/
│ ├── Chess.Domain.Tests/ # Domain unit tests
│ └── Chess.Application.Tests/ # Application unit tests
├── Chess.Frontend/ # Frontend solution
│ └── Chess.Blazor.Server/ # Blazor Server application
│ ├── Components/ # Razor components (pages, board, dialogs)
│ ├── Services/ # Game services (local + online)
│ ├── Models/ # View models for UI
│ └── wwwroot/ # Static assets (CSS, images)
└── docs/ # Documentation
The project follows Clean Architecture with clear separation of concerns:
- Domain — Pure chess logic with no external dependencies
- Application — CQRS pattern using MediatR for commands and queries
- Infrastructure — Repository implementations and SignalR hub
- API — ASP.NET Core controllers exposing REST and WebSocket endpoints
- Frontend — Blazor Server with interactive server-side rendering
See docs/ARCHITECTURE.md for detailed architecture documentation.
- Start the Backend:
cd Chess.Backend
dotnet run --project src/Chess.ApiThe API will be available at http://localhost:5000 (HTTP) and https://localhost:7001 (HTTPS).
Swagger UI is available at http://localhost:5000/swagger.
- Start the Frontend:
cd Chess.Frontend
dotnet run --project Chess.Blazor.ServerThe Blazor app will be available at http://localhost:5000 (or the port shown in terminal).
Navigate to /local to play offline with a friend on the same machine. Two players take turns on the same screen.
Navigate to /online to play over the network:
- One player creates a new game and gets a Game ID
- The opponent connects to the same backend URL and joins using the Game ID
- Both players see the board in real-time via SignalR
For LAN play, ensure both machines can reach the backend IP (e.g., http://192.168.1.x:5000).
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/games |
Create a new game |
| GET | /api/games/{gameId} |
Get game state |
| POST | /api/games/{gameId}/moves |
Make a move |
| GET | /api/games/{gameId}/valid-moves/{from} |
Get valid moves for a piece |
| POST | /api/games/{gameId}/resign |
Resign the game |
| POST | /api/games/{gameId}/draw |
Offer/accept a draw |
Connect to /gamehub for real-time gameplay:
CreateGame(playerName)— Create a new gameJoinGame(gameId, playerName)— Join an existing gameMakeMove(gameId, from, to, promotionPiece?)— Make a moveGetValidMoves(gameId, from)— Get legal moves for a pieceResignGame(gameId, color)— ResignOfferDraw(gameId, color, action)— Offer, accept, or decline drawRequestGameState(gameId)— Request current game state
See docs/API.md for full API documentation.
- All piece movements (King, Queen, Rook, Bishop, Knight, Pawn)
- Castling (king-side and queen-side)
- En passant
- Pawn promotion (Queen, Rook, Bishop, Knight)
- Check and checkmate detection
- Stalemate detection
- 50-move rule
- Threefold repetition
- Insufficient material draw
- Draw by agreement
- Resignation
- Backend: .NET 10, ASP.NET Core, MediatR (CQRS), SignalR
- Frontend: .NET 10, Blazor Server, Bootstrap 5
- Architecture: Clean Architecture, Domain-Driven Design
- Testing: xUnit
MIT