# aminere/spider-engine architecture

> Architecture diagram of the GitHub repository aminere/spider-engine, 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/aminere/spider-engine
- Repository: https://github.com/aminere/spider-engine

## Overview

##### Main Components
- Engine Core & Modules – At the heart of the system are the core functionalities provided under directories like “src/core”, “src/common”, and “src/serialization”. Represent the Engine Initialization, Entity-Component System, Scene Management, and update loops here.
- Graphics/Rendering Subsystem – Include modules from “src/graphics” (and its subdirectories such as “camera”, “geometry”, “lighting”, “shading”, “texture”, “volume”, and “postfx”). These modules manage everything from camera projection to shader handling and visual effects using WebGL.
- Animation – Capture the animation system using components in “src/animation” (including animation tracks, key management, and IK systems).
- Physics & Collision – Represent physics (from “src/physics”) and collision handling (in “src/collision”) that handle physical interactions within the engine.
- Behavior & Scripting – Outline the behavior system (from “src/behavior”, with its operators, converters, and node-based logic) that allows scripting and game logic control.
- UI System – Include the UI framework (“src/ui”) which provides custom elements, layouts, and text/image rendering.
- Input System – Show the handling of gamepad inputs and other user inputs (“src/input”).
- Editor Frontend & Launchers – Represent the separate code and assets for the editor (found in “src/editor”) and launcher components (in the “launcher” directory for Electron and Android, among others).
- Workers – Indicate specialized worker threads (such as for raytracing from “workers/raytracer”) that provide off-main-thread computations.

##### Relationships and Interactions
- Communication between the rendering pipeline and core update loops, with the Engine passing scene, camera, and shader information to the graphics subsystem.
- Animation, Behavior, and Physics modules with the Entity-Component System so that every entity (game object) can have components (e.g., Transform, Visual, Collider, Animation, Behavior) attached.
- That the Asset Management module feeds resources (assets, models, textures) into both the Graphics and Editor subsystems.

##### Architectural Patterns and Design Principles
- Modular design: each major area (graphics, physics, animation, etc.) is in its own directory and is loosely coupled with the rest of the engine.
- Use of the Entity-Component-System (ECS) architecture that decouples data (entities/components) from logic (systems such as collision, update, and rendering).
- Mention that the engine leverages Typescript’s strong typing and modularity; components are self-contained and well organized.
- That asynchronous and background processing (via web workers) is used to handle computationally intensive tasks (e.g., raytracing).

