# glassesneo/saohime architecture

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

- Interactive diagram: https://gitdiagram.com/glassesneo/saohime
- Repository: https://github.com/glassesneo/saohime

## Overview

##### Main Components
- Core Engine: Include the Application instance (src/saohime/core/application.nim), core types (saohime_types.nim), exceptions, and helper modules (like sdl2_helpers.nim). This forms the heart of the engine.
- Plugin System: Show the extensible plugin architecture (present in src/saohime/plugins) which hosts dedicated plugins like asset, camera, event, graphics, render, sdl2, times, transform, and window. Also note the default plugins loaded from default_plugins.nim.
- Entity Component System (ECS): Represent the underlying ECS integration (with ecslib) that ties into the creation of entities, the attaching of components, and the registration of systems.
- System / Game Loop: Indicate the processing flow for events, updates, rendering, and system execution (e.g., as shown by the example usage in the README where multiple systems such as pollEvent, randomCircles, and increaseRadius are registered).
- External Dependencies: Identify external technologies such as SDL, SDL_image, SDL_ttf for rendering, as well as OpenAL (via slappy) for audio, and integrations like Lua through spellua.
- Example Applications: Optionally include the sample projects (example_app and examples) to illustrate practical usage of the engine.

##### Relationships and Data Flow
- “ECS/World” which is responsible for managing entities and components. This block should be linked with the systems registered by both the core engine and the plugins.

##### Adjustments Specific to This Project
- Since this is a full-stack engine that offers both core functionality and an extensible plugin system, emphasize the interplay between the central ECS loop and the various plugin modules.
- A block for “Example Applications” to illustrate how the engine is used practically. This could be shown as usage examples that receive input from the outside (e.g., server.py, example_app) and display how systems (like pollEvent, randomCircles) are utilized.
- Unique elements shown in the file tree such as “config.nims” or build/deployment scripts (.nimble file), noting how they support the build and deployment process rather than runtime behavior.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Engine
    subgraph "Core Engine"
        APP("Application"):::core
        CT("Core Types"):::core
        SDL_HELP("SDL2 Helpers"):::core
        ECS("ECS/World"):::core
        PM("Plugin Manager"):::core
    end

    %% Plugins
    subgraph "Plugins"
        ASSET("Asset Plugin"):::plugin
        CAMERA("Camera Plugin"):::plugin
        EVENT("Event Plugin"):::plugin
        GRAPHICS("Graphics Plugin"):::plugin
        RENDER("Render Plugin"):::plugin
        SDL2P("SDL2 Plugin"):::plugin
        TIMES("Times Plugin"):::plugin
        TRANSFORM("Transform Plugin"):::plugin
        WINDOW("Window Plugin"):::plugin
        HIERARCHY("Hierarchy Plugin"):::plugin
    end

    %% External Dependencies
    subgraph "External Dependencies"
        SDL("SDL2"):::external
        SDLIMG("SDL_image"):::external
        SDLTTF("SDL_ttf"):::external
        OPENAL("OpenAL (slappy)"):::external
        LUA("Lua Integration"):::external
        ECSLIB("ecslib"):::external
    end

    %% Example Applications
    subgraph "Example Applications"
        EXAPP("Example App"):::example
        EXAMPLES("Examples"):::example
    end

    %% Connections
    APP -->|"loads"| PM
    PM -->|"loads"| ASSET
    PM -->|"loads"| CAMERA
    PM -->|"loads"| EVENT
    PM -->|"loads"| GRAPHICS
    PM -->|"loads"| RENDER
    PM -->|"loads"| SDL2P
    PM -->|"loads"| TIMES
    PM -->|"loads"| TRANSFORM
    PM -->|"loads"| WINDOW
    PM -->|"loads"| HIERARCHY

    APP -->|"registers"| ECS
    ASSET -->|"registers_systems"| ECS
    CAMERA -->|"registers_systems"| ECS
    EVENT -->|"registers_systems"| ECS
    GRAPHICS -->|"registers_systems"| ECS
    RENDER -->|"registers_systems"| ECS
    SDL2P -->|"registers_systems"| ECS
    TIMES -->|"registers_systems"| ECS
    TRANSFORM -->|"registers_systems"| ECS
    WINDOW -->|"registers_systems"| ECS
    HIERARCHY -->|"registers_systems"| ECS

    SDL ---|"provides"| SDL_HELP
    SDLIMG ---|"provides"| SDL2P
    SDLTTF ---|"provides"| SDL2P
    OPENAL ---|"provides"| RENDER
    LUA ---|"integrates_with"| APP
    ECSLIB -.-> ECS

    EXAPP -->|"runs_on"| APP
    EXAMPLES -->|"runs_on"| APP

    ECS -->|"data_flow"| RENDER

    %% Click Events
    click APP "https://github.com/glassesneo/saohime/blob/develop/src/saohime/core/application.nim"
    click CT "https://github.com/glassesneo/saohime/blob/develop/src/saohime/core/saohime_types.nim"
    click SDL_HELP "https://github.com/glassesneo/saohime/blob/develop/src/saohime/core/sdl2_helpers.nim"
    click PM "https://github.com/glassesneo/saohime/blob/develop/src/saohime/default_plugins.nim"
    click ASSET "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/asset"
    click CAMERA "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/camera"
    click EVENT "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/event"
    click GRAPHICS "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/graphics"
    click RENDER "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/render"
    click SDL2P "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/sdl2"
    click TIMES "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/times"
    click TRANSFORM "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/transform"
    click WINDOW "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/window"
    click HIERARCHY "https://github.com/glassesneo/saohime/tree/develop/src/saohime/plugins/hierarchy"
    click EXAPP "https://github.com/glassesneo/saohime/tree/develop/example_app"
    click EXAMPLES "https://github.com/glassesneo/saohime/tree/develop/examples"

    %% Styles
    classDef core fill:#a8dadc,stroke:#457b9d,stroke-width:2px;
    classDef plugin fill:#ffb703,stroke:#fb8500,stroke-width:2px;
    classDef external fill:#8ecae6,stroke:#219ebc,stroke-width:2px;
    classDef example fill:#caffbf,stroke:#bdb2ff,stroke-width:2px;
```
