# patriciogonzalezvivo/glsleditor architecture

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

- Interactive diagram: https://gitdiagram.com/patriciogonzalezvivo/glsleditor
- Repository: https://github.com/patriciogonzalezvivo/glsleditor

## Overview

##### Project type and purpose
- This is a standalone, client-side WebGL/JavaScript application (“glslEditor”) that provides an in-browser (and Electron) GLSL shader editing environment.
- It packages as a pure-frontend library (build/glslEditor.js + .css) and has an Electron wrapper for local desktop use.

##### File structure
- Top-level:
- build/          ← production artifacts (glslEditor.js, .css, source maps)
- gulpfile.js     ← build/task runner
- index.html      ← demo/embed page
- package.json    ← dependencies, scripts (start, dev)
- src/            ← source code
- src/css/         ← global styling and component styles
- src/index.html   ← development HTML shell
- src/js/:
- core/          ← core classes: Editor.js (ties CodeMirror + UI), Shader.js (compiles GLSL, interfaces with WebGL)
- io/            ← BufferManager, FileDrop, LocalStorage, Share modules
- tools/         ← utilities (debugging, downloading, media capture, URL handling, interactive DOM helpers)
- ui/            ← visual components (menus, pickers, error displays, modals, debugger)
- main.js         ← Electron main process entrypoint

##### README for additional insights
- Built on top of CodeMirror, glslCanvas or glslViewer backends.
- Exposes an API: `new GlslEditor(element, options)`.
- Supports drag-drop, hash-watch, multiple buffers, menu, inline pickers, error display, breakpoints.

##### Main components
a. User Interfaces (Browser or Electron UI)
- HTML container
- CSS styles
- UI modules (Menus, Pickers, Modals, Debugger)
b. Editor Core
- CodeMirror integration (syntax, editing)
- Buffer management (multiple shader files/tabs)
c. GLSL Shader Pipeline
- Shader.js → compiles GLSL, injects headers/footers
- WebGL canvas (via glslCanvas or native WebGL context)
d. I/O and Persistence Modules
- FileDrop → drag & drop files
- LocalStorage → save/load shaders in browser storage
- Share → generate share links / export
- HashWatch → URL hash‐based file loading
e. Utility Tools
- Debugging, media capture, downloads, interactive DOM helpers
f. Build & Packaging
- Gulp tasks (build, minify)
- npm scripts (start, dev)
g. Electron Layer (optional)
- main.js process
- renderer loads the same src/js modules

##### Relationships and interactions
- User interacts with UI components → events sent to Editor core
- Editor core reads/writes shader buffers via I/O modules
- On compile/run: Editor passes shader code to Shader.js → WebGL context → Canvas output
- UI pickers hook into Editor to modify uniform values at runtime
- Tools respond to user actions (download code, capture media, debug shader)
- Build system (Gulp) generates the final glslEditor.js/css artifacts consumed by index.html or by Electron renderer

##### Architectural patterns and design principles
- Modular directory structure by responsibility (core, io, tools, ui)
- Single-page application style; MVC-like: Editor (Controller), UI (View), BufferManager & Shader (Model)
- Event-driven communication (custom events or callback hooks)
- Reuse of external libraries (CodeMirror, glslCanvas)

##### Elements
- User → UI
- UI → Editor core
- Editor core ↔ I/O modules
- Core → Shader.js → WebGL Canvas
- Tools ↔ Core/UI
- Labels for external dependencies (CodeMirror, WebGL, Electron)

