# chearon/dropflow architecture

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

- Interactive diagram: https://gitdiagram.com/chearon/dropflow
- Repository: https://github.com/chearon/dropflow

## Overview

##### File structure
- Top‑level:
- src/ – core TS modules (parsing, DOM, style, layout, paint, environment abstractions)
- gen/ – code‑generation scripts producing Unicode tries and property tables in C++/TS
- pkg/ – vendored C++ libraries (harfbuzz, sheenbidi, binaryen) and their build scripts
- dist/ – bundled WebAssembly (`dropflow.wasm`)
- examples/ – usage demos
- test/ – automated specs
- site/ – documentation front‑end (Vite)
- assets/ – fonts, logos, images
- build.zig/tools/postprocess_wasm.zig – Zig build configs for WASM

##### README for additional insights
- Confirms the pipeline stages and that HarfBuzz (WASM), SheenBidi, and Unicode tries are core. Emphasizes environment abstraction (fonts/images), hyperscript vs. HTML/CSS parsing, and multiple paint backends.

- A[Hyperscript API] --> B[DOM & Style Engine]
- C --> D[Layout Engine]
- D --> E[Paint Backend]

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input Layer
    subgraph "Input Layer"
        direction TB
        HyperscriptAPI["Hyperscript API (h(), style(), dom())"]:::core
        ParseAPI["Parse API"]:::core
        ParseHTML["Parse HTML"]:::core
        ParseCSS["Parse CSS"]:::core
    end

    %% DOM & Style Engine
    subgraph "DOM & Style Engine"
        direction TB
        DOMTree["DOM Tree (HTMLElement, TextNode)"]:::core
        StyleCalc["Style Calculation (cascade, inheritance)"]:::core
    end

    %% Code-Gen Artifacts
    subgraph "Code-Gen Artifacts"
        direction TB
        GenScripts["Gen Scripts & Data Sources"]:::codegen
        GenTries["Generated Unicode Tries & Tables"]:::codegen
        UnicodeBuilder["Unicode Trie Builder"]:::codegen
    end

    %% Font & Resource Manager
    subgraph "Font & Resource Manager"
        direction TB
        RegisterNoto["Register Noto Fonts API"]:::core
        TextFont["FontFaceSet & Face Creation"]:::core
        EnvHooks["Environment Hooks (URL, font)"]:::core
    end

    %% WASM Runtime
    subgraph "WASM Runtime"
        direction TB
        WasmBinary["dropflow.wasm"]:::wasm
        WasmLoader["WASM Loader/Runtime Glue"]:::wasm
    end

    %% Layout Engine
    subgraph "Layout Engine"
        direction TB
        BoxTree["Box Tree Generation"]:::core
        LayoutAlgo["Layout Algorithms (block, inline, floats, bidi)"]:::core
    end

    %% Paint Backends
    subgraph "Paint Backends"
        direction TB
        PaintCanvas["Canvas Backend"]:::backend
        PaintSVG["SVG Backend"]:::backend
        PaintHTML["HTML Backend"]:::backend
        PaintOrch["Paint Orchestration"]:::backend
    end

    %% Host Environments
    subgraph "Host Environments"
        direction TB
        NodeEnv["Node.js Environment"]:::env
        BrowserEnv["Browser Environment"]:::env
    end

    %% Data Flow
    HyperscriptAPI -->|uses| DOMTree
    ParseAPI -->|parses| DOMTree
    ParseHTML -->|parses HTML| DOMTree
    ParseCSS -->|parses CSS| StyleCalc
    DOMTree -->|builds| StyleCalc
    StyleCalc -->|produces| BoxTree
    BoxTree -->|feeds| LayoutAlgo
    LayoutAlgo -->|outputs| PaintOrch
    PaintOrch -->|renders| PaintCanvas
    PaintOrch -->|renders| PaintSVG
    PaintOrch -->|renders| PaintHTML

    %% Dependencies
    GenScripts -->|build-time| WasmBinary
    GenTries -->|build-time| WasmBinary
    UnicodeBuilder -->|build-time| GenTries

    EnvHooks -->|provides| RegisterNoto
    EnvHooks -->|provides| TextFont
    EnvHooks -->|supplies| WasmLoader

    WasmLoader -->|loads| WasmBinary
    WasmBinary -->|used by| StyleCalc
    WasmBinary -->|used by| LayoutAlgo

    NodeEnv -->|provides fs, canvas| PaintCanvas
    NodeEnv -->|provides| WasmLoader
    BrowserEnv -->|provides fetch, font loading| EnvHooks
    BrowserEnv -->|provides| WasmLoader

    RegisterNoto -->|used by| StyleCalc
    TextFont -->|used by| StyleCalc
    TextFont -->|used by| LayoutAlgo

    %% Click Events
    click HyperscriptAPI "https://github.com/chearon/dropflow/blob/master/src/api.ts"
    click ParseAPI "https://github.com/chearon/dropflow/blob/master/src/api-parse.ts"
    click ParseHTML "https://github.com/chearon/dropflow/blob/master/src/parse-html.ts"
    click ParseCSS "https://github.com/chearon/dropflow/blob/master/src/parse-css.js"
    click DOMTree "https://github.com/chearon/dropflow/blob/master/src/dom.ts"
    click StyleCalc "https://github.com/chearon/dropflow/blob/master/src/style.ts"
    click GenScripts "https://github.com/chearon/dropflow/tree/master/gen/"
    click GenTries "https://github.com/chearon/dropflow/blob/master/src/trie-emoji.ts"
    click UnicodeBuilder "https://github.com/chearon/dropflow/blob/master/src/text-unicode-trie-builder.ts"
    click RegisterNoto "https://github.com/chearon/dropflow/blob/master/src/api-register-noto-fonts.ts"
    click TextFont "https://github.com/chearon/dropflow/blob/master/src/text-font.ts"
    click EnvHooks "https://github.com/chearon/dropflow/blob/master/src/environment.ts"
    click WasmBinary "https://github.com/chearon/dropflow/blob/master/dist/dropflow.wasm"
    click WasmLoader "https://github.com/chearon/dropflow/blob/master/src/wasm.ts"
    click BoxTree "https://github.com/chearon/dropflow/blob/master/src/layout-box.ts"
    click LayoutAlgo "https://github.com/chearon/dropflow/blob/master/src/layout-flow.ts"
    click PaintCanvas "https://github.com/chearon/dropflow/blob/master/src/paint-canvas.ts"
    click PaintSVG "https://github.com/chearon/dropflow/blob/master/src/paint-svg.ts"
    click PaintHTML "https://github.com/chearon/dropflow/blob/master/src/paint-html.ts"
    click NodeEnv "https://github.com/chearon/dropflow/blob/master/src/environment-node.ts"
    click BrowserEnv "https://github.com/chearon/dropflow/blob/master/src/environment-browser.ts"

    %% Styles
    classDef core fill:#AED6F1,stroke:#000
    classDef codegen fill:#ABEBC6,stroke:#000
    classDef wasm fill:#F5B041,stroke:#000
    classDef backend fill:#D2B4DE,stroke:#000
    classDef env fill:#CACFD2,stroke:#000
```
