Skip to content

About

Full-featured chess application with Clean Architecture, Blazor Server, and real-time multiplayer via SignalR

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Chess Game

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.

Features

  • 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

Project Structure

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

Architecture

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.

Getting Started

Prerequisites

Running Locally

  1. Start the Backend:
cd Chess.Backend
dotnet run --project src/Chess.Api

The API will be available at http://localhost:5000 (HTTP) and https://localhost:7001 (HTTPS). Swagger UI is available at http://localhost:5000/swagger.

  1. Start the Frontend:
cd Chess.Frontend
dotnet run --project Chess.Blazor.Server

The Blazor app will be available at http://localhost:5000 (or the port shown in terminal).

Local Game Mode

Navigate to /local to play offline with a friend on the same machine. Two players take turns on the same screen.

Online Game Mode

Navigate to /online to play over the network:

  1. One player creates a new game and gets a Game ID
  2. The opponent connects to the same backend URL and joins using the Game ID
  3. 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).

API Endpoints

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

SignalR Hub

Connect to /gamehub for real-time gameplay:

  • CreateGame(playerName) — Create a new game
  • JoinGame(gameId, playerName) — Join an existing game
  • MakeMove(gameId, from, to, promotionPiece?) — Make a move
  • GetValidMoves(gameId, from) — Get legal moves for a piece
  • ResignGame(gameId, color) — Resign
  • OfferDraw(gameId, color, action) — Offer, accept, or decline draw
  • RequestGameState(gameId) — Request current game state

See docs/API.md for full API documentation.

Chess Rules Implemented

  • 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

Tech Stack

  • Backend: .NET 10, ASP.NET Core, MediatR (CQRS), SignalR
  • Frontend: .NET 10, Blazor Server, Bootstrap 5
  • Architecture: Clean Architecture, Domain-Driven Design
  • Testing: xUnit

License

MIT

About

Full-featured chess application with Clean Architecture, Blazor Server, and real-time multiplayer via SignalR

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages