# kumpelblase2/skrillax architecture

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

- Interactive diagram: https://gitdiagram.com/kumpelblase2/skrillax
- Repository: https://github.com/kumpelblase2/skrillax

## Overview

##### Project Type and Purpose
- This is a Rust-based server emulator project for an MMORPG (Silkroad Online). Its main goal is to learn Rust and ECS concepts by implementing a partially working game server.
- The project is modular, consisting of several interrelated subprojects (crates) that handle protocols, game logic, navigation mesh, login, RPC, and more.
- Key servers include the silkroad-gateway (login server) and silkroad-agent (game server), which communicate with each other and a PostgreSQL database.

##### Analyzing the File Structure
- Top-level directories to note:
– configs (with separate TOML configuration files for the agent and gateway servers)
– migrations (SQL scripts used to set up the database schema)
– crates (contains several sub-crates such as silkroad-protocol, silkroad-data, silkroad-gateway-protocol, silkroad-rpc, silkroad-navmesh, silkroad-game-base, silkroad-protocol, etc.)
– silkroad-agent and silkroad-gateway (each with multiple modules such as login, game, net, chat, sync, etc.)
- There are also Docker-related files and docker-compose examples, indicating containerized deployment is supported.
- The project is organized as a multi-crate Rust workspace which promotes modularity and separation of concerns – for instance, separating protocol definitions from game logic and external communications.

##### Key Components
a. Client & External Dependencies:
– The Silkroad Online client (external; not part of the repository but as the consumer that interacts with the servers).
– External dependencies such as the “skrillax-network” family of crates.
b. Servers:
– Silkroad Gateway Server: Handles authentication, login procedures, and forwarding registration commands.
– Silkroad Agent Server: Main gameserver, handling game logic such as NPC management, gameplay events, movement, inventory, etc.
c. Shared Components and Libraries:
– Protocol Definitions: Provided by crates like silkroad-protocol and silkroad-gateway-protocol. These define the packet specifications and communication contracts with the client.
– RPC & Shared Types: silkroad-rpc for inter-server communication.
– Navigation Mesh: silkroad-navmesh handles the world geometry/navigation used by agent server.
– Game Base and Data: crates like silkroad-game-base, silkroad-data, and silkroad-definitions encapsulate core game logic, character data, inventory, items, etc.
d. Infrastructure:
– Database: PostgreSQL instance (setup via migrations and configured in the TOML files). It stores persistent game data, user accounts, world definitions, etc.
– Deployment: Docker Compose is utilized to spin up containers for the database, gateway, and agent servers.
– Configuration Files: Located in the “configs” directory, defining server-specific parameters (database credentials, game data location, RPC addresses).

##### Relationships and Interactions
– Clients connect to the Silkroad Gateway server to authenticate and potentially register new users.
– Once authenticated, the gateway communicates, possibly via defined RPC channels (“silkroad-rpc”), with the Silkroad Agent server where actual game logic and state management are handled.
– Both servers interact with the PostgreSQL database for persistence, relying on SQL migrations and configuration settings.
– Shared libraries (protocol, data, navmesh) form the foundation for data formats and core mechanics (e.g., movement, combat, chat, inventory) that are used throughout the servers.
– The ECS design within the agent’s codebase (evident in directories such as “agent/src/agent” and “agent/src/comp”) organizes game state and systems like chat, movement, skill processing, etc.

##### Architectural Patterns and Design Principles
– Modularity: The system is divided into several crates each with a focused responsibility (protocol, game core, navigation, etc.).
– Service Separation: A clear separation between the login (gateway) and game (agent) servers.
– ECS (Entity Component System) is used in the agent server to manage game objects and behavior.
– Configuration-as-code: Use of TOML configuration files allows flexible environment setups.
– Containerization: Docker and docker-compose ensure repeatable deployments and clear separation of infrastructure components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        A["Silkroad Online Client"]:::client
    end

    %% Server Layer
    subgraph "Server Layer"
        B["Gateway Server"]:::server
        C["Agent Server"]:::server
        E["ECS Architecture (in Agent)"]:::ecs
    end

    %% Shared Components
    subgraph "Shared Components"
        F["Silkroad Protocol"]:::shared
        G["Gateway Protocol"]:::shared
        H["RPC & Shared Types"]:::shared
        I["Navigation Mesh"]:::shared
        subgraph "Game Base & Data"
            J1["Game Base"]:::shared
            J2["Game Data"]:::shared
            J3["Game Definitions"]:::shared
        end
    end

    %% Infrastructure
    subgraph "Infrastructure"
        D["PostgreSQL Database"]:::database
        K["Configurations"]:::infra
        L["Migrations"]:::infra
    end

    %% Deployment / Containerization
    subgraph "Deployment"
        M1["Dockerfile"]:::deploy
        M2["docker-compose"]:::deploy
        M3["Docker Run Script"]:::deploy
    end

    %% Connections
    A -->|"Auth/Register"| B
    B -->|"RPC"| C
    B -->|"DB_Ops"| D
    C -->|"DB_Ops"| D

    B -->|"Uses"| F
    B -->|"Uses"| G
    B -->|"Uses"| H
    C -->|"Uses"| H
    C -->|"Uses"| I
    C -->|"Uses"| J1
    C -->|"Uses"| J2
    C -->|"Uses"| J3

    B -->|"Reads"| K
    C -->|"Reads"| K
    K -->|"Configures"| D
    L -->|"Initializes"| D

    C -->|"Manages"| E

    M2 -->|"Deploys"| B
    M2 -->|"Deploys"| C
    M2 -->|"Deploys"| D

    %% Click Events
    click B "https://github.com/kumpelblase2/skrillax/tree/master/silkroad-gateway/"
    click C "https://github.com/kumpelblase2/skrillax/tree/master/silkroad-agent/"
    click F "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-protocol/"
    click G "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-gateway-protocol/"
    click H "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-rpc/"
    click I "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-navmesh/"
    click J1 "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-game-base/"
    click J2 "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-data/"
    click J3 "https://github.com/kumpelblase2/skrillax/tree/master/crates/silkroad-definitions/"
    click E "https://github.com/kumpelblase2/skrillax/tree/master/silkroad-agent/src/agent/"
    click K "https://github.com/kumpelblase2/skrillax/tree/master/configs/"
    click L "https://github.com/kumpelblase2/skrillax/tree/master/migrations/"
    click M1 "https://github.com/kumpelblase2/skrillax/tree/master/Dockerfile"
    click M2 "https://github.com/kumpelblase2/skrillax/blob/master/docker-compose.yml.example"
    click M3 "https://github.com/kumpelblase2/skrillax/blob/master/scripts/docker-run.sh"

    %% Styles
    classDef client fill:#ffcc80,stroke:#d35400,stroke-width:2px;
    classDef server fill:#85c1e9,stroke:#2471a3,stroke-width:2px;
    classDef ecs fill:#f7dc6f,stroke:#b7950b,stroke-width:2px;
    classDef shared fill:#abebc6,stroke:#27ae60,stroke-width:2px;
    classDef database fill:#f1948a,stroke:#c0392b,stroke-width:2px;
    classDef infra fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef deploy fill:#fad7a0,stroke:#e67e22,stroke-width:2px;
```
