# supinepandora43/ultralightnet architecture

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

- Interactive diagram: https://gitdiagram.com/supinepandora43/ultralightnet
- Repository: https://github.com/supinepandora43/ultralightnet

## Overview

##### Project Type & Purpose
- UltralightNet is an open-source, multi-project .NET binding library for the native Ultralight HTML rendering engine.
- It exposes Ultralight’s core (AppCore, Core engine, GPU drivers, JavaScript) to C#/.NET, packages native binaries per platform, and provides sample apps (WPF, headless, GPU tests).

##### High-Level File Structure
- Root
- UltralightNet.sln – solution orchestrating all subprojects.
- /Examples – sample apps showing headless, AppCore, OpenGL/Vulkan/Veldrid test clients.
- /gpu – C++ helper shaders and managed GPU-driver projects (OpenGL, Vulkan, Veldrid) under gpu/libs.
- /src – main C# projects:
– UltralightNet (core wrapper)
– UltralightNet.AppCore (window & overlay abstractions)
– UltralightNet.Binaries (native .dll/.dylib packaging)
– UltralightNet.WPF, UltralightNet.Veldrid.SDL2 (UI integrations)
– Benchmarks, Tests, LibraryImportGenerator (automates P/Invoke code gen).
- /UltralightSharp – older C# bindings (legacy, can be omitted or shown as historical).
- CI, scripts (packbinaries.sh, regenerate.sh), config files.

