# floooh/sokol architecture

> Architecture diagram of the GitHub repository floooh/sokol, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/floooh/sokol
- Repository: https://github.com/floooh/sokol

## Overview

##### Main Components

a) Core Libraries Layer:
- sokol_gfx.h (3D-API wrapper)
- sokol_app.h (application framework)
- sokol_time.h (time measurement)
- sokol_audio.h (audio playback)
- sokol_fetch.h (data streaming)
- sokol_args.h (argument parsing)
- sokol_log.h (logging system)

b) Utility Libraries Layer:
- UI-related (sokol_imgui.h, sokol_nuklear.h)
- Graphics utilities (sokol_gl.h, sokol_shape.h, sokol_color.h)
- Debug tools (sokol_debugtext.h, sokol_gfx_imgui.h)
- Memory tracking (sokol_memtrack.h)
- Font handling (sokol_fontstash.h)
- Animation (sokol_spine.h)

c) Platform Support Layer:
- Windows (Win32)
- macOS/iOS (Metal)
- Linux (X11)
- Web (WebAssembly)
- Android
- UWP

d) Graphics Backend Layer:
- OpenGL/GLES3/WebGL2
- Metal
- Direct3D 11
- WebGPU

##### Relationships and Data Flow

**[Platform Layer] → [Core Libraries] ← [Utility Libraries]**
- ↓
- [Graphics Backend Layer]

**┌─ Platform Layer ─────────────────────────┐**
- Win32 │ MacOS │ Linux │ Web │ Android   │
- ┬─────────────────────────┘
- ↓
**┌─ Core Libraries ─────────────────────────┐**
- ┌─────────┐ ┌─────────┐ ┌────────────┐  │
- sokol_gfx│ │sokol_app│ │sokol_audio │  │
- ┘ └─────────┘ └────────────┘  │
- ┌─────────┐ ┌─────────┐ ┌────────────┐  │
- sokol_time│ │sokol_log│ │sokol_fetch│  │
- ┘ └─────────┘ └────────────┘  │
- ┬─────────────────────┘
- ↓
**┌─ Graphics Backends ────────────────────┐**
- OpenGL │ Metal │ D3D11 │ WebGPU      │
- ┘

##### Additional Elements

- Version/compatibility information
- Binding support for different languages
- Test coverage paths

##### Implementation Notes

- Clear separation between core and utility components
- Minimal dependencies between components
- Build and test workflow connections

