# webreflection/linkedom architecture

> Architecture diagram of the GitHub repository webreflection/linkedom, 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/webreflection/linkedom
- Repository: https://github.com/webreflection/linkedom

## Overview

##### Main Components

a. Core DOM Implementation Layer
- Interface Components (interface/)
- HTML Elements (html/)
- DOM Core (dom/)
- XML/SVG Support (xml/, svg/)

b. Module Systems Layer
- ESM Implementation
- CJS Implementation
- Types Support

c. Parser Components
- DOMParser Implementation
- HTML Parser
- XML Parser
- JSDON Serializer/Deserializer

**┌─────────────────────────────────────────────────────────┐**
- Client Application                    │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Public API Layer                      │
- ┬──────────────────────────┬────────────────┤
- DOMParser  │       parseHTML          │    parseJSON   │
- ┴──────────────────────────┴────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Core DOM Implementation                 │
- ┬──────────┬───────────┬──────────┬───────────┤
- Interface │  HTML    │   DOM     │   XML    │    SVG    │
- Layer   │Elements  │   Core    │ Support  │  Support  │
- ┴──────────┴───────────┴──────────┴───────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Shared Components                      │
- ┬──────────┬───────────┬──────────┬───────────┤
- Mixins   │ Utils    │  Cache    │  JSDON   │ Constants │
- ┴──────────┴───────────┴──────────┴───────────┘

##### Key Elements to Highlight

- Node relationships (parent-child connections)
- Module system support (ESM/CJS)
- Parser flow (HTML/XML → DOM nodes)
- Serialization/Deserialization paths

##### Important Relationships

- Document → Node hierarchy
- Element inheritance chain
- Parser → DOM node creation flow
- Cache system (optional component)
- JSDON serialization paths

##### Implementation Details

**[Node Structure Detail]**
**┌─────────────────┐**
- Node        │
- ┤
- ← Previous Link │
- → Next Link     │
- ↑ Parent Link   │
- ┘

##### Additional Notes

- Version information
- Cached vs. non-cached variants
- Performance-critical paths
- Module resolution paths

- The lightweight nature of the implementation
- The triple-linked list architecture
- The separation between core DOM functionality and parsing
- The multiple module system support
- The optimization paths for both cached and non-cached versions

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client ["Client Application"]
        App[Client Code]
    end

    subgraph API ["Public API Layer"]
        Entry["Main Entry Point"]:::api
        Cached["Cached Version"]:::api
        Parser["DOM Parser"]:::parser
        ParseHTML["parseHTML"]:::parser
        ParseJSON["parseJSON"]:::parser
    end

    subgraph Core ["Core DOM Implementation"]
        Interface["Interface Layer"]:::core
        HTML["HTML Elements"]:::core
        DOMCore["DOM Core"]:::core
        XML["XML Support"]:::core
        SVG["SVG Support"]:::core
    end

    subgraph Shared ["Shared Components"]
        Mixins["Mixins"]:::shared
        Utils["Utilities"]:::shared
        Cache["Cache"]:::shared
        JSDON["JSDON"]:::shared
        Constants["Constants"]:::shared
    end

    subgraph Modules ["Module Systems"]
        ESM["ESM Implementation"]:::module
        CJS["CJS Implementation"]:::module
        Types["Types Support"]:::module
    end

    subgraph NodeStructure ["Node Structure"]
        direction TB
        Node["Node Implementation"]:::node
        NodeRel["Node Relationships"]:::node
    end

    %% Relationships
    App --> Entry
    App --> Cached
    Entry --> Parser
    Entry --> ParseHTML
    Entry --> ParseJSON
    Parser --> DOMCore
    ParseHTML --> DOMCore
    ParseJSON --> JSDON
    Interface --> Node
    DOMCore --> Interface
    HTML --> Interface
    XML --> Interface
    SVG --> Interface
    Node --> NodeRel
    Cache --> DOMCore
    Mixins --> Interface
    Utils --> DOMCore
    Constants --> DOMCore
    JSDON --> DOMCore

    %% Click Events
    click Entry "https://github.com/WebReflection/linkedom/blob/main/esm/index.js"
    click Cached "https://github.com/WebReflection/linkedom/blob/main/esm/cached.js"
    click Parser "https://github.com/WebReflection/linkedom/blob/main/esm/dom/parser.js"
    click ParseHTML "https://github.com/WebReflection/linkedom/blob/main/esm/shared/parse-from-string.js"
    click ParseJSON "https://github.com/WebReflection/linkedom/blob/main/esm/shared/parse-json.js"
    click Interface "https://github.com/WebReflection/linkedom/tree/main/esm/interface/"
    click HTML "https://github.com/WebReflection/linkedom/tree/main/esm/html/"
    click DOMCore "https://github.com/WebReflection/linkedom/tree/main/esm/dom/"
    click XML "https://github.com/WebReflection/linkedom/tree/main/esm/xml/"
    click SVG "https://github.com/WebReflection/linkedom/tree/main/esm/svg/"
    click Mixins "https://github.com/WebReflection/linkedom/tree/main/esm/mixin/"
    click Utils "https://github.com/WebReflection/linkedom/blob/main/esm/shared/utils.js"
    click Cache "https://github.com/WebReflection/linkedom/blob/main/esm/shared/cache.js"
    click JSDON "https://github.com/WebReflection/linkedom/blob/main/esm/shared/jsdon.js"
    click Constants "https://github.com/WebReflection/linkedom/blob/main/esm/shared/constants.js"
    click ESM "https://github.com/WebReflection/linkedom/tree/main/esm/"
    click CJS "https://github.com/WebReflection/linkedom/tree/main/cjs/"
    click Types "https://github.com/WebReflection/linkedom/tree/main/types/"
    click Node "https://github.com/WebReflection/linkedom/blob/main/esm/interface/node.js"
    click NodeRel "https://github.com/WebReflection/linkedom/blob/main/esm/shared/node.js"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef api fill:#FFA500,stroke:#333,stroke-width:1px
    classDef parser fill:#90EE90,stroke:#333,stroke-width:1px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef shared fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef module fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef node fill:#20B2AA,stroke:#333,stroke-width:1px

    %% Legend
    subgraph Legend
        API_L["API"]:::api
        Parser_L["Parser"]:::parser
        Core_L["Core"]:::core
        Shared_L["Shared"]:::shared
        Module_L["Module"]:::module
        Node_L["Node"]:::node
    end
```
