# abdlrhman08/hive-ai architecture

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

- Interactive diagram: https://gitdiagram.com/abdlrhman08/hive-ai
- Repository: https://github.com/abdlrhman08/hive-ai

## Overview

##### Project type and purpose
- This is a standalone desktop board‑game application (“Hive Board Game”) written in Python.
- It provides a graphical UI layer, a core game‑logic/model layer, an AI opponent layer, and uses simple asset files (audio) to enhance the user experience.
- The README confirms the flow: the user runs main.py, picks Human or AI players (with several search algorithms), then the game proceeds.

##### File structure
- Top‑level:
- main.py: application entry point and game orchestrator
- README.md, hive-rules.md: documentation
- flake.nix/flake.lock: nix build configuration
- test_board.py: unit tests for the game board
- “UI” directory:
- UI/HiveGame.py: hosts the game loop, renders board, handles input
- UI/Button.py, constants.py, hex_utils.py: helpers for drawing and event handling
- “utils” directory (core model):
- utils/board.py: Board class, placement rules, move generation
- utils/location.py: coordinate system on the hex grid
- utils/pieces/*.py: each piece’s movement and rule‑enforcement logic
- “AI” directory:
- AI/algorithms.py: implementations of MinMax, Alpha‑Beta, Iterative Deepening
- AI/state_tree.py, state_tree_node.py: representation of game states and search trees
- “assets” directory: audio files for various game events

##### README for additional insights
- Confirms zero external services—purely local.
- The architecture is MVC‑inspired: UI = View+Controller, utils = Model, AI = “Guest Controller” for automated players.

##### Be highly detailed
- Test harness as an ancillary component that depends on the Model API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User["User"]:::external

    %% Orchestrator
    Main["Application Orchestrator<br/>(main.py)"]:::orchestrator

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        HiveGame["Game Loop & Renderer<br/>(UI/HiveGame.py)"]:::ui
        Button["Button Helper<br/>(UI/Button.py)"]:::ui
        Constants["Constants<br/>(UI/constants.py)"]:::ui
        HexUtils["Hex Utilities<br/>(UI/hex_utils.py)"]:::ui
    end

    %% Model Layer
    subgraph "Game Model Layer"
        direction TB
        Board["Board Manager<br/>(utils/board.py)"]:::model
        Location["Location Service<br/>(utils/location.py)"]:::model
        subgraph "Piece Logic"
            direction TB
            GameObject["Base Piece Class<br/>(utils/pieces/game_object.py)"]:::model
            Ant["Ant<br/>(utils/pieces/ant.py)"]:::model
            Beetle["Beetle<br/>(utils/pieces/beetle.py)"]:::model
            GrassHopper["Grass Hopper<br/>(utils/pieces/grass_hopper.py)"]:::model
            Queen["Queen<br/>(utils/pieces/queen.py)"]:::model
            Spider["Spider<br/>(utils/pieces/spider.py)"]:::model
        end
    end

    %% AI Layer
    subgraph "AI Layer"
        direction TB
        Algorithms["Search Algorithms<br/>(AI/algorithms.py)"]:::ai
        StateTree["State Tree Representation<br/>(AI/state_tree.py)"]:::ai
        StateNode["State Tree Node<br/>(AI/state_tree_node.py)"]:::ai
    end

    %% Assets
    subgraph "Assets"
        direction TB
        BoardStart["board-start.mp3"]:::assets
        MenuSound["menu-sound.mp3"]:::assets
        PlaySound["play-sound.mp3"]:::assets
        GameOver["game-over.mp3"]:::assets
    end

    %% Tests
    Tests["Board Unit Tests<br/>(test_board.py)"]:::tests

    %% Relationships
    User -->|"input events"| HiveGame
    HiveGame -->|"initialize/game choice"| Main
    Main -->|"init board"| Board
    Main -->|"init location"| Location
    Main -->|"load pieces"| GameObject
    Main -->|"render updates"| HiveGame
    Main -->|"play sounds"| BoardStart
    Main -->|"play sounds"| MenuSound
    Main -->|"play sounds"| PlaySound
    Main -->|"play sounds"| GameOver
    Main <-->|"AI turn request"| Algorithms
    Algorithms -->|"uses state tree"| StateTree
    StateTree -->|"creates nodes"| StateNode
    HiveGame -->|"trigger audio"| BoardStart
    HiveGame -->|"trigger audio"| MenuSound
    HiveGame -->|"trigger audio"| PlaySound
    HiveGame -->|"trigger audio"| GameOver
    Tests -.->|"tests board logic"| Board

    %% Click Events
    click Main "https://github.com/abdlrhman08/hive-ai/blob/main/main.py"
    click HiveGame "https://github.com/abdlrhman08/hive-ai/blob/main/UI/HiveGame.py"
    click Button "https://github.com/abdlrhman08/hive-ai/blob/main/UI/Button.py"
    click Constants "https://github.com/abdlrhman08/hive-ai/blob/main/UI/constants.py"
    click HexUtils "https://github.com/abdlrhman08/hive-ai/blob/main/UI/hex_utils.py"
    click Board "https://github.com/abdlrhman08/hive-ai/blob/main/utils/board.py"
    click Location "https://github.com/abdlrhman08/hive-ai/blob/main/utils/location.py"
    click Ant "https://github.com/abdlrhman08/hive-ai/blob/main/utils/pieces/ant.py"
    click Beetle "https://github.com/abdlrhman08/hive-ai/blob/main/utils/pieces/beetle.py"
    click GrassHopper "https://github.com/abdlrhman08/hive-ai/blob/main/utils/pieces/grass_hopper.py"
    click Queen "https://github.com/abdlrhman08/hive-ai/blob/main/utils/pieces/queen.py"
    click Spider "https://github.com/abdlrhman08/hive-ai/blob/main/utils/pieces/spider.py"
    click GameObject "https://github.com/abdlrhman08/hive-ai/blob/main/utils/pieces/game_object.py"
    click Algorithms "https://github.com/abdlrhman08/hive-ai/blob/main/AI/algorithms.py"
    click StateTree "https://github.com/abdlrhman08/hive-ai/blob/main/AI/state_tree.py"
    click StateNode "https://github.com/abdlrhman08/hive-ai/blob/main/AI/state_tree_node.py"
    click BoardStart "https://github.com/abdlrhman08/hive-ai/blob/main/assets/board-start.mp3"
    click MenuSound "https://github.com/abdlrhman08/hive-ai/blob/main/assets/menu-sound.mp3"
    click PlaySound "https://github.com/abdlrhman08/hive-ai/blob/main/assets/play-sound.mp3"
    click GameOver "https://github.com/abdlrhman08/hive-ai/blob/main/assets/game-over.mp3"
    click Tests "https://github.com/abdlrhman08/hive-ai/blob/main/test_board.py"

    %% Styles
    classDef orchestrator fill:#f88,stroke:#000,color:#000
    classDef ui fill:#8cf,stroke:#000,color:#000
    classDef model fill:#8f8,stroke:#000,color:#000
    classDef ai fill:#fc8,stroke:#000,color:#000
    classDef assets fill:#c8f,stroke:#000,color:#000
    classDef tests fill:#ccc,stroke:#000,color:#000
    classDef external fill:#fff,stroke:#000,color:#000
```
