# rakly3/ofs architecture

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

- Interactive diagram: https://gitdiagram.com/rakly3/ofs
- Repository: https://github.com/rakly3/ofs

## Overview

##### Main Components

A. Core Application Layer:
- Main Application (OpenFunscripter.cpp)
- Project Management (OFS_Project)
- State Management System
- Event System

B. Graphics & UI Layer:
- OpenGL Rendering System
- ImGui Integration
- Video Player Interface
- Timeline Components
- Custom UI Widgets

C. Scripting & Extension Layer:
- Lua Scripting Engine
- WebSocket API
- Core Extensions
- API Interfaces

D. Media Processing:
- MPV Video Player Integration
- Waveform Generation
- Video Preview System

##### Component Relationships

**[User Interface Layer]**
- ↕
**[Core Application Layer]**
- ↕
**[Media Processing Layer] ←→ [Scripting Layer]**
- ↕
**[System Integration Layer]**

##### Specific Implementation Details

- Blue: Core application components (OFS-lib)
- Green: UI components (src/UI)
- Yellow: Media processing (videoplayer/)
- Purple: Scripting & API components (lua/, api/)
- Gray: External dependencies (lib/)

##### Key Architectural Patterns to Highlight

A. State Management:
- State system (OFS-lib/state) managing different application states
- State transitions and data flow

B. Event System:
- Event-driven architecture (OFS-lib/event)
- Event propagation between components

C. Plugin Architecture:
- Demonstrate Lua extension system
- WebSocket API integration

##### Important Relationships

- Data flow between video player and script timeline
- Event propagation paths
- State transitions
- API communication channels

##### Technical Details

Annotations for:
- OpenGL rendering pipeline
- MPV video player integration
- Lua scripting engine
- WebSocket API endpoints
- File format handling

##### External Dependencies

Libraries:
- SDL2
- ImGui
- libmpv
- Lua
- GLM
- Other support libraries

##### Infrastructure Layer (video playback, file I/O)

Remember to emphasize the modular nature of the application, showing how the OFS-lib provides core functionality that's utilized by the main application layer.

This architecture should reflect the application's primary purpose of creating and editing funscript files while maintaining a clear separation between UI, core functionality, and media processing components.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        direction TB
        ImGui["ImGui Integration"]
        Timeline["Timeline Components"]:::ui
        VideoControls["Video Player Controls"]:::ui
        Waveform["Waveform Display"]:::ui
        VideoPreview["Video Preview"]:::ui
        CustomWidgets["Custom UI Widgets"]
    end

    subgraph Core["Core Application Layer"]
        direction TB
        MainApp["Main Application"]:::core
        ProjectMgr["Project Management"]:::core
        StateMgr["State Management"]:::core
        EventSys["Event System"]:::core
        UndoSystem["Undo System"]:::core
        FunscriptHandler["Funscript Handler"]:::core
    end

    subgraph Media["Media Processing Layer"]
        direction TB
        MPV["MPV Video Player"]:::media
        WaveformGen["Waveform Generator"]:::media
        PreviewSys["Preview System"]:::media
    end

    subgraph Script["Scripting Layer"]
        direction TB
        LuaEngine["Lua Scripting Engine"]:::script
        WebSocket["WebSocket API"]:::script
        CoreExt["Core Extensions"]:::script
        ApiInt["API Interfaces"]:::script
    end

    subgraph Ext["External Dependencies"]
        direction TB
        SDL2["SDL2"]:::ext
        OpenGL["OpenGL"]:::ext
        LibMPV["libmpv"]:::ext
        LuaLib["Lua"]:::ext
        GLM["GLM"]:::ext
    end

    %% Relationships
    UI --> Core
    Core --> Media
    Core --> Script
    Media <--> Script
    
    %% External Dependencies
    OpenGL --> UI
    SDL2 --> Core
    LibMPV --> Media
    LuaLib --> Script
    GLM --> Core

    %% Click Events
    click MainApp "https://github.com/Rakly3/OFS/blob/master/src/OpenFunscripter.cpp"
    click ProjectMgr "https://github.com/Rakly3/OFS/blob/master/src/OFS_Project.cpp"
    click StateMgr "https://github.com/Rakly3/OFS/blob/master/OFS-lib/state/OFS_StateManager.cpp"
    click EventSys "https://github.com/Rakly3/OFS/blob/master/OFS-lib/event/OFS_EventSystem.cpp"
    click ImGui "https://github.com/Rakly3/OFS/tree/master/OFS-lib/imgui_impl/"
    click Timeline "https://github.com/Rakly3/OFS/blob/master/OFS-lib/UI/OFS_ScriptTimeline.cpp"
    click VideoControls "https://github.com/Rakly3/OFS/blob/master/OFS-lib/UI/OFS_VideoplayerControls.cpp"
    click LuaEngine "https://github.com/Rakly3/OFS/blob/master/src/lua/OFS_LuaExtension.cpp"
    click WebSocket "https://github.com/Rakly3/OFS/blob/master/src/api/OFS_WebsocketApi.cpp"
    click CoreExt "https://github.com/Rakly3/OFS/blob/master/src/lua/OFS_LuaCoreExtension.cpp"
    click ApiInt "https://github.com/Rakly3/OFS/tree/master/src/lua/api/"
    click MPV "https://github.com/Rakly3/OFS/blob/master/OFS-lib/videoplayer/impl/OFS_MpvVideoplayer.cpp"
    click WaveformGen "https://github.com/Rakly3/OFS/blob/master/OFS-lib/UI/OFS_Waveform.cpp"
    click VideoPreview "https://github.com/Rakly3/OFS/blob/master/OFS-lib/UI/OFS_Videopreview.cpp"
    click FunscriptHandler "https://github.com/Rakly3/OFS/blob/master/OFS-lib/Funscript/Funscript.cpp"
    click UndoSystem "https://github.com/Rakly3/OFS/blob/master/OFS-lib/Funscript/FunscriptUndoSystem.cpp"

    %% Styling
    classDef core fill:#3498db
    classDef ui fill:#2ecc71
    classDef media fill:#f1c40f
    classDef script fill:#9b59b6
    classDef ext fill:#95a5a6

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        UiComp["UI Component"]:::ui
        MediaComp["Media Component"]:::media
        ScriptComp["Script Component"]:::script
        ExtComp["External Dependency"]:::ext
    end
```
