# xenira/space3 architecture

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

- Interactive diagram: https://gitdiagram.com/xenira/space3
- Repository: https://github.com/xenira/space3

## Overview

##### Main Components

a) Client Layer:
- Bevy Game Engine (Main Client)
- UI Components
- Game States
- Networking Module
- Asset Management
- Input Handling

b) Server Layer:
- Game Logic Server
- PostgreSQL Database
- Game Instance Management
- Combat System
- Shop System
- Lobby System

c) Protocol Layer:
- Shared Data Types
- Communication Protocol
- Game Data (Gods/Characters)

**[Client Tier]**
- ↕
**[Protocol Layer]**
- ↕
**[Server Tier]**

##### Component Details

Client Tier (Blue Components):
- Sub-components:
- State Management (menu_login, game_combat, etc.)
- UI Components (prefabs, components)
- Asset Management (textures, fonts, vox models)
- Networking Module (polling, events)

Protocol Layer (Green Components):
- Protocol_types and protocol_data_types
- Data models for:
- Characters
- Gods
- Game States
- Communication Messages

Server Tier (Orange Components):
- Main Server Application
- Database (PostgreSQL)
- Service Modules:
- Game Service
- Combat Service
- Shop Service
- Lobby Service
- Game Instance Management
- Scheduler

##### Connection Flows

- Client-Server communication through the protocol layer
- Database interactions
- State transitions
- Service interactions

##### Additional Elements

Specialized sections for:
- Authentication flow
- Game state transitions
- Combat system interaction
- Shop system flow
- Lobby management

##### Technical Details

- Rust/Bevy for client
- PostgreSQL for persistence
- Docker for deployment
- WebAssembly support
- Diesel ORM
- Fairings for server middleware

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CM["Client Main"]:::client
        click CM "https://github.com/xenira/space3/blob/master/client/src/main.rs"
        
        subgraph ClientComponents
            UI["UI Components"]:::client
            click UI "https://github.com/xenira/space3/tree/master/client/src/prefabs/ui/"
            GS["Game States"]:::client
            click GS "https://github.com/xenira/space3/tree/master/client/src/states/"
            CN["Networking"]:::client
            click CN "https://github.com/xenira/space3/tree/master/client/src/networking/"
            AM["Asset Management"]:::client
            click AM "https://github.com/xenira/space3/tree/master/client/assets/"
            AN["Animation System"]:::client
            click AN "https://github.com/xenira/space3/blob/master/client/src/components/animation.rs"
            IH["Input Handling"]:::client
            click IH "https://github.com/xenira/space3/blob/master/client/src/components/dragndrop.rs"
        end
    end

    subgraph Protocol
        PT["Protocol Types"]:::protocol
        click PT "https://github.com/xenira/space3/tree/master/protocol/protocol_types/src/"
        
        subgraph GameData
            GD["Gods Data"]:::protocol
            click GD "https://github.com/xenira/space3/tree/master/protocol/data/gods/"
            CD["Characters Data"]:::protocol
            click CD "https://github.com/xenira/space3/tree/master/protocol/data/characters/"
        end
    end

    subgraph Server
        SM["Server Main"]:::server
        click SM "https://github.com/xenira/space3/blob/master/server/src/main.rs"
        DB[(PostgreSQL)]:::database
        click DB "https://github.com/xenira/space3/tree/master/server/migrations/"
        
        subgraph Services
            GIM["Game Instance Manager"]:::server
            click GIM "https://github.com/xenira/space3/blob/master/server/src/game/game_instance.rs"
            CS["Combat Service"]:::server
            click CS "https://github.com/xenira/space3/blob/master/server/src/service/combat_service.rs"
            SS["Shop Service"]:::server
            click SS "https://github.com/xenira/space3/blob/master/server/src/service/shop_service.rs"
            LS["Lobby Service"]:::server
            click LS "https://github.com/xenira/space3/blob/master/server/src/service/lobby_service.rs"
            GS2["Game Service"]:::server
            click GS2 "https://github.com/xenira/space3/blob/master/server/src/service/game_service.rs"
        end
        
        DM["Database Models"]:::server
        click DM "https://github.com/xenira/space3/tree/master/server/src/model/"
        SF["Server Fairings"]:::server
        click SF "https://github.com/xenira/space3/tree/master/server/src/fairings/"
        SCH["Scheduler"]:::server
        click SCH "https://github.com/xenira/space3/blob/master/server/src/scheduler.rs"
    end

    %% Connections
    CM --> ClientComponents
    ClientComponents --> CN
    CN <--> PT
    PT <--> SM
    SM --> Services
    Services --> DM
    DM --> DB
    SF --> SM
    SCH --> Services
    PT --> GameData
    
    %% Styles
    classDef client fill:#a8d1ff,stroke:#000
    classDef protocol fill:#90EE90,stroke:#000
    classDef server fill:#ffb366,stroke:#000
    classDef database fill:#c566ff,stroke:#000

    %% Legend
    subgraph Legend
        C1[Client Component]:::client
        P1[Protocol Component]:::protocol
        S1[Server Component]:::server
        D1[(Database)]:::database
    end
```