Remember to maintain a balance between detail and clarity, as Sokol's strength lies in its simplicity and modularity while still providing comprehensive functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef utility fill:#2ecc71,stroke:#27ae60,color:white
    classDef platform fill:#e67e22,stroke:#d35400,color:white
    classDef graphics fill:#9b59b6,stroke:#8e44ad,color:white
    classDef binding fill:#f1c40f,stroke:#f39c12,color:black
    classDef testing fill:#e74c3c,stroke:#c0392b,color:white

    subgraph PlatformLayer["Platform Support Layer"]
        Win["Windows (Win32)"]:::platform
        Mac["macOS/iOS (Metal)"]:::platform
        Linux["Linux (X11)"]:::platform
        Web["Web (WASM)"]:::platform
        Android["Android"]:::platform
        UWP["UWP"]:::platform
    end

    subgraph CoreLibs["Core Libraries"]
        GFX["sokol_gfx.h"]:::core
        APP["sokol_app.h"]:::core
        TIME["sokol_time.h"]:::core
        AUDIO["sokol_audio.h"]:::core
        FETCH["sokol_fetch.h"]:::core
        ARGS["sokol_args.h"]:::core
        LOG["sokol_log.h"]:::core
    end

    subgraph UtilLibs["Utility Libraries"]
        IMGUI["sokol_imgui.h"]:::utility
        NUKLEAR["sokol_nuklear.h"]:::utility
        GL["sokol_gl.h"]:::utility
        SHAPE["sokol_shape.h"]:::utility
        COLOR["sokol_color.h"]:::utility
        DEBUGTEXT["sokol_debugtext.h"]:::utility
        GFXDBG["sokol_gfx_imgui.h"]:::utility
        MEMTRACK["sokol_memtrack.h"]:::utility
        FONT["sokol_fontstash.h"]:::utility
        SPINE["sokol_spine.h"]:::utility
    end

    subgraph GraphicsBackend["Graphics Backend Layer"]
        OPENGL["OpenGL/GLES3/WebGL2"]:::graphics
        METAL["Metal"]:::graphics
        D3D11["Direct3D 11"]:::graphics
        WEBGPU["WebGPU"]:::graphics
    end

    subgraph BindGen["Binding Generation"]
        GENALL["gen_all.py"]:::binding
        GENRUST["gen_rust.py"]:::binding
        GENZIG["gen_zig.py"]:::binding
        GEND["gen_d.py"]:::binding
        GENNIM["gen_nim.py"]:::binding
        GENODIN["gen_odin.py"]:::binding
        GENJAI["gen_jai.py"]:::binding
    end

    subgraph Testing["Testing Infrastructure"]
        COMPILE["Compilation Tests"]:::testing
        FUNCTIONAL["Functional Tests"]:::testing
        TESTWIN["Windows Tests"]:::testing
        TESTLINUX["Linux Tests"]:::testing
        TESTMAC["macOS Tests"]:::testing
    end

    %% Relationships
    PlatformLayer --> CoreLibs
    CoreLibs --> GraphicsBackend
    UtilLibs --> CoreLibs
    BindGen --> CoreLibs
    Testing --> CoreLibs

    %% Click events for component mapping
    click GFX "https://github.com/floooh/sokol/blob/master/sokol_gfx.h"
    click APP "https://github.com/floooh/sokol/blob/master/sokol_app.h"
    click TIME "https://github.com/floooh/sokol/blob/master/sokol_time.h"
    click AUDIO "https://github.com/floooh/sokol/blob/master/sokol_audio.h"
    click FETCH "https://github.com/floooh/sokol/blob/master/sokol_fetch.h"
    click ARGS "https://github.com/floooh/sokol/blob/master/sokol_args.h"
    click LOG "https://github.com/floooh/sokol/blob/master/sokol_log.h"
    
    click IMGUI "https://github.com/floooh/sokol/blob/master/util/sokol_imgui.h"
    click NUKLEAR "https://github.com/floooh/sokol/blob/master/util/sokol_nuklear.h"
    click GL "https://github.com/floooh/sokol/blob/master/util/sokol_gl.h"
    click SHAPE "https://github.com/floooh/sokol/blob/master/util/sokol_shape.h"
    click COLOR "https://github.com/floooh/sokol/blob/master/util/sokol_color.h"
    click DEBUGTEXT "https://github.com/floooh/sokol/blob/master/util/sokol_debugtext.h"
    click GFXDBG "https://github.com/floooh/sokol/blob/master/util/sokol_gfx_imgui.h"
    click MEMTRACK "https://github.com/floooh/sokol/blob/master/util/sokol_memtrack.h"
    click FONT "https://github.com/floooh/sokol/blob/master/util/sokol_fontstash.h"
    click SPINE "https://github.com/floooh/sokol/blob/master/util/sokol_spine.h"
    
    click GENALL "https://github.com/floooh/sokol/blob/master/bindgen/gen_all.py"
    click GENRUST "https://github.com/floooh/sokol/blob/master/bindgen/gen_rust.py"
    click GENZIG "https://github.com/floooh/sokol/blob/master/bindgen/gen_zig.py"
    click GEND "https://github.com/floooh/sokol/blob/master/bindgen/gen_d.py"
    click GENNIM "https://github.com/floooh/sokol/blob/master/bindgen/gen_nim.py"
    click GENODIN "https://github.com/floooh/sokol/blob/master/bindgen/gen_odin.py"
    click GENJAI "https://github.com/floooh/sokol/blob/master/bindgen/gen_jai.py"
    
    click COMPILE "https://github.com/floooh/sokol/tree/master/tests/compile"
    click FUNCTIONAL "https://github.com/floooh/sokol/tree/master/tests/functional"
    click TESTWIN "https://github.com/floooh/sokol/blob/master/tests/test_win.cmd"
    click TESTLINUX "https://github.com/floooh/sokol/blob/master/tests/test_linux.sh"
    click TESTMAC "https://github.com/floooh/sokol/blob/master/tests/test_macos.sh"
```
