# tq-ngo/chess-game architecture

> Architecture diagram of the GitHub repository tq-ngo/chess-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tq-ngo/chess-game
- Repository: https://github.com/tq-ngo/chess-game

## Overview

This is a Java chess game with a JavaFX interface. A player interacts with the board; the interface asks the Rulebook for legal moves, executes a selected Move, and displays the updated position. Match coordinates turns and game-ending checks, while Board, Square, pieces, and move generators hold and evaluate chess state. The tree and excerpts support the GUI and rules structure; unsampled wiring is shown only where the source index names the relationship. The console entry point is also represented as an alternate interface.

Main entry points: [`src/main/java/state/Board.java`](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/Board.java) (Board state), [`src/main/java/ui/GuiMain.java`](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/GuiMain.java) (GUI launcher), [`src/main/java/pieces`](https://github.com/tq-ngo/chess-game/tree/main/src/main/java/pieces) (Chess pieces), [`src/main/java/game/Match.java`](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Match.java) (Match coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Match flow"]
  node_gui_main["GUI launcher<br/>[GuiMain.java]"]
  node_match["Match coordinator<br/>[Match.java]"]
  node_human["Human player<br/>[HumanPlayer.java]"]
  node_agent["Agent player<br/>[Agent.java]"]
  node_player_base["Player base<br/>[Player.java]"]
end

subgraph group_ui["User interfaces"]
  node_javafx_view["JavaFX view<br/>[JavaFXView.java]"]
  node_board_ui["Chessboard UI<br/>[ChessBoardUI.java]"]
  node_console["Console view<br/>[Console.java]"]
  node_view["View contract<br/>[View.java]"]
end

subgraph group_rules["Chess rules"]
  node_rulebook["Rulebook<br/>[Rulebook.java]"]
  node_move["Move execution<br/>[Move.java]"]
  node_movesets["Move generators"]
  node_pieces["Chess pieces"]
end

subgraph group_state["Board model"]
  node_board_factory["Initial position<br/>[BoardFactory.java]"]
  node_board[("Board state<br/>[Board.java]")]
  node_square["Board square<br/>[Square.java]"]
  node_color["Piece colors<br/>[Color.java]"]
end

node_player(("Chess player"))

node_player -->|"starts game"| node_gui_main
node_gui_main -->|"creates position"| node_board_factory
node_gui_main -->|"starts match"| node_match
node_gui_main -->|"creates player"| node_human
node_gui_main -->|"creates view"| node_javafx_view
node_gui_main -->|"sets up board"| node_board_ui
node_match -->|"checks game"| node_rulebook
node_match -->|"uses state"| node_board
node_match -->|"updates view"| node_view
node_match -->|"runs turns"| node_player_base
node_human -->|"extends"| node_player_base
node_agent -->|"extends"| node_player_base
node_javafx_view -->|"implements"| node_view
node_javafx_view -->|"delegates display"| node_board_ui
node_console -->|"implements"| node_view
node_board_ui -->|"requests legal moves"| node_rulebook
node_board_ui -->|"executes selection"| node_move
node_board_ui -->|"reads position"| node_board
node_rulebook -->|"evaluates moves"| node_pieces
node_rulebook -->|"checks positions"| node_board
node_rulebook -->|"simulates moves"| node_move
node_pieces -->|"uses generators"| node_movesets
node_pieces -->|"queries positions"| node_board
node_movesets -->|"reads squares"| node_board
node_board_factory -->|"places pieces"| node_pieces
node_board_factory -->|"builds position"| node_board
node_board -->|"stores squares"| node_square
node_square -->|"holds piece"| node_pieces
node_pieces -->|"uses color"| node_color

click node_gui_main "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/GuiMain.java"
click node_match "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Match.java"
click node_human "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/HumanPlayer.java"
click node_agent "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Agent.java"
click node_player_base "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Player.java"
click node_javafx_view "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/JavaFXView.java"
click node_board_ui "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/ChessBoardUI.java"
click node_console "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/Console.java"
click node_view "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/View.java"
click node_rulebook "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/rules/Rulebook.java"
click node_move "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/rules/Move.java"
click node_movesets "https://github.com/tq-ngo/chess-game/tree/main/src/main/java/movesets"
click node_pieces "https://github.com/tq-ngo/chess-game/tree/main/src/main/java/pieces"
click node_board_factory "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/BoardFactory.java"
click node_board "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/Board.java"
click node_square "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/Square.java"
click node_color "https://github.com/tq-ngo/chess-game/blob/main/src/main/java/util/Color.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gui_main,node_match,node_human,node_agent,node_player_base toneBlue
class node_javafx_view,node_board_ui,node_console,node_view toneAmber
class node_rulebook,node_move,node_movesets,node_pieces toneMint
class node_board_factory,node_board,node_square,node_color toneRose
class node_player toneIndigo
```

## Components

### Match flow

- [GUI launcher](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/GuiMain.java): `src/main/java/ui/GuiMain.java`
- [Match coordinator](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Match.java): `src/main/java/game/Match.java`
- [Human player](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/HumanPlayer.java): `src/main/java/game/HumanPlayer.java`
- [Agent player](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Agent.java): `src/main/java/game/Agent.java`
- [Player base](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/game/Player.java): `src/main/java/game/Player.java`

### User interfaces

- [JavaFX view](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/JavaFXView.java): `src/main/java/ui/JavaFXView.java`
- [Chessboard UI](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/ChessBoardUI.java): `src/main/java/ui/ChessBoardUI.java`
- [Console view](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/Console.java): `src/main/java/ui/Console.java`
- [View contract](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/ui/View.java): `src/main/java/ui/View.java`

### Chess rules

- [Rulebook](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/rules/Rulebook.java): `src/main/java/rules/Rulebook.java`
- [Move execution](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/rules/Move.java): `src/main/java/rules/Move.java`
- [Move generators](https://github.com/tq-ngo/chess-game/tree/main/src/main/java/movesets): `src/main/java/movesets`
- [Chess pieces](https://github.com/tq-ngo/chess-game/tree/main/src/main/java/pieces): `src/main/java/pieces`

### Board model

- [Initial position](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/BoardFactory.java): `src/main/java/state/BoardFactory.java`
- [Board state](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/Board.java): `src/main/java/state/Board.java`
- [Board square](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/state/Square.java): `src/main/java/state/Square.java`
- [Piece colors](https://github.com/tq-ngo/chess-game/blob/main/src/main/java/util/Color.java): `src/main/java/util/Color.java`

### Other components

- **Chess player**

## Connections

- Chess player → GUI launcher: starts game (evidence: `README.md`)
- GUI launcher → Initial position: creates position (evidence: `src/main/java/ui/GuiMain.java`)
- GUI launcher → Match coordinator: starts match (evidence: `src/main/java/ui/GuiMain.java`)
- GUI launcher → Human player: creates player (evidence: `src/main/java/ui/GuiMain.java`)
- GUI launcher → JavaFX view: creates view (evidence: `src/main/java/ui/GuiMain.java`)
- GUI launcher → Chessboard UI: sets up board (evidence: `src/main/java/ui/GuiMain.java`)
- Match coordinator → Rulebook: checks game (evidence: `src/main/java/game/Match.java`)
- Match coordinator → Board state: uses state (evidence: `src/main/java/game/Match.java`)
- Match coordinator → View contract: updates view (evidence: `src/main/java/game/Match.java`)
- Match coordinator → Player base: runs turns (evidence: `src/main/java/game/Match.java`)
- Human player → Player base: extends (evidence: `src/main/java/game/HumanPlayer.java`)
- Agent player → Player base: extends (evidence: `src/main/java/game/Agent.java`)
- JavaFX view → View contract: implements (evidence: `src/main/java/ui/JavaFXView.java`)
- JavaFX view → Chessboard UI: delegates display (evidence: `src/main/java/ui/JavaFXView.java`)
- Console view → View contract: implements (evidence: `src/main/java/ui/Console.java`)
- Chessboard UI → Rulebook: requests legal moves (evidence: `src/main/java/ui/ChessBoardUI.java`)
- Chessboard UI → Move execution: executes selection (evidence: `src/main/java/ui/ChessBoardUI.java`)
- Chessboard UI → Board state: reads position (evidence: `src/main/java/ui/ChessBoardUI.java`)
- Rulebook → Chess pieces: evaluates moves (evidence: `src/main/java/rules/Rulebook.java`)
- Rulebook → Board state: checks positions (evidence: `src/main/java/rules/Rulebook.java`)
- Rulebook → Move execution: simulates moves (evidence: `src/main/java/rules/Rulebook.java`)
- Chess pieces → Move generators: uses generators (evidence: `src/main/java/pieces/Queen.java`)
- Chess pieces → Board state: queries positions (evidence: `src/main/java/pieces/Queen.java`)
- Move generators → Board state: reads squares (evidence: `src/main/java/movesets/DiagonalMoveset.java`)
- Initial position → Chess pieces: places pieces (evidence: `src/main/java/state/BoardFactory.java`)
- Initial position → Board state: builds position (evidence: `src/main/java/state/BoardFactory.java`)
- Board state → Board square: stores squares (evidence: `src/main/java/state/Board.java`)
- Board square → Chess pieces: holds piece (evidence: `src/main/java/state/Square.java`)
- Chess pieces → Piece colors: uses color (evidence: `src/main/java/pieces/Piece.java`)
