# blindmindstudios/starruler2-source architecture

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

- Interactive diagram: https://gitdiagram.com/blindmindstudios/starruler2-source
- Repository: https://github.com/blindmindstudios/starruler2-source

## Overview

##### Project type and purpose
- Star Ruler 2 is a large-scale, cross-platform 4X/RTS game engine and toolchain.
- It combines a native C++ core (rendering, physics, networking, resource management), an embedded AngelScript VM for game logic, a rich data-driven asset system (text data, models, shaders, sounds, UI skins), and mod‐editing/CI toolkits.

##### File structure
- Top level:
– Launcher executables/scripts (`Star Ruler 2.exe`, `StarRuler2.sh`) and `bin/` for compiled output.
– `data/`: all game assets and configuration (abilities, anomalies, models, shaders, sounds, maps, mods).
– `scripts/`: AngelScript client, server, shared and toolkit code driving high-level game logic, UI, AI, networking.
– `source/`: C++ engine code, sub-repos (Angelscript VM, freetype2, glfw, network, os abstraction, sound, util), and game-specific C++ (`source/game`).
- Patterns in structure:
– Subsystems are isolated in C++ (`source/game/render`, `physics`, `network`, `resource`).
– Script layers separated into `client`, `server`, `shadow`, `shared`.
– Asset directories (`data/...`) follow a strict domain model (abilities, buildings, research, etc.).
– Build scripts and CI under `source/linux`, `source/ci`, `source/msvc`.

##### README insights
- This is the full open-source release, MIT-licensed code with CC-BY-NC assets.
- Platform abstraction for Steam/GOG is removed but extensible.
- Build instructions demonstrate separation between working directory, external dependencies, and target binaries.
- Multiplayer compatibility retained via script definitions (`version.as`) and network manager components.

##### Detail
- Every major subsystem, script directory, and data repository
- At least one example of script-to-engine binding (e.g., `as_binding_print.cpp` → `Console` API)
- CI/build layer to reflect how the system is produced and deployed

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Launcher Layer
    subgraph "Launcher"
        EXE["Star Ruler 2.exe"]:::external
        SH["StarRuler2.sh"]:::external
        LOADER["SR2Loader/"]:::external
    end

    %% Engine Core Layer
    subgraph "Engine Core (C++ Core)" 
        REND["Rendering Subsystem"]:::engineCore
        PHYS["Physics Subsystem"]:::engineCore
        AUD["Audio Subsystem"]:::engineCore
        RES["Resource Manager"]:::engineCore
        NETCORE["Network Manager"]:::network
        OS["OS Abstraction"]:::engineCore
    end

    %% Scripting Layer
    subgraph "Scripting Layer (AngelScript VM Host)"
        VM["AngelScript VM"]:::scripts
        BIND["Script Bindings (Engine–Script API)"]:::scripts
        subgraph "Game Scripts"
            CLIENT["Client Scripts"]:::scripts
            SERVER["Server Scripts"]:::scripts
            SHARED["Shared Scripts"]:::scripts
            SHADOW["Shadow Scripts"]:::scripts
        end
    end

    %% Data/Asset Layer
    subgraph "Data/Asset Layer"
        ASSETS[(Game Data/Assets)]:::data
        MAPS[(maps/)]:::data
        MODS[(mods/)]:::data
    end

    %% Toolkits & CI Layer
    subgraph "Toolkits & CI"
        TOOL["Mod-Editing Toolkit"]:::scripts
        CI["CI/Build Automation"]:::external
        DOC["Documentation Generator"]:::external
    end

    %% Relationships
    EXE -->|"launches"| RES
    SH -->|"launches"| RES
    LOADER -->|"launches"| RES

    RES -->|"provides assets to"| REND
    RES -->|"provides assets to"| PHYS
    RES -->|"provides assets to"| AUD
    RES -->|"feeds data to"| VM

    OS -->|"platform services"| RES

    VM -->|"hosts scripts via API"| BIND
    BIND -->|"binds to"| CLIENT
    BIND -->|"binds to"| SERVER
    BIND -->|"binds to"| SHARED
    BIND -->|"binds to"| SHADOW

    SERVER -->|"authoritative state to"| NETCORE
    NETCORE -->|"sync state to"| CLIENT
    CLIENT -->|"user orders to"| NETCORE
    NETCORE -->|"sync state to"| SERVER

    TOOL -->|"edits assets in"| ASSETS
    TOOL -->|"uses scripts from"| SHARED
    CI -->|"builds engine from"| RES
    CI -->|"builds scripts from"| BIND
    DOC -->|"generates docs from"| VM

    ASSETS --> REND
    ASSETS --> PHYS
    ASSETS --> AUD

    MAPS --> RES
    MODS --> RES

    %% Click Events
    click EXE "https://github.com/blindmindstudios/starruler2-source/blob/master//Star Ruler 2.exe"
    click SH "https://github.com/blindmindstudios/starruler2-source/blob/master//StarRuler2.sh"
    click LOADER "https://github.com/blindmindstudios/starruler2-source/tree/master//loader/SR2Loader/"
    click REND "https://github.com/blindmindstudios/starruler2-source/tree/master/source/game/render/"
    click PHYS "https://github.com/blindmindstudios/starruler2-source/tree/master/source/game/physics/"
    click AUD "https://github.com/blindmindstudios/starruler2-source/tree/master/source/sound/"
    click RES "https://github.com/blindmindstudios/starruler2-source/tree/master/source/game/resource/"
    click NETCORE "https://github.com/blindmindstudios/starruler2-source/tree/master/source/game/network/"
    click OS "https://github.com/blindmindstudios/starruler2-source/tree/master/source/os/"
    click VM "https://github.com/blindmindstudios/starruler2-source/tree/master/source/angelscript/"
    click BIND "https://github.com/blindmindstudios/starruler2-source/tree/master/source/game/as/"
    click CLIENT "https://github.com/blindmindstudios/starruler2-source/tree/master/scripts/client/"
    click SERVER "https://github.com/blindmindstudios/starruler2-source/tree/master/scripts/server/"
    click SHARED "https://github.com/blindmindstudios/starruler2-source/tree/master/scripts/shared/"
    click SHADOW "https://github.com/blindmindstudios/starruler2-source/tree/master/scripts/shadow/"
    click TOOL "https://github.com/blindmindstudios/starruler2-source/tree/master/scripts/toolkit/"
    click ASSETS "https://github.com/blindmindstudios/starruler2-source/tree/master/data/"
    click MAPS "https://github.com/blindmindstudios/starruler2-source/tree/master/maps/"
    click MODS "https://github.com/blindmindstudios/starruler2-source/tree/master/mods/"
    click CI "https://github.com/blindmindstudios/starruler2-source/tree/master/source/ci/"
    click DOC "https://github.com/blindmindstudios/starruler2-source/tree/master/source/doc/"

    %% Styles
    classDef engineCore fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef scripts fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef network fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