##### Putting It All Together
- On a separate branch, illustrate the “Editor Frontend” (linking it to the Core for scene management and configuration) along with “Platform-Specific Launchers” (Electron, Android, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    EngineCore["Engine Core & Modules\n(initialization, ECS, scene management)"]:::core
    Graphics["Graphics/Rendering Subsystem\n(WebGL based)"]:::subsystem
    Animation["Animation System"]:::subsystem
    Physics["Physics & Collision System"]:::subsystem
    Behavior["Behavior & Scripting"]:::subsystem
    Asset["Asset & Resource Management"]:::subsystem
    UI["UI System"]:::editor
    Input["Input System"]:::subsystem
    IO["IO & Serialization"]:::io
    Editor["Editor Frontend"]:::editor
    Launcher["Platform-Specific Launchers"]:::launcher
    Worker["Worker Threads (e.g., Raytracing)"]:::worker

    %% Relationships from Engine Core to subsystems
    EngineCore -->|"update"| Graphics
    EngineCore -->|"update"| Animation
    EngineCore -->|"update"| Physics
    EngineCore -->|"update"| Behavior
    EngineCore -->|"resource"| Asset
    EngineCore -->|"UI_events"| UI
    EngineCore -->|"input"| Input
    EngineCore -->|"IO_calls"| IO
    EngineCore -->|"scene_config"| Editor
    EngineCore -->|"launcher_invoke"| Launcher
    EngineCore -->|"offloads"| Worker

    %% Asset feeds into Graphics and Editor
    Asset -->|"supplies"| Graphics
    Asset -->|"supplies"| Editor

    %% Subgraph for Graphics Subsystems
    subgraph "Graphics Subsystems"
        GCamera["Camera"]:::subsystem
        GGeometry["Geometry"]:::subsystem
        GLighting["Lighting"]:::subsystem
        GShading["Shading"]:::subsystem
        GTexture["Texture"]:::subsystem
        GVolume["Volume"]:::subsystem
        GPostFX["PostFX"]:::subsystem
    end
    Graphics -->|"configures"| GCamera
    Graphics -->|"configures"| GGeometry
    Graphics -->|"configures"| GLighting
    Graphics -->|"configures"| GShading
    Graphics -->|"configures"| GTexture
    Graphics -->|"configures"| GVolume
    Graphics -->|"configures"| GPostFX

    %% Subgraph for Animation Components
    subgraph "Animation Components"
        A_IK["IK System"]:::subsystem
        A_Keys["Key Management"]:::subsystem
        A_Tracks["Animation Tracks"]:::subsystem
    end
    Animation -->|"manages"| A_IK
    Animation -->|"manages"| A_Keys
    Animation -->|"manages"| A_Tracks

    %% Subgraph for Behavior Components
    subgraph "Behavior Components"
        BConverters["Converters"]:::subsystem
        BOperators["Operators"]:::subsystem
    end
    Behavior -->|"comprises"| BConverters
    Behavior -->|"comprises"| BOperators

    %% Subgraph for Asset Subsystems
    subgraph "Asset Subsystems"
        AModel["Model Handling"]:::subsystem
    end
    Asset -->|"handles"| AModel

    %% Subgraph for IO Components
    subgraph "IO Components"
        IO_File["File I/O"]:::io
        IO_Network["Network Calls"]:::io
    end
    IO -->|"performs"| IO_File
    IO -->|"performs"| IO_Network

    %% Subgraph for Platform Launchers
    subgraph "Platform Launchers"
        L_Electron["Electron"]:::launcher
        L_Android["Android"]:::launcher
    end
    Launcher -->|"includes"| L_Electron
    Launcher -->|"includes"| L_Android

    %% Click Events
    click EngineCore "https://github.com/aminere/spider-engine/tree/master/src/core"
    click EngineCore "https://github.com/aminere/spider-engine/tree/master/src/common"
    click EngineCore "https://github.com/aminere/spider-engine/tree/master/src/serialization"

    click Graphics "https://github.com/aminere/spider-engine/tree/master/src/graphics"
    click GCamera "https://github.com/aminere/spider-engine/tree/master/src/graphics/camera"
    click GGeometry "https://github.com/aminere/spider-engine/tree/master/src/graphics/geometry"
    click GLighting "https://github.com/aminere/spider-engine/tree/master/src/graphics/lighting"
    click GShading "https://github.com/aminere/spider-engine/tree/master/src/graphics/shading"
    click GTexture "https://github.com/aminere/spider-engine/tree/master/src/graphics/texture"
    click GVolume "https://github.com/aminere/spider-engine/tree/master/src/graphics/volume"
    click GPostFX "https://github.com/aminere/spider-engine/tree/master/src/graphics/postfx"

    click Animation "https://github.com/aminere/spider-engine/tree/master/src/animation"
    click A_IK "https://github.com/aminere/spider-engine/tree/master/src/animation/ik"
    click A_Keys "https://github.com/aminere/spider-engine/tree/master/src/animation/keys"
    click A_Tracks "https://github.com/aminere/spider-engine/tree/master/src/animation/tracks"

    click Physics "https://github.com/aminere/spider-engine/tree/master/src/physics"
    click Physics "https://github.com/aminere/spider-engine/tree/master/src/collision"

    click Behavior "https://github.com/aminere/spider-engine/tree/master/src/behavior"
    click BConverters "https://github.com/aminere/spider-engine/tree/master/src/behavior/converters"
    click BOperators "https://github.com/aminere/spider-engine/tree/master/src/behavior/operators"

    click Asset "https://github.com/aminere/spider-engine/tree/master/src/assets"
    click AModel "https://github.com/aminere/spider-engine/tree/master/src/assets/model"

    click UI "https://github.com/aminere/spider-engine/tree/master/src/ui"
    click Input "https://github.com/aminere/spider-engine/tree/master/src/input"

    click IO "https://github.com/aminere/spider-engine/tree/master/src/io"
    click IO_Network "https://github.com/aminere/spider-engine/tree/master/src/network"

    click Editor "https://github.com/aminere/spider-engine/tree/master/src/editor"

    click Launcher "https://github.com/aminere/spider-engine/tree/master/launcher"
    click L_Electron "https://github.com/aminere/spider-engine/tree/master/launcher/electron"
    click L_Android "https://github.com/aminere/spider-engine/tree/master/launcher/android"

    click Worker "https://github.com/aminere/spider-engine/tree/master/workers/raytracer"

    %% Styles
    classDef core fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef subsystem fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef editor fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef launcher fill:#f08080,stroke:#333,stroke-width:2px;
    classDef worker fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef io fill:#ffa07a,stroke:#333,stroke-width:2px;
```
