# erkrodc/unitychess architecture

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

- Interactive diagram: https://gitdiagram.com/erkrodc/unitychess
- Repository: https://github.com/erkrodc/unitychess

## Overview

##### Project’s Key Components
- Unity Engine & Runtime: The central execution environment—all scenes, rendering, input handling, and lifecycle management come via Unity.
- Scenes & Prefabs:
- Scenes (e.g., Assets/Scenes/Board.unity) that host the game world and chess board.
- Prefabs (under Assets/Prefabs) for essential game objects like Board, GameManager, UI, Main Camera, and debug tools.
- Game Logic and Controllers:
- Scripts in Assets/Scripts/Game (BoardManager.cs, GameManager.cs, UIManager.cs, etc.) which coordinate game flow, state, and rules.
- The MonoBehaviourSingleton pattern indicates a common approach to sharing central managers.
- The UnityChessLib might contain core chess logic separated from presentation.
- Chess Engine Integration:
- Interface (IUCIEngine) and concrete implementation (MockUCIEngine) alongside the UCI engine executable in Assets/StreamingAssets/UCIEngines. This shows that external chess engine integration is a key part of game move computation.
- Art and Rendering:
- Assets/Art (models, textures, materials) for the chess pieces, board, and visual effects.
- Post-processing components (Assets/PostProcessing) indicate a modular architecture for enhanced visuals.
- Additional Components:
- MultiplayerSystem.cs in Assets/Scripts/Game hints at networking capabilities.
- Editor scripts in Assets/Scripts/Editor assist with tooling and debugging.

##### Analyzing Relationships and Interactions
- The UI, Board, and GameManager prefabs interact to drive the game flow, with the BoardManager handling the state of the chess pieces and board.
- The GameManager communicates with the chess engine component (via IUCIEngine) to validate and generate moves.
- External assets like UCI engine executables are called from within the game logic when chess move decisions are required.
- Post-processing and art assets are utilized by the rendering system to provide visual fidelity.
- Editor and debugging tools are separate but facilitating deeper development and troubleshooting.

##### Architectural Patterns and Design Principles
- Component-based Design: Every element (board, pieces, UI) is modular, using Unity’s GameObject and prefab system.
- Separation of Concerns: Presentation (scenes, UI) and logic (game managers, chess logic) are clearly separated.
- Plugin/Interface-based Integration: Use of interfaces (e.g., IUCIEngine) allows swapping or mocking of the chess engine.
- Singleton Pattern: Observed from use of MonoBehaviourSingleton for central controllers.

- Provide clear labels for each component (e.g., “GameManager,” “BoardManager,” “Chess Engine Interface”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Unity Engine & Runtime
    subgraph "Unity Engine & Runtime"
        engine("Unity Engine 2021.2.6f1"):::unity
        sceneMgmt("Scene & Input Management"):::unity
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        scene("Board Scene"):::presentation
        subgraph "Prefabs"
            boardPrefab("Board Prefab"):::presentation
            gmPrefab("GameManager Prefab"):::presentation
            uiPrefab("UI Prefab"):::presentation
            cameraPrefab("Main Camera Prefab"):::presentation
            debugPrefab("DebugView Prefab"):::presentation
        end
    end

    %% Game Logic Layer
    subgraph "Game Logic"
        boardManager("BoardManager.cs"):::logic
        gameManager("GameManager.cs"):::logic
        uiManager("UIManager.cs"):::logic
        fullMoveUI("FullMoveUI.cs"):::logic
        multiplayer("MultiplayerSystem.cs"):::logic
        visualPiece("VisualPiece.cs"):::logic
        singleton("MonoBehaviourSingleton.cs"):::logic
        chessLib("UnityChessLib"):::logic
    end

    %% Chess Engine Integration
    subgraph "Chess Engine Integration"
        uciInterface("IUCIEngine.cs"):::chessEngine
        mockEngine("MockUCIEngine.cs"):::chessEngine
        uciExecutable("UCI Engine Executable"):::chessEngine
    end

    %% Art & Rendering
    subgraph "Art & Rendering"
        artAssets("Art Assets"):::art
        postProcessing("PostProcessing Effects"):::art
    end

    %% Editor Tools
    subgraph "Editor Tools"
        editorScripts("Editor Scripts"):::editor
    end

    %% Relationships
    engine --> sceneMgmt
    engine --> scene
    scene --> boardPrefab
    scene --> uiPrefab
    scene --> gmPrefab
    scene --> artAssets
    scene --> postProcessing

    boardPrefab -->|"controls"| boardManager
    uiPrefab -->|"updates"| uiManager
    gmPrefab -->|"initializes"| gameManager

    gameManager -->|"delegatesTo"| boardManager
    gameManager -->|"communicatesWith"| uiManager
    gameManager -->|"handlesNetwork"| multiplayer
    gameManager -->|"calls"| uciInterface
    boardManager -->|"utilizes"| chessLib
    uiManager -->|"triggers"| fullMoveUI

    uciInterface -->|"implementedBy"| mockEngine
    uciInterface -->|"invokes"| uciExecutable

    %% Click Events
    click scene "https://github.com/erkrodc/unitychess/blob/development/Assets/Scenes/Board.unity"
    click boardPrefab "https://github.com/erkrodc/unitychess/blob/development/Assets/Prefabs/Board.prefab"
    click gmPrefab "https://github.com/erkrodc/unitychess/blob/development/Assets/Prefabs/GameManager.prefab"
    click uiPrefab "https://github.com/erkrodc/unitychess/blob/development/Assets/Prefabs/UI.prefab"
    click cameraPrefab "https://github.com/erkrodc/unitychess/blob/development/Assets/Prefabs/Main Camera.prefab"
    click debugPrefab "https://github.com/erkrodc/unitychess/blob/development/Assets/Prefabs/Debug/DebugView.prefab"

    click boardManager "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/BoardManager.cs"
    click gameManager "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/GameManager.cs"
    click uiManager "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/UIManager.cs"
    click fullMoveUI "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/FullMoveUI.cs"
    click multiplayer "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/MultiplayerSystem.cs"
    click visualPiece "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/VisualPiece.cs"
    click singleton "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/MonoBehaviourSingleton.cs"
    click chessLib "https://github.com/erkrodc/unitychess/tree/development/Assets/Scripts/UnityChessLib"

    click uciInterface "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/IUCIEngine.cs"
    click mockEngine "https://github.com/erkrodc/unitychess/blob/development/Assets/Scripts/Game/MockUCIEngine.cs"
    click uciExecutable "https://github.com/erkrodc/unitychess/blob/development/Assets/StreamingAssets/UCIEngines/pigeon-1.5.1/pigeon-1.5.1.exe"

    click artAssets "https://github.com/erkrodc/unitychess/tree/development/Assets/Art"
    click postProcessing "https://github.com/erkrodc/unitychess/tree/development/Assets/PostProcessing"

    click editorScripts "https://github.com/erkrodc/unitychess/tree/development/Assets/Scripts/Editor"

    %% Styles
    classDef unity fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef presentation fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef logic fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef chessEngine fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef art fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef editor fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