##### Main Components
A. Native Ultralight Engine
- AppCore (libAppCore)
- Core rendering engine (libUltralight, libUltralightCore, libWebCore)
B. Managed Binding Layer
- LibraryImportGenerator → generates P/Invoke signatures & marshallers
- P/Invoke wrappers (UltralightNet.Platform, NativeContainer, Methods)
- Core .NET types (Session, View, Renderer, Bitmap, Overlay, Settings)
- JavaScript bindings (JSContext, JSValue, JSObject)
C. GPU Driver Abstractions
- GPUCommon (shared interfaces: CommandList, GpuState, Uniforms)
- Concrete drivers: OpenGLGPUDriver, VulkanGPUDriver, VeldridGPUDriver
D. Native Binaries Packaging
- UltralightNet.Binaries (runtime/*.dll/.dylib native libs per OS/arch)
- UltralightNet.AppCore.Binaries
E. UI Integrations & Examples
- UltralightNet.WPF → ULBrowser control
- UltralightNet.Veldrid.SDL2 → Veldrid + SDL2 host
- Headless & GPU test apps in /Examples
F. Test & Benchmark Projects
- UltralightNet.Test (xUnit tests validating wrappers)
- Benchmarks project

##### Relationships & Data Flow
- GPU Driver Abstractions ←→ Native Engine (engine issues GPU commands via driver callbacks)
- LibraryImportGenerator outputs code into Managed Binding Layer
- Native Binaries feed into runtime loader in Binaries projects
- UI Integrations consume Managed Binding Layer (e.g., WPF control calls Session, View APIs)
- Examples & Tests reference the integration and core projects

##### Architectural Patterns & Principles
- Layered architecture: UI → .NET API → P/Invoke layer → Native engine
- Dependency inversion: engine defines driver callbacks, concrete drivers plug in
- Code generation: LibraryImportGenerator automates low-level bindings
- Separation of concerns: packaging, core wrapper, platform abstraction, GPU drivers, UI hosts

##### Technologies & Frameworks
- C#/.NET 6.0+
- P/Invoke / NativeLibrary loader
- xUnit for tests, BenchmarkDotNet (if used)
- WPF (XAML) and Veldrid + SDL2 for UI demos
- C++ shaders for GPU examples

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Native Engine Layer
    subgraph "Native Engine" 
        direction TB
        AppCoreLib["libAppCore"]:::native
        CoreLibs["libUltralight*, libUltralightCore, libWebCore"]:::native
    end

    %% Build-Time Tools
    subgraph "Build-Time Tools"
        direction TB
        Generator["LibraryImportGenerator"]:::tools
    end

    %% Managed Binding Layer
    subgraph "Managed Binding Layer"
        direction TB
        PInvokeWrappers["P/Invoke Wrappers\n(Methods.cs, NativeContainer.cs, Platform)"]:::managed
        CoreTypes["Core .NET Types\n(Session, View, Renderer, Bitmap, Settings)"]:::managed
        JSBindings["JavaScript Bindings\n(JSContext, JSValue, JSObject)"]:::managed
    end

    %% GPU Driver Layer
    subgraph "GPU Driver Abstractions"
        direction TB
        GPUCommon["GPUCommon Interfaces"]:::gpu
        OpenGLDriver["OpenGLGPUDriver"]:::gpu
        VulkanDriver["VulkanGPUDriver"]:::gpu
        VeldridDriver["VeldridGPUDriver"]:::gpu
    end

    %% Packaging Layer
    subgraph "Native Binaries Packaging"
        direction TB
        BinariesCore["UltralightNet.Binaries"]:::packaging
        BinariesAppCore["UltralightNet.AppCore.Binaries"]:::packaging
    end

    %% UI & Examples Layer
    subgraph "UI Integrations & Examples"
        direction TB
        WPF["UltralightNet.WPF"]:::ui
        SDL2["UltralightNet.Veldrid.SDL2"]:::ui
        HeadlessExample["Headless & AppCore Examples"]:::ui
        GPUExamples["GPU Test Clients"]:::ui
        Tests["UltralightNet.Test"]:::ui
        Benchmarks["Benchmarks"]:::ui
    end

    %% Relationships
    Generator -.->|generates code| PInvokeWrappers
    PInvokeWrappers -->|P/Invoke calls| AppCoreLib
    PInvokeWrappers -->|P/Invoke calls| CoreLibs
    CoreTypes -->|C# API calls| PInvokeWrappers
    JSBindings -->|C# API calls| PInvokeWrappers
    GPUCommon <-->|implements callbacks| CoreLibs
    OpenGLDriver -->|driver plugin| GPUCommon
    VulkanDriver -->|driver plugin| GPUCommon
    VeldridDriver -->|driver plugin| GPUCommon
    CoreLibs -->|issues GPU commands| GPUCommon
    BinariesCore -->|packages native libs| CoreLibs
    BinariesCore -->|packages native libs| AppCoreLib
    BinariesAppCore -->|packages native libs| AppCoreLib
    WPF -->|uses| CoreTypes
    SDL2 -->|uses| CoreTypes
    HeadlessExample -->|references| CoreTypes
    GPUExamples -->|references| OpenGLDriver
    GPUExamples -->|references| VulkanDriver
    GPUExamples -->|references| VeldridDriver
    Tests -->|validates| PInvokeWrappers
    Benchmarks -->|benchmarks| CoreTypes

    %% Click Events
    click AppCoreLib "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.AppCore.Binaries/runtimes/**/native/libAppCore.*"
    click CoreLibs "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.Binaries/runtimes/**/native/libUltralight*.*"
    click Generator "https://github.com/supinepandora43/ultralightnet/tree/master/src/UltralightNet/LibraryImportGenerator"
    click PInvokeWrappers "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/Methods.cs"
    click PInvokeWrappers "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/NativeContainer.cs"
    click PInvokeWrappers "https://github.com/supinepandora43/ultralightnet/tree/master/src/UltralightNet/Platform"
    click CoreTypes "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/Session.cs"
    click CoreTypes "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/View.cs"
    click CoreTypes "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/Renderer.cs"
    click CoreTypes "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/ULBitmap.cs"
    click CoreTypes "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet/ULSettings.cs"
    click JSBindings "https://github.com/supinepandora43/ultralightnet/tree/master/src/UltralightNet/JavaScript"
    click GPUCommon "https://github.com/supinepandora43/ultralightnet/blob/master/gpu/libs/UltralightNet.GPUCommon"
    click OpenGLDriver "https://github.com/supinepandora43/ultralightnet/blob/master/gpu/libs/UltralightNet.OpenGL/OpenGLGPUDriver.cs"
    click VulkanDriver "https://github.com/supinepandora43/ultralightnet/blob/master/gpu/libs/UltralightNet.Vulkan/VulkanGPUDriver.cs"
    click VeldridDriver "https://github.com/supinepandora43/ultralightnet/blob/master/gpu/libs/UltralightNet.Veldrid/VeldridGPUDriver.cs"
    click BinariesCore "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.Binaries"
    click BinariesAppCore "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.AppCore.Binaries"
    click WPF "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.WPF"
    click SDL2 "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.Veldrid.SDL2"
    click HeadlessExample "https://github.com/supinepandora43/ultralightnet/tree/master/Examples/Headless/GettingStarted"
    click GPUExamples "https://github.com/supinepandora43/ultralightnet/blob/master/Examples/gpu/UltralightNet.OpenGL.TestApp"
    click Tests "https://github.com/supinepandora43/ultralightnet/blob/master/src/UltralightNet.Test"
    click Benchmarks "https://github.com/supinepandora43/ultralightnet/tree/master/src/Benchmarks"

    %% Styles
    classDef native fill:#d3d3d3,stroke:#999
    classDef managed fill:#bbdefb,stroke:#1e88e5
    classDef gpu fill:#c8e6c9,stroke:#388e3c
    classDef packaging fill:#ffe0b2,stroke:#ef6c00
    classDef ui fill:#e1bee7,stroke:#8e24aa
    classDef tools fill:#f8bbd0,stroke:#d81b60,stroke-dasharray: 5 5
```
