Skip to content

florentdevk/chess-api

Repository files navigation

Chess API

A REST API built with PHP 8.4 / Symfony 8.1 implementing a chess game engine, designed with Domain-Driven Design (DDD) principles and a strict layered architecture.


Architecture

src/Chess/ ├── Domain/ # Pure PHP business logic — zero framework dependency ├── Application/ # Command/Query handlers (CQRS via Symfony Messenger) └── Infrastructure/ # Doctrine, Symfony controllers, API serialization

Dependency rule: dependencies always point inward toward the Domain.


Domain model

Class DDD Pattern Description
Game Aggregate Root Enforces all game invariants, orchestrates the game
Board Entity 8×8 grid managing piece positions
GameId Value Object Unique game identifier (UUID)
Square Value Object Algebraic notation (e2, e4…), immutable
Move Value Object A from → to square pair, immutable
Color Enum White / Black
PieceType Enum King, Queen, Rook, Bishop, Knight, Pawn
Piece Entity A piece with its color and type

API Endpoints

Method Endpoint Description
POST /api/games Start a new game
GET /api/games/{id} Get current game state
POST /api/games/{id}/moves Play a move

Example

# Start a game
curl -X POST http://localhost:8000/api/games

# Get game state
curl http://localhost:8000/api/games/{gameId}

# Play a move
curl -X POST http://localhost:8000/api/games/{gameId}/moves \
  -H "Content-Type: application/json" \
  -d '{"from": "e2", "to": "e4"}'

Stack

  • PHP 8.4 / Symfony 8.1
  • Doctrine ORM / PostgreSQL
  • PHPUnit 13 / PHPStan 2.2 (level 8)
  • Docker / GitHub Actions
  • OpenAPI 3.0 / Swagger UI

Getting started

git clone https://github.com/florentdevk/chess-api.git
cd chess-api
composer install
docker compose up -d
php bin/console doctrine:migrations:migrate
symfony server:start

About

Chess game engine API — DDD, CQRS, Symfony 8.1 / PHP 8.4

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors