# pkcarreno/jsod architecture

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

- Interactive diagram: https://gitdiagram.com/pkcarreno/jsod
- Repository: https://github.com/pkcarreno/jsod

## Overview

##### Main Components Identification

The system can be broken down into these major components:

a) Frontend Application (React-based)
- Editor Interface
- Output Display
- Settings Management
- UI Components

b) JavaScript Execution Engine
- QuickJS Runtime (via quickjs-emscripten)
- Execution Manager
- Runtime Controller

c) Storage Layer
- Query Storage
- Settings Storage

**┌─ User Interface Layer ─────────────────────┐**
- Editor Component                         │
- Output Component                         │
- Header Controls                          │
- Settings Dialog                          │
- ┬───────────────────────┘
- ↕
**┌─ Application Core Layer ───────────────────┐**
- Editor Behavior Provider                 │
- Code Store                              │
- Settings Store                          │
- Meta Provider                           │
- ┬───────────────────────┘
- ↕
**┌─ Execution Layer ──────────────────────────┐**
- QuickJS Runtime                         │
- Execution Manager                       │
- Runtime Controller                      │
- ┬───────────────────────┘
- ↕
**┌─ Storage Layer ────────────────────────────┐**
- Query Storage                           │
- Local Storage                           │
- ┘

##### Key Interactions to Highlight

a) Code Execution Flow:
- Editor → Code Store → Execution Manager → QuickJS Runtime → Output Display

b) Settings Flow:
- Settings Dialog → Settings Store → Runtime Controller

c) Storage Flow:
- Query Storage ↔ Code Store
- Local Storage ↔ Settings Store

##### Implementation Details to Note

- The separation between the editor interface and execution engine
- The security boundary around the QuickJS runtime
- The offline-first architecture
- The storage mechanism for sharing code

##### Additional Elements

- Component types
- Flow directions
- Security boundaries
- Storage mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef execution fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef boundary fill:none,stroke:#e74c3c,stroke-dasharray: 5 5

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        Editor["Editor Interface"]:::ui
        Output["Output Display"]:::ui
        Header["Header Controls"]:::ui
        Settings["Settings Dialog"]:::ui
        UIComps["UI Components"]:::ui
    end

    %% Application Core Layer
    subgraph Core["Application Core Layer"]
        EditorBehavior["Editor Behavior Provider"]:::core
        CodeStore["Code Store"]:::core
        SettingsStore["Settings Store"]:::core
        MetaProvider["Meta Provider"]:::core
        LogsStore["Logs Store"]:::core
    end

    %% Execution Layer
    subgraph Exec["Execution Layer"]
        QuickJS["QuickJS Runtime"]:::execution
        ExecManager["Execution Manager"]:::execution
        RuntimeCtrl["Runtime Controller"]:::execution
    end

    %% Storage Layer
    subgraph Storage["Storage Layer"]
        QueryStorage["Query Storage"]:::storage
        LocalStorage["Local Storage"]:::storage
    end

    %% Relationships
    Editor --> EditorBehavior
    Editor --> CodeStore
    Output --> LogsStore
    Header --> CodeStore
    Settings --> SettingsStore
    EditorBehavior --> ExecManager
    CodeStore --> ExecManager
    SettingsStore --> RuntimeCtrl
    ExecManager --> QuickJS
    QuickJS --> LogsStore
    RuntimeCtrl --> QuickJS
    CodeStore <--> QueryStorage
    SettingsStore <--> LocalStorage
    MetaProvider --> CodeStore
    UIComps --> Editor
    UIComps --> Output
    UIComps --> Header
    UIComps --> Settings

    %% Click Events
    click Editor "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/components/editor/index.tsx"
    click Output "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/components/output/index.tsx"
    click Settings "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/providers/settings-dialog-provider/index.tsx"
    click QuickJS "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/utils/engine/runtime.ts"
    click ExecManager "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/utils/engine/execution-manager.ts"
    click RuntimeCtrl "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/utils/engine/controller.ts"
    click QueryStorage "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/api/query-storage.ts"
    click SettingsStore "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/stores/settings/index.ts"
    click CodeStore "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/stores/editor/code-store.ts"
    click EditorBehavior "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/providers/editor-behavior/index.tsx"
    click MetaProvider "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/providers/meta-provider.tsx"
    click Header "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/components/header/index.tsx"
    click UIComps "https://github.com/pkcarreno/jsod/tree/main/src/components/ui"
    click LogsStore "https://github.com/pkcarreno/jsod/blob/main/src/features/editor/stores/editor/logs-store.ts"

    %% Legend
    subgraph Legend
        UI_L["UI Component"]:::ui
        Core_L["Core Component"]:::core
        Exec_L["Execution Component"]:::execution
        Storage_L["Storage Component"]:::storage
    end
```
