# duydo1007/ai_chess architecture

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

- Interactive diagram: https://gitdiagram.com/duydo1007/ai_chess
- Repository: https://github.com/duydo1007/ai_chess

## Overview

##### Main Components
- Entry Point: The main.py file serves as the starting point of the application.
- Game Logic & Move Validation: The check_valid_move.py file encapsulates the rules and validations for chess moves.
- Game State / Persistence: The game_state.json file likely maintains current board status and game progress.
- Assets Management:
- Images: Directory holding visual assets (chess pieces, board background, etc.)
- Sounds: A dedicated sounds folder containing sound files (e.g., game-start.mp3, move-check.mp3) which enhance user feedback.
- Development & Configuration Artifacts: The .idea directory for IDE settings and perhaps other environment configurations, though these are less critical from an architectural standpoint.

##### Interactions and Data Flow
- The main.py module orchestrates the overall game flow. It initializes the game state (reading from game_state.json), renders the board (using images), and processes user actions.
- When a move is attempted, main.py calls upon check_valid_move.py to validate the move according to chess rules.
- Based on game events (move, capture, castle, etc.), the appropriate sound file is played from the sounds directory.
- The design principle here leans toward a modular separation (almost an informal MVC pattern): models (game_state.json/assets), view (rendering images and playing sounds), and control (game logic and move validations).

##### Architectural Patterns and Principles
- Modularity: Each responsibility is clearly split between game logic, state management, and asset management.
- Separation of Concerns: Different directories and files indicate that the project is structured to isolate rules (check_valid_move.py) from state (game_state.json) and presentation assets (images, sounds).
- Extensibility: With dedicated modules for each core task, the application can be extended (e.g., enhanced UI features, networked play) without major refactoring.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Control Layer"
        Main["main.py"]:::controller
        Validator["check_valid_move.py"]:::controller
    end

    subgraph "Model Layer"
        State["game_state.json"]:::model
    end

    subgraph "View Layer"
        Images["images"]:::asset
        Sounds["sounds"]:::asset
    end

    Dev[".idea"]:::dev

    Main -->|"calls"| Validator
    Main -->|"loads"| State
    Main -->|"renders"| Images
    Main -->|"plays"| Sounds

    %% Styles
    classDef controller fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef model fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef asset fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef dev fill:#577590,stroke:#333,stroke-width:2px;

    %% Click Events
    click Main "https://github.com/duydo1007/ai_chess/blob/main/main.py"
    click Validator "https://github.com/duydo1007/ai_chess/blob/main/check_valid_move.py"
    click State "https://github.com/duydo1007/ai_chess/blob/main/game_state.json"
    click Images "https://github.com/duydo1007/ai_chess/tree/main/images"
    click Sounds "https://github.com/duydo1007/ai_chess/tree/main/sounds"
    click Dev "https://github.com/duydo1007/ai_chess/blob/main/.idea"
```
