How vd-phuc-2k5/chessgame works
ChessGame is a browser-based chess app with a TypeScript rules engine and optional Stockfish opponent. The main workflow runs from board interaction through GameController into the domain Game, which validates and applies moves, records notation/history and updates state; the controller publishes snapshots for the UI. In engine mode, the strategy requests a move from the API route and converts its UCI response. Edges reflect the README and shown calls/imports; unsampled UI and engine wiring is represented only where documented.
Main entry points: game.ts Game rules facade · gameController.ts Game controller · board.tsx Board view · playerStrategy.ts Engine strategy
Components 29
Board UI
- Board view
client/src/components/board/board.tsx - Board grid
client/src/components/board/boardGrid.tsx - Promotion choice
client/src/components/board/promotionOverlay.tsx - Game overlays
client/src/components/board/gameOverlay.tsx - Game controls
client/src/components/board/gameControls.tsx - Move history UI
client/src/components/board/moveHistoryPanel.tsx - Board orientation
client/src/components/board/boardOrientation.tsx
Game orchestration
- Game controller
client/src/game/gameController.ts - Snapshot hook
client/src/game/useGameController.ts - Game clock
client/src/game/gameClock.ts - Player strategy
client/src/game/playerStrategy.ts
Chess domain
- Game rules facade
packages/domain/src/lib/game/game.ts - Board state
packages/domain/src/lib/board/board.ts - Piece creation
packages/domain/src/lib/piece/pieceFactory.ts - Move generation
packages/domain/src/lib/move/moveGenerator.ts - Move validation
packages/domain/src/lib/move/moveValidator.ts - Move execution
packages/domain/src/lib/execution - Game state
packages/domain/src/lib/game/gameState.ts - State updater
packages/domain/src/lib/game/gameStateUpdater.ts - Move history
packages/domain/src/lib/history/moveHistory.ts - Notation and PGN
packages/domain/src/lib/history/moveNotationBuilder.ts - Position model
packages/domain/src/lib/position/position.ts
Computer opponent
- Engine strategy
client/src/game/playerStrategy.ts - Engine client
client/src/game/stockfishEngine.ts - UCI conversion
client/src/game/uci.ts - Engine API
client/src/app/api/engine/route.ts - Stockfish process
Core contracts
- Chess contracts
packages/core/src/lib/interfaces/iGameState.ts
Other components
- Player
Connections 34
- Player → Board view: interacts with
- Board view → Board grid: renders
client/src/components/board/board.tsx - Board view → Promotion choice: renders
client/src/components/board/board.tsx - Board view → Game overlays: renders
client/src/components/board/board.tsx - Board view → Board orientation: configures
- Board view → Game controls: offers
- Board view → Move history UI: shows
- Board view → Game controller: sends moves
- Promotion choice → Game controller: chooses piece
- Game controller → Game rules facade: requests legal moves
client/src/game/gameController.ts - Game controller → Game rules facade: executes move
- Game controller → Game clock: starts and ticks
client/src/game/gameController.ts - Game controller → Player strategy: creates player
client/src/game/gameController.ts - Snapshot hook → Game controller: subscribes
client/src/game/useGameController.ts - Game controller → Snapshot hook: publishes snapshot
client/src/game/useGameController.ts - Game rules facade → Board state: reads and resets
packages/domain/src/lib/game/game.ts - Board state → Piece creation: creates pieces
packages/domain/src/lib/board/board.ts - Game rules facade → Move generation: generates candidates
packages/domain/src/lib/game/game.ts - Game rules facade → Move validation: checks legality
packages/domain/src/lib/game/game.ts - Game rules facade → Move execution: selects executor
packages/domain/src/lib/game/game.ts - Game rules facade → State updater: updates state
packages/domain/src/lib/game/game.ts - State updater → Game state: updates
packages/domain/src/lib/game/gameStateUpdater.ts - Game rules facade → Notation and PGN: builds notation
packages/domain/src/lib/game/game.ts - Game rules facade → Move history: records moves
packages/domain/src/lib/game/game.ts - Notation and PGN → Move generation: finds alternatives
packages/domain/src/lib/history/moveNotationBuilder.ts - Move generation → Board state: reads board
packages/domain/src/lib/move/moveGenerator.ts - Game rules facade → Position model: uses coordinates
packages/domain/src/lib/game/game.ts - Game rules facade → Chess contracts: implements contracts
packages/domain/src/lib/game/game.ts - Game controller → Engine strategy: creates engine player
client/src/game/gameController.ts - Engine strategy → Engine client: requests move
- Engine client → Engine API: posts UCI moves
client/src/game/stockfishEngine.ts - Engine API → Stockfish process: spawns process
- Engine strategy → UCI conversion: converts move
- UCI conversion → Game controller: returns move