# mercotui/u-bahn architecture

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

- Interactive diagram: https://gitdiagram.com/mercotui/u-bahn
- Repository: https://github.com/mercotui/u-bahn

## Overview

##### Project type and purpose
- U-Bahn is a cross-platform, native C++ “game” or simulation engine.
- It uses CMake + Conan for build/packaging, protobuf for world definition, Raylib/libenjoy for rendering & input, and has content-tooling (a Blender exporter addon).

##### File structure
- Top-level build & config: CMakeLists.txt, conanfile.py, profiles/, containers/, .github CI.
- Core code under src/:
- src/game – game engine modules (camera, input, control, world simulation).
- src/platform – OS/target shims (desktop, Android, Emscripten).
- src/utils – common utilities (file I/O, versioning).
- src/third_party – bundled deps (libenjoy, raylib).
- proto/ – protobuf definitions for world files.
- Resources/ contains models and binary level files.
- Tools/ contains the Blender addon used in the asset pipeline.

##### README for additional insights
- Confirms it’s a game engine; suggests protobuf world editing; points to build docs.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Build & Packaging Layer
    subgraph "Build & Packaging Layer"
        direction TB
        CMake["CMakeLists.txt"] 
        Conan["conanfile.py"]
        Profiles["profiles/"]
        Containers["containers/"]
        CI[".github/workflows/ci.yml"]
    end

    %% Asset Pipeline
    subgraph "Asset Pipeline Tools"
        direction TB
        BlenderDir["tools/blender_exporter_addon/"]
        ExportRails["export_rails.py"]
        ExportTest["export_rails_test.py"]
        ProtoDefs["proto/"]
    end

    %% Engine Core
    subgraph "Engine Core"
        direction TB
        GameOrch["game.cpp / game.h"]
        subgraph "Camera Module"
            direction TB
            CamIface["camera_interface.h"]
            CamImpl["camera.cpp"]
        end
        subgraph "Input Manager"
            direction TB
            InputIface["input_manager_interface.h"]
            IMImpl["input_manager.cpp"]
            Joystick["joystick_handler.cpp"]
            RaylibInput["raylib_input_handlers.cpp"]
        end
        subgraph "Control Scheme Mapper"
            direction TB
            ControlIface["control_scheme_mapper.h"]
            ControlImpl["control_scheme_mapper.cpp"]
        end
        subgraph "World Simulation"
            direction TB
            WorldHdr["world.h"]
            WorldImpl["world.cpp"]
            RailSeg["rail_segment.cpp"]
            TrainMod["train.cpp"]
        end
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        FileIface["file_reader_interface.h"]
        FileImpl["file_reader.cpp"]
        Version["version.h"]
    end

    %% Third-Party Libraries
    subgraph "Third-Party Libraries"
        direction TB
        LibEnjoy["src/third_party/libenjoy/"]
        RaylibDir["src/third_party/raylib/"]
    end

    %% Platform Abstraction Layer
    subgraph "Platform Targets"
        direction TB
        subgraph "Desktop"
            MainCPP["src/main.cpp"]
            PlatformSrc["platform.cpp / platform.h"]
        end
        subgraph "Android"
            AndroidManifest["AndroidManifest.xml"]
            NativeLoader["NativeLoader.java"]
            PackageAPK["package_apk.sh"]
        end
        subgraph "Web (Emscripten)"
            ShellHTML["shell.html"]
        end
    end

    %% Resources
    subgraph "Resources"
        direction TB
        Model["berlin/f7x-attempt-1.glb"]
        WorldBin["world_unitest_test_track.bin"]
    end

    %% Relationships
    CMake -->|builds| GameOrch
    CMake -->|builds| MainCPP
    CMake -->|builds| LibEnjoy
    CMake -->|builds| RaylibDir

    Conan -->|manages deps| LibEnjoy
    Conan -->|manages deps| RaylibDir
    CI -->|runs build| CMake

    GameOrch -->|"uses"| CamIface
    GameOrch -->|"uses"| InputIface
    GameOrch -->|"uses"| ControlIface
    GameOrch -->|"uses"| WorldHdr

    CamIface --> CamImpl
    InputIface --> IMImpl
    IMImpl --> Joystick
    IMImpl --> RaylibInput
    ControlIface --> ControlImpl
    WorldHdr --> WorldImpl
    WorldImpl --> RailSeg
    WorldImpl --> TrainMod

    GameOrch -->|"calls"| PlatformSrc
    GameOrch -->|"renders via"| RaylibDir
    GameOrch -->|"reads input via"| LibEnjoy
    GameOrch -->|"loads"| Model
    GameOrch -->|"loads"| WorldBin

    BlenderDir --> ExportRails
    BlenderDir --> ExportTest
    ExportRails --> ProtoDefs
    ProtoDefs --> WorldBin
    ExportTest --> ProtoDefs

    %% Click Events
    click CMake "https://github.com/mercotui/u-bahn/blob/main/CMakeLists.txt"
    click Conan "https://github.com/mercotui/u-bahn/blob/main/conanfile.py"
    click Profiles "https://github.com/mercotui/u-bahn/tree/main/profiles/"
    click Containers "https://github.com/mercotui/u-bahn/tree/main/containers/"
    click CI "https://github.com/mercotui/u-bahn/blob/main/.github/workflows/ci.yml"
    click BlenderDir "https://github.com/mercotui/u-bahn/tree/main/tools/blender_exporter_addon/"
    click ExportRails "https://github.com/mercotui/u-bahn/blob/main/tools/blender_exporter_addon/ubahn_exporter_blender_addon/export_rails.py"
    click ExportTest "https://github.com/mercotui/u-bahn/blob/main/tools/blender_exporter_addon/tests/export_rails_test.py"
    click ProtoDefs "https://github.com/mercotui/u-bahn/tree/main/proto/"
    click GameOrch "https://github.com/mercotui/u-bahn/blob/main/src/game/game.cpp"
    click CamIface "https://github.com/mercotui/u-bahn/blob/main/src/game/camera/camera_interface.h"
    click CamImpl "https://github.com/mercotui/u-bahn/blob/main/src/game/camera/private/camera.cpp"
    click InputIface "https://github.com/mercotui/u-bahn/blob/main/src/game/input/input_manager_interface.h"
    click IMImpl "https://github.com/mercotui/u-bahn/blob/main/src/game/input/private/input_manager.cpp"
    click Joystick "https://github.com/mercotui/u-bahn/blob/main/src/game/input/private/joystick_handler.cpp"
    click RaylibInput "https://github.com/mercotui/u-bahn/blob/main/src/game/input/private/raylib_input_handlers.cpp"
    click ControlIface "https://github.com/mercotui/u-bahn/blob/main/src/game/control/control_scheme_mapper.h"
    click ControlImpl "https://github.com/mercotui/u-bahn/blob/main/src/game/control/private/control_scheme_mapper.cpp"
    click WorldHdr "https://github.com/mercotui/u-bahn/blob/main/src/game/world/world.h"
    click WorldImpl "https://github.com/mercotui/u-bahn/blob/main/src/game/world/private/world.cpp"
    click RailSeg "https://github.com/mercotui/u-bahn/blob/main/src/game/world/private/rail_segment.cpp"
    click TrainMod "https://github.com/mercotui/u-bahn/blob/main/src/game/world/private/train.cpp"
    click MainCPP "https://github.com/mercotui/u-bahn/blob/main/src/main.cpp"
    click PlatformSrc "https://github.com/mercotui/u-bahn/blob/main/src/platform/platform.cpp"
    click AndroidManifest "https://github.com/mercotui/u-bahn/blob/main/src/platform/android/AndroidManifest.xml"
    click NativeLoader "https://github.com/mercotui/u-bahn/blob/main/src/platform/android/NativeLoader.java"
    click PackageAPK "https://github.com/mercotui/u-bahn/blob/main/src/platform/android/package_apk.sh"
    click ShellHTML "https://github.com/mercotui/u-bahn/blob/main/src/platform/emscripten/shell.html"
    click LibEnjoy "https://github.com/mercotui/u-bahn/tree/main/src/third_party/libenjoy/"
    click RaylibDir "https://github.com/mercotui/u-bahn/tree/main/src/third_party/raylib/"
    click FileIface "https://github.com/mercotui/u-bahn/blob/main/src/utils/file_reader_interface.h"
    click FileImpl "https://github.com/mercotui/u-bahn/blob/main/src/utils/private/file_reader.cpp"
    click Version "https://github.com/mercotui/u-bahn/blob/main/src/utils/version.h"
    click Model "https://github.com/mercotui/u-bahn/blob/main/resources/berlin/f7x-attempt-1.glb"
    click WorldBin "https://github.com/mercotui/u-bahn/blob/main/src/game/world/private/world_unitest_test_track.bin"

    %% Styles
    classDef buildpack fill:#a6e3a1,stroke:#0f380f
    classDef engine fill:#89b4fa,stroke:#07467c
    classDef thirdparty fill:#f2cd5c,stroke:#7a620a
    classDef platform fill:#8bd5ca,stroke:#2c5f5f
    classDef utils fill:#cdd6f4,stroke:#4f4f67
    classDef resources fill:#ffe5b4,stroke:#cc9a06
    classDef asset fill:#dcaeee,stroke:#722d7a

    class CMake,Conan,Profiles,Containers,CI buildpack
    class GameOrch,CamIface,CamImpl,InputIface,IMImpl,Joystick,RaylibInput,ControlIface,ControlImpl,WorldHdr,WorldImpl,RailSeg,TrainMod engine
    class LibEnjoy,RaylibDir thirdparty
    class MainCPP,PlatformSrc,AndroidManifest,NativeLoader,PackageAPK,ShellHTML platform
    class FileIface,FileImpl,Version utils
    class Model,WorldBin resources
    class BlenderDir,ExportRails,ExportTest,ProtoDefs asset
```
