# floooh/sokol-zig architecture

> Architecture diagram of the GitHub repository floooh/sokol-zig, 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/floooh/sokol-zig
- Repository: https://github.com/floooh/sokol-zig

## Overview

##### Main Components
- Build System & Dependency Management
- This includes the build files (build.zig and build.zig.zon) as well as GitHub workflows. The build system handles both native (platform-specific APIs such as GL, D3D11, Metal) and web (wasm32-emscripten) targets.
- Core Bindings Layer
- Located in the src/sokol directory, this layer provides auto-generated Zig bindings for the Sokol headers.
- Sokol C Library
- Found under src/sokol/c, this contains the Sokol C implementations (e.g., sokol_app.c, sokol_gfx.c, etc.) that the bindings depend on.
- This library is exposed via the build system as an artifact (sokol_clib) that projects can link with.
- Examples / Demo Applications
- The examples folder contains a host of sample Zig files (and associated GLSL shader files) that demonstrate how to use the bindings in practical scenarios.
- They illustrate different rendering techniques (like instancing, offscreen rendering, or debug text) and illustrate the cross-platform build strategy.
- Web Integration
- Specific components under src/sokol/web and web-related portions of the build scripts show integration with Emscripten for browser targets.
- Optional Dear ImGui Integration
- Although not fully bundled, the README explains how to include sokol_imgui support using an external library (cimgui) that the build scripts wire in optionally.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project is split clearly into build scripts, core bindings, C library implementations, and examples.
- Modularity and Reusability: The directory structure (src, examples, tools) supports adding more modules and examples without affecting the core architecture.

##### Technology and Frameworks
- Zig Language: Indicate that the project is written mostly in Zig, including its build scripts.
- C Language: Include that the underlying Sokol C implementations are linked in (via static libraries).
- Emscripten: For web targets, the integration uses Emscripten to do linking and runtime execution.
- Sokol Headers: The core function of the library is to offer bindings to Sokol headers, so clearly annotate that as the “primary dependency” or external interface.

## Diagram (Mermaid)

```mermaid
graph TD
    BS["Build System"]:::build
    CB["Core Bindings (Zig)"]:::bindings
    CL["Sokol C Library"]:::cLib
    EX["Examples / Demos"]:::examples
    WI["Web Integration"]:::web
    DI["Dear ImGui Integration"]:::imgui

    BS -->|"Build-Dependency"| CB
    BS -->|"Build-Dependency"| CL
    BS -->|"BuildRun"| EX
    BS -->|"WebBuild"| WI
    CB -->|"Uses"| CL
    CB -->|"OptionalIntegration"| DI

    classDef build fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef bindings fill:#B3E5FC,stroke:#000,stroke-width:2px;
    classDef cLib fill:#B2DFDB,stroke:#000,stroke-width:2px;
    classDef examples fill:#FFE0B2,stroke:#000,stroke-width:2px;
    classDef web fill:#C8E6C9,stroke:#000,stroke-width:2px;
    classDef imgui fill:#F8BBD0,stroke:#000,stroke-width:2px;
    
    click BS "https://github.com/floooh/sokol-zig/blob/master/build.zig"
    click BS "https://github.com/floooh/sokol-zig/blob/master/build.zig.zon"
    click BS "https://github.com/floooh/sokol-zig/tree/master/.github/workflows/"
    click CB "https://github.com/floooh/sokol-zig/tree/master/src/sokol/"
    click CL "https://github.com/floooh/sokol-zig/tree/master/src/sokol/c/"
    click EX "https://github.com/floooh/sokol-zig/tree/master/examples/"
    click WI "https://github.com/floooh/sokol-zig/tree/master/src/sokol/web/"
    click DI "https://github.com/floooh/sokol-zig/blob/master/src/sokol/imgui.zig"
    click DI "https://github.com/floooh/sokol-zig/blob/master/src/sokol/c/sokol_imgui.c"
    click DI "https://github.com/floooh/sokol-zig/blob/master/src/sokol/c/sokol_imgui.h"
```
