# alexpineda/titan-reactor architecture

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

- Interactive diagram: https://gitdiagram.com/alexpineda/titan-reactor
- Repository: https://github.com/alexpineda/titan-reactor

## Overview

##### Main Components Architecture

The system should be represented with these primary components:

- Titan Reactor                                        |

- ^                    ^                     ^

- UI Runtime     |  |    Plugins     |  |     Cascbridge      |
- (iframe-based)   |  |                |  | (Asset Server)      |

##### Core System Components (Detail Layer)

- Titan Reactor                                        |

- OpenBW    |    |  Three.js     |    |  Plugin System |    |  Asset Management|   |
- Integration |    |  Renderer      |    |                |    |                  |   |

- Scene     |    |    World      |    |     Input      |    |     Audio        |   |
- Management  |    |  Composition   |    |   Handling     |    |    System        |   |

##### Data Flow Architecture

- Cascbridge   | --> |  Asset Loader | --> |  Resource Manager|
- (SC Assets)   |     |               |     |                  |

- v

- OpenBW WASM  | <- |  Game State   | <- |    Renderer      |
- Engine       |    |  Management   |    |                  |

- v

- Plugin System | <- |   UI Runtime  | <- |    User Input    |
- (iframe)    |    |    Processing    |

##### Key Technical Elements to Highlight

- Blue: Core engine components (OpenBW, Three.js)
- Green: Asset management and loading
- Orange: Plugin system and UI components
- Purple: Input and state management

- WebGL/Three.js
- WebAssembly (OpenBW)
- File system interactions
- Network communications

##### Important Subsystems to Detail

- Plugin System                                        |

- Plugin Host   |    |  Plugin Registry  |    | Session Context  |    | UI Runtime   | |
- Bridge       | |

##### Asset Pipeline

- SC Assets    | -> | Asset Server  | -> |  Asset Cache   | -> |  Renderer    |
- (via Casc)    |    | (Cascbridge) |    | (IndexedDB)    |    |              |

- The separation between the core engine and plugin system
- The asset loading pipeline
- The communication between UI Runtime and main application
- The WebGL rendering pipeline
- The integration with OpenBW
- The plugin system's extensibility points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph TitanReactor["Titan Reactor Core"]
        Core["Core Engine"]:::core
        OpenBW["OpenBW Integration"]:::core
        ThreeJS["Three.js Renderer"]:::renderer
        SceneMgmt["Scene Management"]:::core
        WorldComp["World Composition"]:::core
        InputHandle["Input Handling"]:::input
        AudioSys["Audio System"]:::core
        GameState["Game State Management"]:::state
        ResourceMgr["Resource Management"]:::resource
    end

    subgraph AssetPipeline["Asset Pipeline"]
        CascBridge["Cascbridge<br/>(Asset Server)"]:::asset
        AssetLoader["Asset Loader"]:::asset
        AssetCache["Asset Cache<br/>(IndexedDB)"]:::asset
    end

    subgraph PluginSystem["Plugin System"]
        PluginHost["Plugin Host"]:::plugin
        PluginRegistry["Plugin Registry"]:::plugin
        SessionContext["Session Context"]:::plugin
        UIBridge["UI Runtime Bridge"]:::plugin
    end

    subgraph UIRuntime["UI Runtime Layer"]
        UIFrame["iframe-based UI"]:::ui
        ConfigUI["Configuration UI"]:::ui
    end

    %% Connections
    CascBridge --> AssetLoader
    AssetLoader --> AssetCache
    AssetCache --> ResourceMgr
    ResourceMgr --> ThreeJS

    Core --> OpenBW
    Core --> ThreeJS
    Core --> SceneMgmt
    Core --> WorldComp
    
    GameState --> Core
    InputHandle --> GameState
    AudioSys --> Core
    
    PluginHost --> Core
    PluginRegistry --> PluginHost
    SessionContext --> PluginHost
    UIBridge --> UIFrame
    
    UIFrame --> InputHandle
    ConfigUI --> Core

    %% Click Events
    click Core "https://github.com/alexpineda/titan-reactor/blob/dev/src/core/titan-reactor.ts"
    click OpenBW "https://github.com/alexpineda/titan-reactor/tree/dev/src/openbw/"
    click ThreeJS "https://github.com/alexpineda/titan-reactor/tree/dev/src/render/"
    click SceneMgmt "https://github.com/alexpineda/titan-reactor/tree/dev/src/scenes/"
    click WorldComp "https://github.com/alexpineda/titan-reactor/tree/dev/src/core/world/"
    click InputHandle "https://github.com/alexpineda/titan-reactor/tree/dev/src/input/"
    click AudioSys "https://github.com/alexpineda/titan-reactor/tree/dev/src/audio/"
    click GameState "https://github.com/alexpineda/titan-reactor/tree/dev/src/stores/"
    click ResourceMgr "https://github.com/alexpineda/titan-reactor/blob/dev/src/image/loader/resource-loader.ts"
    click AssetLoader "https://github.com/alexpineda/titan-reactor/tree/dev/src/image/loader/"
    click PluginHost "https://github.com/alexpineda/titan-reactor/tree/dev/src/plugins/"
    click UIFrame "https://github.com/alexpineda/titan-reactor/blob/dev/src/runtime.tsx"
    click ConfigUI "https://github.com/alexpineda/titan-reactor/tree/dev/src/configuration-ui/"

    %% Styles
    classDef core fill:#2b5797,color:#fff
    classDef renderer fill:#1a237e,color:#fff
    classDef asset fill:#2e7d32,color:#fff
    classDef plugin fill:#ff8f00,color:#fff
    classDef ui fill:#6a1b9a,color:#fff
    classDef input fill:#c62828,color:#fff
    classDef state fill:#283593,color:#fff
    classDef resource fill:#00695c,color:#fff

    %% Legend
    subgraph Legend
        CoreL["Core Components"]:::core
        RenderL["Renderer"]:::renderer
        AssetL["Asset Management"]:::asset
        PluginL["Plugin System"]:::plugin
        UIL["UI Components"]:::ui
        InputL["Input Processing"]:::input
        StateL["State Management"]:::state
        ResourceL["Resource Management"]:::resource
    end
```
