# hiveboardgame/hive architecture

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

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

## Overview

##### Main Components Identification

a) Frontend Layer (Leptos-based):
- Subcomponents for:
- Pages (/apis/src/pages)
- Components (atoms, molecules, organisms)
- Providers (websocket, game state, etc.)

b) Backend Services:
- WebSocket Server
- Client Handlers
- Server Handlers
- Connection Management
- Game Engine (/engine)
- Database Layer (/db)

c) External Systems:
- PostgreSQL Database
- Static Assets (tiles, sounds)

##### Component Relationships

a) Client-Server Communication:
**Frontend <---> WebSocket Server (bidirectional)**
**Frontend ----> HTTP Endpoints (one-directional for static resources)**

b) Internal Services:
**WebSocket Server <---> Game Engine**
**WebSocket Server <---> Database Layer**

##### Detailed Component Breakdown

Frontend (Leptos):

- Frontend         |

- Pages               |
- Components          |
- Providers           |
- WebSocket Client    |

Backend:

- WebSocket Server    |

- Connection Manager   |
- Game Handlers       |
- Tournament Handlers  |
- Chat Handlers       |

Game Engine:

- Game Engine       |

- Board Logic         |
- Game Rules          |
- State Management    |
- Move Validation     |

##### Deployment Context

Containerization:
- Docker container boundaries
- Fly.io deployment configuration
- Development vs Production environments

This architecture emphasizes the real-time nature of the game server while showing how it handles multiple concerns like game state, user management, and tournament organization in a scalable way.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef engine fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        Pages["Pages"]
        Components["Components"]
        Providers["Providers"]
        WSClient["WebSocket Client"]
        PWA["PWA Support"]
        I18n["Internationalization"]
        StaticAssets["Static Assets"]
    end

    %% Backend Layer
    subgraph Backend
        WSServer["WebSocket Server"]
        ClientHandlers["Client Handlers"]
        ServerHandlers["Server Handlers"]
        TournamentSystem["Tournament System"]
    end

    %% Game Engine Layer
    subgraph GameEngine
        EngineCore["Game Engine Core"]
        BoardLogic["Board Logic"]
        GameRules["Game Rules"]
        StateManagement["State Management"]
        MoveValidation["Move Validation"]
    end

    %% Database Layer
    subgraph Storage
        DB[(PostgreSQL)]
        DBLayer["Database Layer"]
        Migrations["DB Migrations"]
        RatingSystem["Rating System"]
    end

    %% Relationships
    Pages --> WSClient
    Components --> WSClient
    Providers --> WSClient
    WSClient <--> WSServer
    WSServer --> ClientHandlers
    WSServer --> ServerHandlers
    WSServer --> TournamentSystem
    WSServer <--> GameEngine
    GameEngine --> EngineCore
    EngineCore --> BoardLogic
    EngineCore --> GameRules
    EngineCore --> StateManagement
    EngineCore --> MoveValidation
    WSServer <--> DBLayer
    DBLayer --> DB
    DBLayer --> Migrations
    DBLayer --> RatingSystem

    %% Styling
    class Pages,Components,Providers,WSClient,PWA,I18n,StaticAssets frontend
    class WSServer,ClientHandlers,ServerHandlers,TournamentSystem backend
    class DB,DBLayer,Migrations,RatingSystem database
    class EngineCore,BoardLogic,GameRules,StateManagement,MoveValidation engine

    %% Click events
    click Pages "https://github.com/hiveboardgame/hive/tree/main/apis/src/pages/"
    click Components "https://github.com/hiveboardgame/hive/tree/main/apis/src/components/"
    click Providers "https://github.com/hiveboardgame/hive/tree/main/apis/src/providers/"
    click WSServer "https://github.com/hiveboardgame/hive/tree/main/apis/src/websocket/"
    click EngineCore "https://github.com/hiveboardgame/hive/tree/main/engine/src/"
    click DBLayer "https://github.com/hiveboardgame/hive/tree/main/db/"
    click StaticAssets "https://github.com/hiveboardgame/hive/tree/main/apis/assets/"
    click I18n "https://github.com/hiveboardgame/hive/tree/main/apis/locales/"
    click ClientHandlers "https://github.com/hiveboardgame/hive/tree/main/apis/src/websocket/client_handlers/"
    click ServerHandlers "https://github.com/hiveboardgame/hive/tree/main/apis/src/websocket/server_handlers/"
    click Migrations "https://github.com/hiveboardgame/hive/tree/main/db/migrations/"
    click PWA "https://github.com/hiveboardgame/hive/blob/main/apis/assets/js/pwa.js"
    click TournamentSystem "https://github.com/hiveboardgame/hive/tree/main/apis/src/websocket/server_handlers/tournaments/"
    click RatingSystem "https://github.com/hiveboardgame/hive/tree/main/db/migrations/2023-09-27-092621_ratings/"
```