##### Final advice
- Don’t omit the build step and Electron wrapper.
- Data flow (shader code, uniform values) and control flow (user actions, compile triggers).
- Keep it detailed but organized by functional layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User"]:::external
    User -->|"interacts with"| UIContainer

    %% UI Layer
    subgraph "UI Layer"
        direction TB
        UIContainer["UI Components"]:::ui
        CSSStyles["CSS Styles"]:::ui
        HTMLShell["HTML Shell"]:::ui
        subgraph "UI Modules"
            direction TB
            ErrorsDisplay["ErrorsDisplay"]:::ui
            Menu["Menu"]:::ui
            MenuItem["MenuItem"]:::ui
            ExportIcon["ExportIcon"]:::ui
            VisualDebugger["VisualDebugger"]:::ui
            subgraph "Modals"
                direction TB
                Modal["Modal"]:::ui
                ExportModal["ExportModal"]:::ui
            end
            subgraph "Pickers"
                direction TB
                Picker["Picker"]:::ui
                ColorPicker["ColorPicker"]:::ui
                FloatPicker["FloatPicker"]:::ui
                Vec2Picker["Vec2Picker"]:::ui
                Vec3Picker["Vec3Picker"]:::ui
                PickersTypes["Picker Types"]:::ui
            end
        end
        UIContainer --> CSSStyles
        UIContainer --> HTMLShell
        UIContainer --> ErrorsDisplay
        UIContainer --> Menu
        UIContainer --> MenuItem
        UIContainer --> ExportIcon
        UIContainer --> VisualDebugger
        UIContainer --> Modal
        UIContainer --> ExportModal
        UIContainer --> Picker
        UIContainer --> ColorPicker
        UIContainer --> FloatPicker
        UIContainer --> Vec2Picker
        UIContainer --> Vec3Picker
        UIContainer --> PickersTypes
    end

    %% Core Layer
    subgraph "Core Layer"
        direction TB
        GlslEditor["GlslEditor"]:::core
        EditorCore["Editor"]:::core
        ShaderCore["Shader"]:::core
    end

    UIContainer -->|"API calls"| GlslEditor
    GlslEditor --> EditorCore
    EditorCore --> ShaderCore

    %% I/O Layer
    subgraph "I/O & Persistence"
        direction TB
        BufferManager["BufferManager"]:::io
        FileDrop["FileDrop"]:::io
        HashWatch["HashWatch"]:::io
        LocalStorage["LocalStorage"]:::io
        ShareModule["Share"]:::io
    end

    EditorCore -->|"read/write buffer"| BufferManager
    EditorCore --> FileDrop
    EditorCore --> HashWatch
    EditorCore --> LocalStorage
    EditorCore --> ShareModule
    BufferManager --> EditorCore

    %% Shader Engine
    subgraph "Shader Engine"
        direction TB
        WebGLCanvas["WebGL Canvas"]:::external
        ShaderCore -->|"compile & inject"| WebGLCanvas
    end

    %% Tools Layer
    subgraph "Utility Tools"
        direction TB
        CommonUtil["common.js"]:::tools
        DebugUtil["debugging.js"]:::tools
        DownloadUtil["download.js"]:::tools
        MediaCapture["mediaCapture.js"]:::tools
        URLUtil["urls.js"]:::tools
        DOMHelpers["interactiveDom.js"]:::tools
        MixinUtil["mixin.js"]:::tools
    end

    CommonUtil <--> EditorCore
    DebugUtil <--> EditorCore
    DownloadUtil <--> UIContainer
    MediaCapture <--> UIContainer
    URLUtil <--> HashWatch
    DOMHelpers <--> EditorCore
    MixinUtil <--> EditorCore

    %% Build & Packaging
    subgraph "Build & Packaging"
        direction TB
        Gulpfile["gulpfile.js"]:::build
        BuildArtifacts["build/glslEditor.js/.css"]:::build
        DemoPage["index.html"]:::build
        PackageConfig["package.json"]:::build
        PackageLock["package-lock.json"]:::build
        Gulpfile --> BuildArtifacts
        PackageConfig --> BuildArtifacts
    end

    DemoPage --> BuildArtifacts

    %% Electron Layer
    subgraph "Electron Layer"
        direction TB
        MainProcess["main.js"]:::build
        ElectronStyles["ElectronApp.css"]:::ui
        MainProcess --> UIContainer
        MainProcess --> GlslEditor
    end

    %% External Dependencies
    subgraph "External Libraries"
        direction TB
        CodeMirror["CodeMirror"]:::external
        GlslCanvas["glslCanvas"]:::external
        ElectronExt["Electron"]:::external
    end

    EditorCore --> CodeMirror
    WebGLCanvas --> GlslCanvas
    MainProcess --> ElectronExt

    %% Click Events
    click CSSStyles "https://github.com/patriciogonzalezvivo/glsleditor/tree/main/src/css/"
    click HTMLShell "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/index.html"
    click ErrorsDisplay "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/ErrorsDisplay.js"
    click Menu "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/Menu.js"
    click MenuItem "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/MenuItem.js"
    click ExportIcon "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/ExportIcon.js"
    click VisualDebugger "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/VisualDebugger.js"
    click Modal "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/modals/Modal.js"
    click ExportModal "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/modals/ExportModal.js"
    click Picker "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/pickers/Picker.js"
    click ColorPicker "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/pickers/ColorPicker.js"
    click FloatPicker "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/pickers/FloatPicker.js"
    click Vec2Picker "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/pickers/Vec2Picker.js"
    click Vec3Picker "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/ui/pickers/Vec3Picker.js"
    click PickersTypes "https://github.com/patriciogonzalezvivo/glsleditor/tree/main/src/js/ui/pickers/types/"
    click GlslEditor "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/GlslEditor.js"
    click EditorCore "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/core/Editor.js"
    click ShaderCore "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/core/Shader.js"
    click BufferManager "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/io/BufferManager.js"
    click FileDrop "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/io/FileDrop.js"
    click HashWatch "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/io/HashWatch.js"
    click LocalStorage "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/io/LocalStorage.js"
    click ShareModule "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/io/Share.js"
    click CommonUtil "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/common.js"
    click DebugUtil "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/debugging.js"
    click DownloadUtil "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/download.js"
    click MediaCapture "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/mediaCapture.js"
    click URLUtil "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/urls.js"
    click DOMHelpers "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/interactiveDom.js"
    click MixinUtil "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/js/tools/mixin.js"
    click Gulpfile "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/gulpfile.js"
    click DemoPage "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/index.html"
    click PackageConfig "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/package.json"
    click PackageLock "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/package-lock.json"
    click MainProcess "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/main.js"
    click ElectronStyles "https://github.com/patriciogonzalezvivo/glsleditor/blob/main/src/css/ElectronApp.css"

    %% Styles
    classDef ui fill:#FFA500,stroke:#333,stroke-width:1px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef io fill:#90EE90,stroke:#333,stroke-width:1px
    classDef tools fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef build fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#F08080,stroke:#333,stroke-width:1px
```
