# sardonyx-forks/commonlibvr architecture

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

- Interactive diagram: https://gitdiagram.com/sardonyx-forks/commonlibvr
- Repository: https://github.com/sardonyx-forks/commonlibvr

## Overview

This project is a C++ library designed to support Skyrim plugin development by providing reverse‐engineered wrappers for Skyrim’s internal classes and systems. It is essentially an evolution of CommonLibSSE (for Skyrim Special Edition) that now also supports Skyrim VR. It serves as a static dependency for SKSE and SKSEVR plugins, abstracting various internal details (memory addresses, game interfaces, etc.) via its “RE” (reverse engineered) components. In addition, the project includes a Flash/AS2 GUI component and a set of build system files (using CMake, vcpkg, and related scripts) to manage presets for both SSE and VR builds.

##### Main Components
- Build & Configuration Subsystem:
– CMakeLists.txt, CMake presets (vs2022-windows-vcpkg and vs2022-windows-vcpkg-vr), xmake files, and scripts in the “scripts” folder.
– Vcpkg integration and other configuration files (.clang-format, .gitignore, etc.)
- Core Library Modules:
– “include” directory which houses extensive header files (especially under include/RE and its subdirectories) defining reverse-engineered SKSE interfaces, game object wrappers, and utility functions.
– “src” directory which implements the library; note the organization by modules like RE/A, RE/B, … RE/Z, etc.
- Graphical/User Interface Components:
– The “Flash” folder, particularly the Flash/AS2/CLIK directory which contains ActionScript files for GUI controls (e.g., Button, Dialog, TextInput).
- External Dependencies and Integration:
– External submodules like “extern/openvr” (for VR-specific functionality).
– Dependencies on third-party libraries such as spdlog, fmt, and binary_io.
- SKSE/SKSEVR Integration Layer:
– Folders like “SKSE” (and related files) are used to interface with the runtime components in Skyrim.
– Also, include the REL, REX, and other system interface wrappers that abstract OS-level or game-engine level functionality.

##### Relationships and Flow
- The Build & Configuration subsystem sits at the top, controlling how all modules are compiled and linked.
- External dependencies (vcpkg, spdlog, fmt, OpenVR, etc.) are injected during the build configuration phase.
- The Core Library (header “include” and their corresponding “src” implementations) forms the heart of the system. Modules under “RE” are organized (for example, RE/A, RE/B,… RE/T, etc.) and interact to expose game functionalities.
- The Flash UI components are an auxiliary module that interacts with the core via specific interfaces (possibly exposing visual elements to in-game plugins).
- Finally, the library exposes abstraction layers that integrate with SKSE and SKSEVR. In the build flow, there are separate presets that compile everything for either Skyrim SE or Skyrim VR.

##### Architectural Patterns
- Modularity: The project is decomposed into a number of well-organized modules (by reverse-engineered game subsystems, UI components, and external integration).
- Layering: There are clear layers from low-level interfacing (RE, REL, REX, SKSE) up to higher-level UI (Flash/AS2) and build configuration.
- Dependency Injection: External libraries and configuration files are managed centrally through CMake and vcpkg, ensuring that dependencies are injected into the build processes.
- Abstraction: The reverse-engineered “RE” modules act as an abstraction layer that hides the internal complexities of Skyrim’s engine from the plugin developers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Configuration Subsystem
    subgraph "Build & Configuration Subsystem"
        b1("CMakeLists.txt"):::build
        b2("CMakePresets.json"):::build
        b3("cmake/config.cmake.in"):::build
        b4("scripts/cmake_generate.py"):::build
        b5("xmake.lua"):::build
        b6("xmake-rules.lua"):::build
        b7("vcpkg.json"):::build
    end

    %% Core Library Modules
    subgraph "Core Library Modules"
        c1("include/RE"):::core
        c2("src/RE"):::core
    end

    %% Graphical/User Interface Components
    subgraph "Graphical/UI Components"
        u1("Flash/AS2/CLIK"):::ui
    end

    %% External Dependencies and Integration
    subgraph "External Dependencies"
        e1("extern/openvr"):::external
    end

    %% SKSE/SKSEVR Integration Layer
    subgraph "SKSE/SKSEVR Integration"
        s1("include/SKSE"):::skse
        s2("src/SKSE"):::skse
    end

    %% REL/REX Abstraction Layers
    subgraph "REL/REX Abstraction Layers"
        r1("include/REL"):::rex
        r2("include/REX"):::rex
        r3("src/REL"):::rex
        r4("src/REX"):::rex
    end

    %% Connections from Build System to other components
    b1 -->|"builds"| c1
    b1 -->|"builds"| u1
    b1 -->|"builds"| s1
    b1 -->|"injects"| e1

    %% Connections from Core Library Modules to other layers
    c1 -->|"exposes"| s1
    c2 -->|"exposes"| s2
    c1 -->|"abstracts"| r1
    c2 -->|"abstracts"| r3
    c1 -->|"abstracts"| r2
    c2 -->|"abstracts"| r4

    %% Interaction between UI and Core Library
    u1 -->|"interfaces"| c1

    %% Styles
    classDef build fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef core fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef skse fill:#B0C4DE,stroke:#000,stroke-width:2px;
    classDef rex fill:#E6E6FA,stroke:#000,stroke-width:2px;

    %% Click Events for Build & Configuration Subsystem
    click b1 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/CMakeLists.txt"
    click b2 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/CMakePresets.json"
    click b3 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/cmake/config.cmake.in"
    click b4 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/scripts/cmake_generate.py"
    click b5 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/xmake.lua"
    click b6 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/xmake-rules.lua"
    click b7 "https://github.com/sardonyx-forks/commonlibvr/blob/vr/vcpkg.json"

    %% Click Events for Core Library Modules
    click c1 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/include/RE"
    click c2 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/src/RE"

    %% Click Events for Graphical/UI Components
    click u1 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/Flash/AS2/CLIK"

    %% Click Events for External Dependencies
    click e1 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/extern/openvr"

    %% Click Events for SKSE/SKSEVR Integration Layer
    click s1 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/include/SKSE"
    click s2 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/src/SKSE"

    %% Click Events for REL/REX Abstraction Layers
    click r1 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/include/REL"
    click r2 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/include/REX"
    click r3 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/src/REL"
    click r4 "https://github.com/sardonyx-forks/commonlibvr/tree/vr/src/REX"
```
