# pongasoft/emscripten-glfw architecture

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

- Interactive diagram: https://gitdiagram.com/pongasoft/emscripten-glfw
- Repository: https://github.com/pongasoft/emscripten-glfw

## Overview

##### Main Components

a) Core Components:
- GLFW API Layer (C/C++ Interface)
- Emscripten Bridge Layer
- JavaScript Runtime Layer
- Browser Integration Layer

b) Feature Modules:
- Window Management System
- Input Systems (Mouse, Keyboard, Joystick)
- Context Management
- Event System
- Timer System
- Clipboard System
- Threading System (pthread support)

**[Application Layer]**
- ↓
**[GLFW C/C++ API Layer]**
- ↓
**[Emscripten Bridge Layer]**
- ↓
**[JavaScript Runtime Layer]**
- ↓
**[Browser APIs/DOM]**

##### Component Relationships

- Event propagation paths
- API call paths
- Resource management relationships

##### Specific Implementation Details

- Canvas management system
- Hi-DPI support
- Resizable window implementation
- Input device handlers
- Clipboard management
- Threading support

##### Key Features to Highlight

- Multi-window support
- Event handling system
- Resource management
- Platform-specific optimizations

##### Integration Points

Clear connection points for:
- External canvas elements
- Browser event systems
- WebGL/WebGPU context
- Native browser APIs

##### Additional Elements

Include:
- Version information
- Key configuration options
- Platform compatibility notes

##### Implementation Notes

Callouts for:
- Asyncify support
- Hi-DPI handling
- Threading model
- Browser compatibility requirements

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#a8d1f0,stroke:#333
    classDef bridge fill:#90ee90,stroke:#333
    classDef js fill:#ffd700,stroke:#333
    classDef browser fill:#ffa07a,stroke:#333
    classDef input fill:#dda0dd,stroke:#333
    classDef window fill:#98fb98,stroke:#333
    classDef system fill:#f0e68c,stroke:#333

    %% Main Layers
    subgraph ApplicationLayer["Application Layer"]
        App[Application Code]
    end

    subgraph GLFWAPILayer["GLFW API Layer"]
        GLFWAPI["GLFW C/C++ API"]:::api
        ErrorHandler["Error Handling"]:::api
        Config["Configuration"]:::api
    end

    subgraph EmscriptenLayer["Emscripten Bridge Layer"]
        EmBridge["Emscripten Bridge"]:::bridge
        Bindings["Native Bindings"]:::bridge
    end

    subgraph JSLayer["JavaScript Runtime Layer"]
        JSRuntime["JS Runtime"]:::js
        EventLoop["Event Loop"]:::js
    end

    subgraph BrowserLayer["Browser Integration Layer"]
        DOM["DOM Interface"]:::browser
        Canvas["Canvas Management"]:::browser
        WebGL["WebGL Context"]:::browser
    end

    %% Feature Modules
    subgraph CoreSystems["Core Systems"]
        Window["Window Management"]:::window
        Context["Context Management"]:::system
        Events["Event System"]:::system
        Timer["Timer System"]:::system
        Clipboard["Clipboard System"]:::system
        Threading["Threading Support"]:::system
    end

    subgraph InputSystems["Input Systems"]
        Keyboard["Keyboard Handler"]:::input
        Mouse["Mouse Handler"]:::input
        Joystick["Joystick Handler"]:::input
    end

    %% Relationships
    App --> GLFWAPI
    GLFWAPI --> ErrorHandler
    GLFWAPI --> Config
    GLFWAPI --> EmBridge
    EmBridge --> Bindings
    Bindings --> JSRuntime
    JSRuntime --> EventLoop
    EventLoop --> DOM
    DOM --> Canvas
    DOM --> WebGL

    Window --> JSRuntime
    Context --> WebGL
    Events --> EventLoop
    InputSystems --> Events
    Clipboard --> DOM
    Threading --> JSRuntime

    %% Click Events
    click GLFWAPI "https://github.com/pongasoft/emscripten-glfw/blob/master/include/GLFW/emscripten_glfw3.h"
    click EmBridge "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/glfw3.cpp"
    click JSRuntime "https://github.com/pongasoft/emscripten-glfw/blob/master/src/js/lib_emscripten_glfw3.js"
    click Window "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Window.h"
    click Keyboard "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Keyboard.h"
    click Mouse "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Mouse.h"
    click Joystick "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Joystick.h"
    click Context "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Context.h"
    click Events "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Events.h"
    click Clipboard "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Clipboard.h"
    click ErrorHandler "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/ErrorHandler.h"
    click Config "https://github.com/pongasoft/emscripten-glfw/blob/master/src/cpp/emscripten/glfw3/Config.h"
    click Threading "https://github.com/pongasoft/emscripten-glfw/blob/master/examples/example_pthread/main.cpp"

    %% Legend
    subgraph Legend
        L1["API Components"]:::api
        L2["Bridge Components"]:::bridge
        L3["JavaScript Components"]:::js
        L4["Browser Integration"]:::browser
        L5["Input Systems"]:::input
        L6["Window Management"]:::window
        L7["Core Systems"]:::system
    end
```
