# jaryjay/chess-roguelike architecture

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

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

## Overview

##### Main Components
- AI Module – Located in the “ai” directory. This Python-based component contains the game logic for AI moves, configuration, game types, and rules. It is started via main.py and uses external dependencies (requirements.txt).
- Game Backend – Found in the “backend” folder. These are Godot scripts (using .gd files) that implement core game logic, board management, piece rules, rules engine, and move management.
- Game Frontend – Found in the “frontend” folder. This includes Godot scene files (.tscn) and scripts (.gd) for visual rendering of the board, pieces, and user interface (UI elements like promotion UI). It bridges user interactions with the backend game state.
- Assets & Android Build – Assets folder holds logos and UI design elements, while the “android” folder indicates platform-specific build/version data.
- Configuration & Data – Files such as config.json and pieces.json provide configurable parameters and game-piece definitions. They are used by both AI and game logic.

##### Relationships and Interactions
- The AI Module operates as an independent executable, possibly designed for testing or simulating game decisions. In a live game environment, it might interact with the backend through command-line triggers or API endpoints (if integrated).
- The Backend is the central part that manages game state: it uses its own AI scripts (as seen with different AI implementations in the “backend/ai” subdirectory) and leverages board management (board/*) and game rules (rules/*).
- The Frontend communicates with the Backend: user inputs (e.g., moves on board, UI interactions) are sent to the backend, while backend state changes are visualized via the frontend’s scenes in Godot.
- Assets support visual design and iconography across the UI and game interfaces.
- The configuration files enable consistency of game settings and piece definitions across the layers.

##### Architectural Patterns and Design Principles
- Separation of Concerns – Clear division between AI, game logic (backend), and presentation (frontend).
- Layered Architecture – The design suggests a layered approach, where the backend (game engine logic) acts as the core and independent modules (AI, UI) interact with it.
- Modularity – Multiple implementations of AI (Python and Godot implementations) hint at plug-and-play modules that could be swapped or extended independently.
- Cross-Platform Consideration – With support for Android and desktop-like components, the system seems designed for scalability across platforms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% AI Module
    subgraph "AI Module"
        A1["AI: Move Generation"]:::ai
        A2["Entry Point (main.py)"]:::ai
        A3["Board Logic (board.py)"]:::ai
        A4["Game Logic (game.py)"]:::ai
        A5["AI Config (config.py)"]:::ai
    end

    %% Game Backend
    subgraph "Game Backend"
        B1["Backend: Game Logic & Rule Enforcement"]:::backend
        B2["Game Engine (game.gd)"]:::backend
        B3["Board Management"]:::backend
        B4["Rules Engine"]:::backend
        B5["Built-in AI"]:::backend
        B6["Backend Config (config.gd)"]:::backend
    end

    %% Game Frontend
    subgraph "Game Frontend"
        F1["Frontend: UI & Rendering"]:::frontend
        F2["Board Rendering"]:::frontend
        F3["UI Elements"]:::frontend
        F4["Piece Presentation"]:::frontend
    end

    %% Assets & Android Build
    subgraph "Assets & Android"
        AR1["Assets: Design Elements"]:::assets
        AR2["Android Build: Mobile Config"]:::assets
    end

    %% Configuration & Data
    subgraph "Configuration & Data"
        C1["Global Config (config.json)"]:::config
        C2["Piece Definitions (pieces.json)"]:::config
    end

    %% Relationships between major components
    F1 -->|"sends_input"| B1
    B1 -->|"requests_move"| A1
    A1 -->|"returns_move"| B1
    B1 -->|"state_update"| F1

    C1 -->|"feeds"| A5
    C1 -->|"feeds"| B6
    C2 -->|"defines"| A1
    C2 -->|"defines"| B1

    AR1 -->|"provides"| F3
    AR2 -->|"builds_for"| F1

    %% Styles for components using class definitions
    classDef ai fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef frontend fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef assets fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef config fill:#FFB6C1,stroke:#000,stroke-width:2px;

    %% Click Events for AI Module
    click A1 "https://github.com/jaryjay/chess-roguelike/tree/main/ai/"
    click A2 "https://github.com/jaryjay/chess-roguelike/blob/main/ai/main.py"
    click A3 "https://github.com/jaryjay/chess-roguelike/blob/main/ai/board.py"
    click A4 "https://github.com/jaryjay/chess-roguelike/blob/main/ai/game.py"
    click A5 "https://github.com/jaryjay/chess-roguelike/blob/main/ai/config.py"

    %% Click Events for Game Backend
    click B1 "https://github.com/jaryjay/chess-roguelike/tree/main/backend/"
    click B2 "https://github.com/jaryjay/chess-roguelike/blob/main/backend/game.gd"
    click B3 "https://github.com/jaryjay/chess-roguelike/tree/main/backend/board/"
    click B4 "https://github.com/jaryjay/chess-roguelike/tree/main/backend/rules/"
    click B5 "https://github.com/jaryjay/chess-roguelike/tree/main/backend/ai/"
    click B6 "https://github.com/jaryjay/chess-roguelike/blob/main/backend/config.gd"

    %% Click Events for Game Frontend
    click F1 "https://github.com/jaryjay/chess-roguelike/tree/main/frontend/"
    click F2 "https://github.com/jaryjay/chess-roguelike/tree/main/frontend/board/"
    click F3 "https://github.com/jaryjay/chess-roguelike/tree/main/frontend/ui/"
    click F4 "https://github.com/jaryjay/chess-roguelike/tree/main/frontend/pieces/"

    %% Click Events for Assets & Android Build
    click AR1 "https://github.com/jaryjay/chess-roguelike/tree/main/assets/"
    click AR2 "https://github.com/jaryjay/chess-roguelike/tree/main/android/"

    %% Click Events for Configuration & Data
    click C1 "https://github.com/jaryjay/chess-roguelike/blob/main/config.json"
    click C2 "https://github.com/jaryjay/chess-roguelike/blob/main/pieces.json"
```
