# silwyne/chess architecture

> Architecture diagram of the GitHub repository silwyne/chess, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/silwyne/chess
- Repository: https://github.com/silwyne/chess

## Overview

##### Project Type and Purpose
- This is a Java-based 2D Chess game built using Java FX – though it’s more of a proof-of-concept for a chess engine and user interface.
- The README indicates that among its goals are validating move logic and exploring Java FX for simple 2D game development. It also mentions plans for an AI component that is pending.

##### File Structure
- The top-level structure includes typical Maven project files – pom.xml for build configuration and directories like src/main/java and src/main/resources.
- Within src/main/java, the package “nilian” is subdivided into multiple thematic sub-packages:
- Game: Contains game related logic (e.g., Game/EndGameChecker.java, Main.java).
- Move: Includes everything related to handling and validating moves. There’s a clear separation between move handling (e.g., ClickHandler, LightHandler, MoveShower) and move validation (e.g., individual validators for BishopMove, KingMove, etc.) – indicating a modular design for move processing.
- Pieces: Manages pieces’ images and extraction methods.
- Style: Contains components for UI customization (board styles, pane styles, theme handling) to allow dynamic UI changes.
- Window: Handles initialization of the user interface (e.g., OriginStarter, StarterSceneProvider).
- board: Contains core board representations such as ChessBoard, ChessSquare, and piece logic for the chess board.
- The directory “images” and contents in src/main/resources (e.g., PiecesSets) further support the visual and resource elements of the game.

##### Components
- Application Entry and Initialization:
- Main.java acts as the starting point.
- Window package (OriginStarter, StarterSceneProvider) initiates the primary Java FX windows and scenes.
- Game Logic and Flow:
- Game package handles overarching game state and end-check conditions.
- Board package creates and manages the chess board and its cells (ChessBoard, ChessSquare) and defines piece properties.
- Move Handling:
- Move package is the central hub for user move input (ClickHandler, LightHandler) and managing the moves (Move, MoveShower, PieceMover).
- Validation sub-package within Move ensures that each type of move (Bishop, King, Pawn, etc.) adheres to chess rules.
- UI and Visual Design:
- Style package provides styling for both board and pane as well as theme selection and style names.
- Pieces package deals with extracting and assigning images to pieces.
- Resources:
- External images and resource sets stored in the “images” directory and src/main/resources support the game’s assets.

##### Relationships and Data Flow
- The Main component starts the application and calls into the Window package to start up the Java FX UI.
- The UI components then interact with the Game logic to update state, show moves, highlight valid moves, and check for game termination.
- The Move package listens to user events (via ClickHandler) and uses the Validation classes to verify moves before they are executed.
- The board components update the displayed state of the game (through ChessBoard and ChessSquare), driven by the logic from Move and Game modules.
- The Style and Pieces modules provide the aesthetic and visual support, decoupled from the core game logic but integrated at the UI level.

##### Architectural Patterns and Design Principles
- The project exhibits a modular design with separation of concerns:
- Move processing, validation, and piece behavior are all segmented into separate classes/packages.
- UI components are separated from core game logic.
- There is some hint of the MVC pattern where the “View” is managed by Window/Style/Pieces and the “Controller/Model” is handled by Game, Move, and Board.
- Components are designed to be extendable (e.g., support for different piece moves and later AI integration).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Entry
    subgraph "Application Entry"
        MA["Main.java"]:::application
        WI["Window Init (OriginStarter & StarterSceneProvider)"]:::application
        MA -->|"starts"| WI
    end

    %% External Dependencies for Application Entry
    FX["External: JavaFX"]:::external
    JDK["External: JDK 17"]:::external
    MAVEN["Build Config (pom.xml)"]:::external
    FX -->|"required"| WI
    JDK -->|"runs"| MA
    MAVEN -->|"builds"| MA

    %% Game Engine
    subgraph "Game Engine"
        GL["Game Logic (EndGameChecker, etc.)"]:::logic
        BP["Board & Pieces (ChessBoard, ChessSquare, etc.)"]:::logic
        GL -->|"updates"| BP
    end

    %% Move Processing
    subgraph "Move Processing"
        MH["Move Handling (ClickHandler, LightHandler, Move, MoveShower, PieceMover)"]:::move
        MV["Move Validation (BishopMove, HorseMove, KingMove, PawnMove, RookMove, MoveValidation)"]:::move
        MH -->|"validates"| MV
        MH -->|"triggers board update"| BP
    end

    %% UI & Styling
    subgraph "UI & Styling"
        US["UI Styling (BoardStyles, PaneStyles, StyleName, ThemeName, ThemeSelector)"]:::ui
        PI["Pieces Images (ImageExtractor, PiecesImages)"]:::ui
        US -->|"integrates"| PI
        WI -->|"launches"| US
        US -->|"affects"| BP
        US -->|"passes input"| MH
    end

    %% Resources
    subgraph "Resources"
        RS["Images & Resource Sets"]:::resources
        RS ---|"supplies"| PI
        RS ---|"supports"| US
    end

    %% Click Events
    click MA "https://github.com/silwyne/chess/blob/master/src/main/java/nilian/Main.java"
    click WI "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/Window"
    click GL "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/Game"
    click BP "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/board"
    click MH "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/Move"
    click MV "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/Move/Validation"
    click US "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/Style"
    click PI "https://github.com/silwyne/chess/tree/master/src/main/java/nilian/Pieces"
    click RS "https://github.com/silwyne/chess/tree/master/images"

    %% Styles
    classDef application fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef logic fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef move fill:#cc99ff,stroke:#333,stroke-width:2px;
    classDef ui fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef resources fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef external fill:#e6e6e6,stroke:#333,stroke-width:2px;
```
