# bmaow/levikno architecture

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

- Interactive diagram: https://gitdiagram.com/bmaow/levikno
- Repository: https://github.com/bmaow/levikno

## Overview

##### Project Type and Purpose
- Levikno is a native C++ graphics library aimed at simplifying Vulkan and OpenGL usage for game and graphics application development. It exposes a single context‐based API (lvn::createContext, lvn::terminateContext) and supports multiple backends (OpenGL, Vulkan) and window APIs (GLFW).
- Rather than a server/client or full‐stack app, this is a library with examples demonstrating rendering, resource loading, and window management.

##### File Structure Analysis
- Top‐level:
- CMakeLists.txt, src/, include/, examples/, docs/ – indicates a library build using CMake, with public headers in include/, sources in src/, and sample apps in examples/.
- external/ – vendored third‐party libs (GLFW, GLAD, FreeType, stb, Vulkan SDK, ENet, etc.).
- src/api/ – the core abstraction layers:
- graphics/opengl and graphics/vulkan backends
- window/glfw backend
- loaders/gltf, loaders/obj
- src/levikno.cpp, lvn_renderer.cpp – glue code and entry points for context management and rendering.
- examples/ – standalone executables linking against the library to demonstrate usage.

##### Key Architecture Insights from README
- Two orthogonal abstraction axes:
a. Window API (currently GLFW)
b. Graphics API (OpenGL or Vulkan)
- Plugin‐style backends chosen at runtime via LvnContextCreateInfo.
- Asset loaders and utility modules provide functionality for models, shaders, audio, etc.

##### Main Components
A. Application Layer
- Example Executables – user code calling the public API.
B. Public API / Facade
- lvn::createContext / terminate
- Context object, command submission, swapchain management.
C. Abstraction Layers
- WindowAPI module
- GraphicsAPI module
- AssetLoader module
D. Backend Implementations
- GLFW (windowing)
- OpenGL backend
- Vulkan backend
- GLTF/OBJ loaders
E. External Dependencies
- GLFW, GLAD, Vulkan SDK, glslang, FreeType, stb_image, miniaudio, ENet, etc.
F. Platform / OS / GPU Driver

##### Relationships & Data Flow
- Example App → Public API → Context
- Context uses WindowAPI to create window & input callbacks → GLFW → OS/Platform
- Context uses GraphicsAPI abstraction → chosen backend (OpenGL or Vulkan) → GPU driver
- AssetLoader invoked by user code or internally to load models/shaders → uses GLTF/OBJ loader modules → std::filesystem or tinygltf
- Optional: networking via ENet, text rendering via FreeType, audio via miniaudio (shown as optional integration points).

##### Architectural Patterns and Design Principles
- Facade Pattern: single entry point simplifies complex Vulkan/OpenGL setup.
- Strategy/Plugin Pattern: interchangeable backends selected at runtime for windowing and graphics.
- Modular Structure: clear separation of concerns among window, graphics, loaders, and external libs.

– WindowAPI Abstraction
– GraphicsAPI Abstraction
– AssetLoader
– GLFW → OS/Platform
– OpenGL Backend → GLAD → GPU Driver
– Vulkan Backend → Vulkan SDK / glslang → GPU Driver
– GLTF Loader, OBJ Loader → std lib
f. At the bottom, show “OS / GPU Driver”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    ExampleApps["Example Applications"]:::app
    click ExampleApps "https://github.com/bmaow/levikno/blob/main/examples/simpleTriangle.cpp"

    %% Core Facade
    PublicAPI["Public API / Facade<br/>(lvn::createContext, terminateContext)"]:::core
    click PublicAPI "https://github.com/bmaow/levikno/blob/main/include/levikno/levikno.h"

    %% Abstractions Layer
    subgraph "Abstractions"
        direction TB
        WindowAbst["WindowAPI Abstraction"]:::abstraction
        click WindowAbst "https://github.com/bmaow/levikno/blob/main/src/api/window/glfw/lvn_glfw.h"
        GraphicsAbst["GraphicsAPI Abstraction"]:::abstraction
        AssetLoader["AssetLoader Abstraction"]:::abstraction
        click AssetLoader "https://github.com/bmaow/levikno/blob/main/src/api/loaders/lvn_loaders.h"
    end

    %% Window Backend
    GLFW["GLFW Backend"]:::backend
    click GLFW "https://github.com/bmaow/levikno/blob/main/src/api/window/glfw/lvn_glfw.cpp"

    %% Graphics Backends
    OpenGL["OpenGL Backend"]:::backend
    click OpenGL "https://github.com/bmaow/levikno/blob/main/src/api/graphics/opengl/lvn_opengl.h"
    Vulkan["Vulkan Backend"]:::backend
    click Vulkan "https://github.com/bmaow/levikno/blob/main/src/api/graphics/vulkan/lvn_vulkan.h"

    %% Graphics Backend Helpers
    GLAD["GLAD"]:::external
    click GLAD "https://github.com/bmaow/levikno/tree/main/src/external/glad/"
    VSDK["Vulkan SDK / glslang"]:::external
    click VSDK "https://github.com/bmaow/levikno/tree/main/src/external/vulkan/"
    GPU["GPU Driver"]:::external

    %% Asset Loaders
    GLTF["GLTF Loader"]:::backend
    click GLTF "https://github.com/bmaow/levikno/blob/main/src/api/loaders/lvn_loader_gltf.cpp"
    OBJ["OBJ Loader"]:::backend
    click OBJ "https://github.com/bmaow/levikno/blob/main/src/api/loaders/lvn_loader_obj.cpp"
    STD["std::filesystem / tinygltf"]:::external

    %% Other External Dependencies
    FreeType["FreeType"]:::external
    click FreeType "https://github.com/bmaow/levikno/tree/main/src/external/freetype/"
    STB["stb_*"]:::external
    click STB "https://github.com/bmaow/levikno/tree/main/src/external/stb_*"
    ENet["ENet"]:::external
    click ENet "https://github.com/bmaow/levikno/tree/main/src/external/enet/"
    MiniAudio["miniaudio"]:::external
    click MiniAudio "https://github.com/bmaow/levikno/blob/main/src/external/miniaudio.c"

    %% Platform
    OS["OS / Platform"]:::external

    %% Connections
    ExampleApps -->|"uses"| PublicAPI
    PublicAPI -->|"window calls"| WindowAbst
    PublicAPI -->|"graphics calls"| GraphicsAbst
    PublicAPI -->|"asset loading"| AssetLoader

    WindowAbst -->|"implements"| GLFW
    GLFW -->|"calls into"| OS

    GraphicsAbst -->|"uses"| OpenGL
    GraphicsAbst -->|"uses"| Vulkan

    OpenGL -->|"loads functions"| GLAD
    Vulkan -->|"uses SDK"| VSDK

    GLAD -->|"driver interface"| GPU
    VSDK -->|"driver interface"| GPU

    AssetLoader -->|"loads format"| GLTF
    AssetLoader -->|"loads format"| OBJ

    GLTF -->|"file I/O"| STD
    OBJ -->|"file I/O"| STD

    AssetLoader -->|"optional text"| FreeType
    AssetLoader -->|"optional images"| STB
    AssetLoader -->|"optional audio"| MiniAudio
    AssetLoader -->|"optional networking"| ENet

    %% Styles
    classDef app fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#bbf,stroke:#333,stroke-width:2px
    classDef abstraction fill:#ffeb99,stroke:#333,stroke-width:2px
    classDef backend fill:#b3e5fc,stroke:#333,stroke-width:2px
    classDef external fill:#c8e6c9,stroke:#333,stroke-width:2px
```
