# atifibrahim7/chess-2d-private architecture

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

- Interactive diagram: https://gitdiagram.com/atifibrahim7/chess-2d-private
- Repository: https://github.com/atifibrahim7/chess-2d-private

## Overview

##### Project type and purpose
- This is a standalone 2D desktop chess application written in C++ with a clean graphical interface.
- Purpose: Allow two players to play chess on a local machine with full rule support, move validation, game saving/loading, and UI enhancements (highlighting, timers, captured‐piece display).

##### File structure
- Top‐level directories:
- / – Public headers (board, chessGame, piece, menu, errorReporting, pieceTextures).
- src/ – Implementation (.cpp files) and main entry point (main.cpp).
- resources/Textures/ – All image assets (chess piece images, UI elements).
- CMakeLists.txt – Build configuration.
- Patterns:
- Clear separation of Game Logic (chessGame, board, piece) vs. UI (menu, pieceTextures) vs. Core Application (main.cpp).
- Resource directory for static assets.

##### Extract key architectural points from README
- Game logic fully encapsulates official chess rules.
- UI layer handles rendering, input, highlighting, timers.
- Game State Manager supports save/load and history tracking.

##### Main components
a. Application Entry (main.cpp)
b. Game Loop
c. Input Handler
d. UI Renderer
e. Game Logic / Rules Engine
f. Game State Manager
g. Resource Manager (textures)
h. Domain Models (Board, Piece)
i. Menu System
j. Error Reporting

##### Relationships & Interactions
- main.cpp initializes Resource Manager and Game State Manager, then enters the Game Loop.
- Game Loop cycles: Input Handler → Game Logic → UI Renderer.
- Input Handler reads mouse events and passes commands to Game Logic (e.g., select/move piece).
- Game Logic updates Domain Models (Board, Piece), enforces rules, notifies State Manager (for history, save).
- Menu System hooks into Input Handler and UI Renderer to provide start/load/save functionality.
- Error Reporting monitors invalid moves or runtime issues and surfaces alerts via UI Renderer.

##### Architectural patterns & design principles
- MVC‐like separation:
- Model – Domain Models + Game State Manager
- View – UI Renderer + Resource Manager
- Controller – Input Handler + Menu System
- Single Responsibility: each module (board logic, piece behavior, rendering, input) has a focused role.
- Event‐driven loop: central game loop dispatches input and orchestrates rendering/updates.

- Clear labels: e.g., “Game Logic Engine”, “Board Model”, “Piece Model”, “Texture Manager”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Entry
    ApplicationEntry["Application Entry"]:::core
    click ApplicationEntry "https://github.com/atifibrahim7/chess-2d-private/blob/master/src/main.cpp"

    %% Managers
    subgraph "Managers"
        ResourceManager["Resource Manager"]:::data
        click ResourceManager "https://github.com/atifibrahim7/chess-2d-private/tree/master/resources/Textures"
        GameStateManager["Game State Manager"]:::data
    end

    %% Initialization Flow
    ApplicationEntry -->|"initialize"| ResourceManager
    ApplicationEntry -->|"initialize"| GameStateManager
    ApplicationEntry -->|"start loop"| GameLoop

    %% Game Loop and Core Flow
    subgraph "Game Loop"
        direction TB
        GameLoop["Game Loop"]:::core
        InputHandler["Input Handler"]:::ui
        GameLogic["Game Logic Engine"]:::core
        click GameLogic "https://github.com/atifibrahim7/chess-2d-private/blob/master/include/chessGame.h"
        UIRenderer["UI Renderer"]:::ui
    end

    GameLoop --> InputHandler
    InputHandler --> GameLogic
    GameLogic --> UIRenderer
    UIRenderer --> GameLoop

    %% Domain Models
    BoardModel["Board Model"]:::data
    click BoardModel "https://github.com/atifibrahim7/chess-2d-private/blob/master/include/board.h"
    PieceModel["Piece Model"]:::data
    click PieceModel "https://github.com/atifibrahim7/chess-2d-private/blob/master/include/piece.h"
    GameLogic -->|"manipulates"| BoardModel
    GameLogic -->|"manipulates"| PieceModel

    %% Texture Management
    subgraph "Texture Management"
        TextureHeader["Texture Manager (header)"]:::ui
        click TextureHeader "https://github.com/atifibrahim7/chess-2d-private/blob/master/include/pieceTextures.h"
        TextureImpl["Texture Manager (impl)"]:::ui
        click TextureImpl "https://github.com/atifibrahim7/chess-2d-private/blob/master/src/pieceTextures.cpp"
        Textures["Textures (assets)"]:::data
        click Textures "https://github.com/atifibrahim7/chess-2d-private/tree/master/resources/Textures"
    end
    UIRenderer -->|"load textures"| TextureHeader
    UIRenderer --> TextureImpl
    UIRenderer --> Textures

    %% Menu System
    MenuSystem["Menu System"]:::ui
    click MenuSystem "https://github.com/atifibrahim7/chess-2d-private/blob/master/include/menu.h"
    InputHandler --> MenuSystem
    MenuSystem -->|"save/load"| GameStateManager
    MenuSystem --> UIRenderer

    %% Error Reporting
    ErrorReporting["Error Reporting"]:::util
    click ErrorReporting "https://github.com/atifibrahim7/chess-2d-private/blob/master/include/errorReporting.h"
    InputHandler --> ErrorReporting
    GameLogic --> ErrorReporting
    ErrorReporting --> UIRenderer

    %% State Updates
    GameLogic -->|"update state"| GameStateManager

    %% Styles
    classDef core fill:#d0e1f9,stroke:#0275d8,stroke-width:2px;
    classDef ui fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef util fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
