# dvreeze/yaidom architecture

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

- Interactive diagram: https://gitdiagram.com/dvreeze/yaidom
- Repository: https://github.com/dvreeze/yaidom

## Overview

##### Main Components
- Core API & Domain Model: Representing the uniform XML query API, including elements, trees, and the various “query API” traits and classes (which are central in the “shared” module).
- Platform-Specific Implementations: Include separate components for the JVM and JavaScript implementations. The “jvm” folder contains conversion, parsing (using JAXP, StAX, SAX, and DOM), printing, and XPath evaluation modules (with additional support for Saxon). The “js” folder contains analogous JS implementations and demo apps.
- Conversion Layers: Separate these as they allow inter-conversion between different XML models (e.g., Scala XML, JsDom, Saxon-based nodes, etc.). Components like “convert”, “scalaxml”, and “simple” illustrate this approach.

##### Relationships and Interactions
- The Core API is the central hub that the platform-specific modules (JVM and JS) depend on and extend.
- The “shared” module provides common definitions (e.g., handling of names, namespaces, core types like EName, QName, etc.) that the implementations in the “jvm” and “js” modules build upon.
- Conversion components feed into both the input (parsing) and output (printing) pipelines, allowing conversion from one XML model to another.
- There is directional dependency from the higher-level query API and abstraction toward lower-level technical implementations (e.g., parser or printer classes), and also from the application/demo layers toward these processing engines.
- Notice the usage of external libraries (Saxon-HE) along with integration mechanisms to plug in more sophisticated XPath or transformation capabilities.

##### Architectural Patterns and Design Principles
- Modularity: The project is clearly segmented into modules based on platforms (JVM, JS) and shared concerns.
- Separation of Concerns: Each layer (the query API, parsing, printing, conversions) is well encapsulated.
- Abstraction & Extensibility: The uniform query API abstracts over several concrete implementations, allowing additional DOM implementations to be added.
- Use of well-known technologies: Leveraging the Scala Collections API, JAXP, and Saxon for XML processing.
- Test-Driven Design: The extensive test directories show a focus on validating consistency and correctness across multiple XML processing techniques.

##### Design Elements and Notations
- Use clear labels for each module or component.
- Brief annotations within or near the components to note any key features (e.g., “Immutable Default DOM”, “Saxon-based XPath”, “Supports Scala Collections”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core API & Domain Model
    subgraph "Core API & Domain Model"
        coreApi["Yaidom Core API"]:::core
        coreTypes["Core Types (EName, QName, etc.)"]:::core
        queryApi["Query API"]:::core
    end

    %% Shared/Common Utilities
    subgraph "Shared/Common Utilities"
        sharedConvert["Shared Convert"]:::shared
        sharedUtils["Shared Utils"]:::shared
    end

    %% Conversion Layer
    subgraph "Conversion Layer"
        convLayer["Conversion Layer"]:::conversion
    end

    %% JVM-specific Implementation
    subgraph "JVM Implementation"
        jvmParse["JVM Parsing (SAX/DOM/StAX)"]:::jvm
        jvmConvert["JVM Conversion"]:::jvm
        jvmPrint["JVM Printing"]:::jvm
        jvmSaxon["JVM Saxon-based XPath"]:::jvm
        jvmDom["JVM DOM-like Trees"]:::jvm
    end

    %% JS-specific Implementation
    subgraph "JS Implementation"
        jsConvert["JS Conversion (JsDom)"]:::js
        jsDom["JS DOM-like Trees"]:::js
        jsXpath["JS XPath Evaluation"]:::js
    end

    %% Demo / Test Applications
    subgraph "Demo / Test Applications"
        jsDemo["JS Demo Apps"]:::demo
        jsdemos["JS Demos (HTML/CSS/XML)"]:::demo
    end

    %% External Dependencies
    subgraph "External Dependencies"
        saxonDep["Saxon-HE"]:::external
    end

    %% Relationships
    %% Shared utilities feed conversion layer
    sharedConvert --> convLayer
    sharedUtils --> convLayer

    %% Conversion layer supplies the Core API
    convLayer --> coreApi
    convLayer --> queryApi

    %% Core API is composed of core types and query API designs
    coreApi --- coreTypes
    coreApi --- queryApi

    %% JVM Flow
    jvmParse --> jvmConvert
    jvmConvert --> convLayer
    jvmPrint --> coreApi
    jvmDom --> coreApi
    jvmSaxon --> saxonDep

    %% JS Flow
    jsConvert --> convLayer
    jsDom --> coreApi
    jsXpath --> coreApi

    %% Demo Applications utilize JS Implementation and Core API
    jsDemo --> coreApi
    jsdemos --> coreApi

    %% Styling Classes
    classDef core fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef shared fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef conversion fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef jvm fill:#f5cba7,stroke:#a04000,stroke-width:2px;
    classDef js fill:#d2f4ea,stroke:#0e6251,stroke-width:2px;
    classDef demo fill:#fcf3cf,stroke:#b7950b,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#922b21,stroke-width:2px;

    %% Click Events for Component Mapping
    click coreApi "https://github.com/dvreeze/yaidom/tree/master/shared/src/main/scala/eu/cdevreeze/yaidom"
    click coreTypes "https://github.com/dvreeze/yaidom/tree/master/shared/src/main/scala/eu/cdevreeze/yaidom/core"
    click queryApi "https://github.com/dvreeze/yaidom/tree/master/shared/src/main/scala/eu/cdevreeze/yaidom/queryapi"

    click sharedConvert "https://github.com/dvreeze/yaidom/tree/master/shared/src/main/scala/eu/cdevreeze/yaidom/convert"
    click sharedUtils "https://github.com/dvreeze/yaidom/tree/master/shared/src/main/scala/eu/cdevreeze/yaidom/utils"

    click jvmParse "https://github.com/dvreeze/yaidom/tree/master/jvm/src/main/scala/eu/cdevreeze/yaidom/parse"
    click jvmConvert "https://github.com/dvreeze/yaidom/tree/master/jvm/src/main/scala/eu/cdevreeze/yaidom/convert"
    click jvmPrint "https://github.com/dvreeze/yaidom/tree/master/jvm/src/main/scala/eu/cdevreeze/yaidom/print"
    click jvmSaxon "https://github.com/dvreeze/yaidom/tree/master/jvm/src/main/scala/eu/cdevreeze/yaidom/saxon"
    click jvmDom "https://github.com/dvreeze/yaidom/tree/master/jvm/src/main/scala/eu/cdevreeze/yaidom/dom"

    click jsConvert "https://github.com/dvreeze/yaidom/tree/master/js/src/main/scala/eu/cdevreeze/yaidom/convert"
    click jsDom "https://github.com/dvreeze/yaidom/tree/master/js/src/main/scala/eu/cdevreeze/yaidom/jsdom"
    click jsXpath "https://github.com/dvreeze/yaidom/tree/master/js/src/main/scala/eu/cdevreeze/yaidom/xpath/jsdom"

    click jsDemo "https://github.com/dvreeze/yaidom/tree/master/js/src/main/scala/eu/cdevreeze/yaidom/jsdemoapp"
    click jsdemos "https://github.com/dvreeze/yaidom/tree/master/jsdemos"
```
