# nitload-nsi/stgsharp architecture

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

- Interactive diagram: https://gitdiagram.com/nitload-nsi/stgsharp
- Repository: https://github.com/nitload-nsi/stgsharp

## Overview

##### Project type and purpose
- Stg# is a multi‐module, C#-based 2D/3D STG (shoot ’em up) game engine built on top of OpenGL/GLFW.
- It provides:
- A high-efficiency math library
- An MVVM windowing framework (C# GUI)
- An EXPRESS-language script compiler/interpreter
- Native C helpers (vector math acceleration)
- A resource manager and model loader (STEP files)

##### File structure
Top-level solution: StgSharp.sln
Key projects / directories:
- StgSharp.Common – core data structures, math, geometry, graphics abstractions (OpenGL + Vulkan stubs), threading, timing, MVVM, pipeline nodes, STG gameplay entities.
- StgSharp – the main engine project that brings together Common modules, resource management, initialization, application bootstrap.
- StgSharpGraphic – high-level OpenGL wrappers, shaders, textures, framebuffers.
- StgSharp.C – native C code for high-performance vector/matrix operations, image loading (stb_image), OpenGL extension loading, GLFW bindings.
- StgSharp.Script – EXPRESS language lexer, parser, AST, semantic analyzer, code generator and runtime integration.
- StgSharp.Model – STEP file parser, syntax/analyzer, data model for CAD-style geometry definitions.
- StgSharp.Generator (and StgSgharp.Generator) – source-generation utilities for EXP schema or blueprint nodes.
- StgSharp.TerminalDialogue – a sample/CLI program demonstrating the terminal-based UI.
- .vs folders & configuration – IDE build/cache.

##### README for additional insights
- StgSharp is layered:
1. Core common libraries (math, geometry, threading).
2. Graphics abstractions (OpenGL/Vulkan pipelines via StgSharpGraphic).
3. Native performance helpers (StgSharp.C).
4. High-level engine & resource manager (StgSharp).
5. Script support (StgSharp.Script + Generator).
6. Model parsing (StgSharp.Model).
- Uses GLFW for cross-platform viewport & input.

##### Essential architectural elements to capture
– Separation of Common lib vs. Engine vs. Graphics vs. Native C vs. Scripting vs. Model
– MVVM → Engine integration
– Engine → OpenGL/GLFW call path
– Runtime SCRIPT compile & execution path
– Source generation path (Generator → Script → Engine)
– External dependencies

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["MVVM Windowing Framework"]:::presentation
        CLI["Terminal UI Demo"]:::presentation
    end

    %% Core Layer
    subgraph "Core Layer"
        Engine["Engine Core"]:::core
        Common["Common Library"]:::core
    end

    %% Graphics Layer
    subgraph "Graphics Abstraction Layer"
        Graphic["Graphics Abstraction"]:::graphics
    end

    %% Native Performance Layer
    subgraph "Native Performance Layer"
        Native["Native Performance"]:::native
    end

    %% Scripting Layer
    subgraph "Scripting Layer"
        Script["Scripting Engine"]:::scripting
        Gen1["Script Source Generator"]:::scripting
        Gen2["Alt Generator"]:::scripting
    end

    %% Model Loader Layer
    subgraph "Model Loader Layer"
        Model["Model Loader"]:::model
    end

    %% External Services
    subgraph "External Services"
        OpenGL["OpenGL"]:::external
        GLFW["GLFW"]:::external
        stb["stb_image"]:::external
    end

    %% Relationships
    UI -->|DataBinding| Engine
    CLI -->|Uses| Engine
    Engine -->|Uses| Common
    Common -->|Provides Types| Engine
    Engine -->|Draw API| Graphic
    Graphic -->|P/Invoke| Native
    Native -->|GL Calls| OpenGL
    Native -->|Window/Input| GLFW
    Native -->|Image Loading| stb
    Engine -->|Load/Compile Scripts| Script
    Script -->|SourceGen| Gen1
    Script -->|SourceGen| Gen2
    Gen1 -->|Generates AST| Script
    Gen2 -->|Generates AST| Script
    Script -->|Loads Models| Model
    Model -->|Uses Geometry Types| Common

    %% Click Events
    click Common "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.Common/"
    click UI "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.Common/MVVM/"
    click CLI "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.TerminalDialogue/"
    click Graphic "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharpGraphic/"
    click Native "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.C/"
    click Script "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.Script/"
    click Gen1 "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.Generator/SourceGenerator/"
    click Gen2 "https://github.com/nitload-nsi/stgsharp/tree/main/StgSgharp.Generator/SourceGenerator/"
    click Model "https://github.com/nitload-nsi/stgsharp/tree/main/StgSharp.Model/STEP/"

    %% Styles
    classDef presentation fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1
    classDef core fill:#C8E6C9,stroke:#388E3C,color:#1B5E20
    classDef graphics fill:#D1C4E9,stroke:#8E24AA,color:#4A148C
    classDef native fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef scripting fill:#E1BEE7,stroke:#AB47BC,color:#6A1B9A
    classDef model fill:#B2DFDB,stroke:#009688,color:#004D40
    classDef external fill:#ECEFF1,stroke:#90A4AE,color:#37474F
```
