# triformine/delixia architecture

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

- Interactive diagram: https://gitdiagram.com/triformine/delixia
- Repository: https://github.com/triformine/delixia

## Overview

##### Main Components
- Client:
- A React-based user interface (UI) that renders via the browser.
- A Babylon.js-powered 3D game scene (components like BabylonScene.tsx), which includes game components such as CharacterController, GameEngine, MapLoader, etc.
- Hooks and utilities that manage state and handle real-time communication with the game server (e.g., use-colyseus.ts).
- Assets management: Public assets (3D models, textures, skyboxes, etc.) are stored under the public folder.
- Server:
- A Colyseus game server running on Bun (as seen by src/server, including Dockerfile, index.ts, and rooms such as GameRoom.ts).
- Server configuration (app.config.ts) and utilities for handling game maps and room logic.
- Shared Library:
- Code in src/shared (such as shared schemas, type definitions, maps configuration) that is used by both the client and the server for consistent game state and communication.

##### Relationships and Interactions
- The Client communicates with the Server using Colyseus protocols (WebSocket/real-time messaging) for synchronizing game state.
- The Server manages real-time game sessions (GameRoom) and orchestrates player interactions and game events.
- The Shared module provides common types, schemas, and map data to ensure that both client and server remain in sync with the gameplay logic.
- Assets (3D models, textures, etc.) stored in the public folder support the rendering in the Babylon.js 3D scene.
- The build/deployment pipelines (Dockerfile, .env files, and Github workflows) indicate that containerization and CI/CD are part of the broader deployment architecture.

##### Architectural Patterns and Technologies
- Separation of Concerns: The client and server codebases are clearly separated into distinct folders (src/client and src/server), along with a shared module for common data.
- Real-Time Communication: The integration with Colyseus for handling multiplayer synchronization and state, with Bun providing performance benefits on the server side.
- 3D Rendering: Babylon.js for rendering the immersive 3D game environment.
- Component-Based UI: React (with Tailwind CSS) forms a minimalistic yet dynamic user interface.
- Game Engine Logic: Custom game-related logic (character and map loaders, interaction controllers, shader management) encapsulated in separate game modules.

##### Essential Components and Details
- The “Client” container should encapsulate both the visual user interface (HTML entrypoint like index.html, React components in src/client) and the game logic (Babylon.js integration and game controllers).
- The “Server” container should include game room orchestration (located in src/server/rooms), initialization (index.ts), and integration with Bun.
- External libraries/frameworks (Babylon.js, Colyseus, React, Tailwind, Bun) near the corresponding components.
- To include asset management (the public folder with its extensive 3D models) as it’s a key enabler for the 3D game environment.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Client Layer
    subgraph "Client"
        RCUI["React Client UI"]:::clientStyle
        Babylon["Babylon 3D Scene & Game Engine"]:::clientStyle
        Hooks["Utility Functions & Hooks"]:::clientStyle
        Assets["Public Assets Management"]:::clientStyle
    end

    %% Shared Layer
    subgraph "Shared"
        Shared["Shared Schemas, Types & Map Configurations"]:::sharedStyle
    end

    %% Server Layer
    subgraph "Server"
        Server["Bun-powered Colyseus Game Server"]:::serverStyle
        GameRoom["Game Room Logic"]:::serverStyle
        SrvUtils["Server Utilities (Map Loader)"]:::serverStyle
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        Infra["Deployment & Infra Configurations"]:::infraStyle
    end

    %% Connections / Data Flow
    RCUI -->|"realTimeSync"| Server
    Babylon -->|"renders using"| Assets
    Hooks -->|"handles WS"| Server
    RCUI -->|"renders UI"| Babylon
    RCUI ---|"uses"| Shared
    Server ---|"shares types with"| Shared
    Server -->|"orchestrates"| GameRoom
    Server -->|"utilizes"| SrvUtils
    Infra -->|"deploys"| Server

    %% Legend (for clarity)
    subgraph "Legend"
        L1["Client Components"]:::clientStyle
        L2["Server Components"]:::serverStyle
        L3["Shared Modules"]:::sharedStyle
        L4["Deployment/Infra"]:::infraStyle
        L5["---> : Data Flow/Dependency"]
    end

    %% Click Events for Client Components
    click RCUI "https://github.com/triformine/delixia/blob/master/src/client/App.tsx"
    click RCUI "https://github.com/triformine/delixia/tree/master/src/client/components/UI/"
    click Babylon "https://github.com/triformine/delixia/blob/master/src/client/components/BabylonScene.tsx"
    click Babylon "https://github.com/triformine/delixia/tree/master/src/client/game/"
    click Hooks "https://github.com/triformine/delixia/tree/master/src/client/hooks/"
    click Hooks "https://github.com/triformine/delixia/tree/master/src/client/utils/"
    click Assets "https://github.com/triformine/delixia/tree/master/public/"

    %% Click Events for Server Components
    click Server "https://github.com/triformine/delixia/tree/master/src/server/"
    click GameRoom "https://github.com/triformine/delixia/blob/master/src/server/rooms/GameRoom.ts"
    click SrvUtils "https://github.com/triformine/delixia/blob/master/src/server/utils/ServerMapLoader.ts"

    %% Click Event for Shared Module
    click Shared "https://github.com/triformine/delixia/tree/master/src/shared/"

    %% Click Event for Deployment/Infrastructure
    click Infra "https://github.com/triformine/delixia/tree/master/.github/workflows/"
    
    %% Styles
    classDef clientStyle fill:#E6F5FF,stroke:#0077B6,stroke-width:2px;
    classDef serverStyle fill:#FFEDDA,stroke:#FF5400,stroke-width:2px;
    classDef sharedStyle fill:#E2F0CB,stroke:#006400,stroke-width:2px;
    classDef infraStyle fill:#FDE2E4,stroke:#C40003,stroke-width:2px;
```
