# lefti97/chess-sfml architecture

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

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

## Overview

##### Main components
- Game Entry Point: The main.cpp file is where program execution starts. This component is responsible for initializing the game and setting up the SFML window and main loop.
- Game Logic Component (ChessGame): Represented by chessGame.cpp/h, this module orchestrates the game state, handles rule enforcement, turn changes, and overall game progression.
- Board Representation: Indicated by board.cpp/h, this component models the chess board (its state, grid, etc.) and supports the placement and movement of pieces.
- Piece Handling: The piece.cpp/h files define the chess pieces (e.g., king, queen, etc.) and their behaviors.
- Texture and Graphic Management: The pieceTextures.cpp/h files manage the loading and mapping of textures for chess pieces, while the Textures folder (inside src) holds the image resources.
- External Dependencies: The project depends on SFML (as explained in the README) to provide rendering, window handling, and likely event management for user interaction.

##### Relationships and interactions
- The main entry point initializes the SFML window and probably creates a ChessGame instance.
- The ChessGame component relies on a Board instance to handle board state and interacts with Piece objects to manage individual chess entities.
- The PieceTextures component interacts with game objects to ensure that each piece has the proper visual representation by using textures stored in the Textures directory.
- SFML serves as the underlying framework to render graphics, process input, and display the game interface.

##### Architectural Patterns or Design Principles
- Instead of a complicated layered or microservices structure, this project follows a modular design where each module (game logic, board, pieces, textures) is clearly separated.
- The design encourages separation of concerns by isolating the game loop (in main.cpp), logic handling (ChessGame), state management (Board), and rendering helpers (PieceTextures).

##### Elements
- Optionally, highlight the “Textures” directory as a resource node linked to PieceTextures.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Nodes
    Main["Main/Entry Point"]:::core

    subgraph "Core Game Logic"
        ChessGame["ChessGame (Game Controller)"]:::core
        Board["Board (Game State)"]:::core
        Pieces["Pieces (Entities)"]:::core
    end

    subgraph "Rendering Module"
        PieceTextures["PieceTextures (Graphics Handler)"]:::render
    end

    SFML["SFML Library\n(Rendering & Window Management)"]:::external
    Textures["Textures\n(Resource Directory)"]:::resource

    %% Connections
    Main -->|"initializes"| ChessGame
    ChessGame -->|"controls"| Board
    Board -->|"manages"| Pieces
    ChessGame -->|"invokes"| PieceTextures
    PieceTextures -->|"renders"| Pieces
    PieceTextures -->|"loads"| Textures
    Main -->|"uses"| SFML
    PieceTextures -->|"uses"| SFML

    %% Click Events
    click Main "https://github.com/lefti97/chess-sfml/blob/master/src/main.cpp"
    click ChessGame "https://github.com/lefti97/chess-sfml/blob/master/src/chessGame.cpp"
    click Board "https://github.com/lefti97/chess-sfml/blob/master/src/board.cpp"
    click Pieces "https://github.com/lefti97/chess-sfml/blob/master/src/piece.cpp"
    click PieceTextures "https://github.com/lefti97/chess-sfml/blob/master/src/pieceTextures.cpp"
    click Textures "https://github.com/lefti97/chess-sfml/tree/master/src/Textures"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef render fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef resource fill:#F5CBA7,stroke:#7D6608,stroke-width:2px;
```
