# alexwiench/json-canvas-to-mermaid architecture

> Architecture diagram of the GitHub repository alexwiench/json-canvas-to-mermaid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexwiench/json-canvas-to-mermaid
- Repository: https://github.com/alexwiench/json-canvas-to-mermaid

## Overview

##### File structure
- Top-level artifacts:
- `ExampleUsage.js` (demo script)
- Build & packaging files (`package.json`, `bun.lockb`, `.npmignore`, etc.)
- `src/` directory containing the implementation modules
- `tests/` directory containing unit tests for each phase
- Implementation modules in `src/`:
- `validation.js` – input data checks
- `createNodeTree.js` – builds hierarchical node graph
- `index.js` – main export that wires the three phases
- Configuration: `jsconfig.json` for IDE support, CI/test scripts in `package.json`.

##### Key points from the README
- Three-step pipeline: **Validate → Build Tree → Generate Syntax**
- Exposed utilities for advanced use cases (`validateCustomColors`, `validateGraphDirection`, etc.)
- Zero external dependencies, published on npm

##### Main components
1. **Input Layer**
- JSON Canvas Data object
- Optional parameters: `customColors`, `graphDirection`
2. **Validation Module**
- `validateJsonCanvasData(data)`
- `validateGraphDirection(direction)`
3. **Hierarchy Builder**
- `createNodeTree(data)`
5. **Output Layer**
- Can be passed to a renderer (browser, CLI) or saved to file
6. **Support & Packaging**
- Example/demo script (`ExampleUsage.js`)
- Unit tests (`tests/…`)
- NPM/Bun packaging and publishing

##### Architectural patterns and principles
- **Pipeline pattern**: clear separation of concerns in a linear data flow
- **Modularity**: each responsibility (validate, transform, generate) lives in its own unit
- **Extensibility points**: exposed utility functions for custom workflows
- **Zero-dependency design**: simplifies packaging and reduces surface area

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input & Configuration
    subgraph "Input & Configuration"
        JSON["JSON Canvas Data"]:::blue
        params["customColors & graphDirection"]:::blue
        Example["ExampleUsage.js"]:::blue
    end

    %% Core Pipeline
    subgraph "Core Pipeline"
        Orchestrator["Pipeline Orchestrator\nsrc/index.js"]:::green
        Validate["Validation Module\nvalidateJsonCanvasData()\nvalidateCustomColors()\nvalidateGraphDirection()"]:::green
        Build["Hierarchy Builder\ncreateNodeTree()"]:::green
        Generate["Mermaid Generator\nconvertToMermaid()"]:::green
    end

    %% Output
    subgraph "Output"
        Mermaid["Mermaid Syntax Output"]:::blue
    end

    %% Tests & Packaging
    subgraph "Tests & Packaging"
        Test1["buildJsonCanvasHierarchy.test.js"]:::orange
        Test2["generateMermaidFlowchart.test.js"]:::orange
        pkg1["package.json"]:::orange
        pkg2["bun.lockb"]:::orange
        pkg3[".npmignore"]:::orange
        pkg4["jsconfig.json"]:::orange
    end

    %% Data Flow
    JSON -->|"raw JSON Canvas"| Validate
    params --> Validate
    Validate -->|"validated data"| Build
    Build -->|"hierarchical tree"| Generate
    params --> Generate
    Generate -->|"Mermaid syntax"| Mermaid

    %% Orchestration
    Example -->|"imports Orchestrator"| Orchestrator
    Orchestrator --> Validate
    Orchestrator --> Build
    Orchestrator --> Generate
    Generate -->|"returns syntax"| Orchestrator
    Orchestrator --> Mermaid

    %% Tests relations
    Test1 -->|"tests Validation & Build"| Validate
    Test1 --> Build
    Test2 -->|"tests Generate"| Generate

    %% Packaging relations
    pkg1 -->|"publishes Orchestrator"| Orchestrator
    pkg2 --> Orchestrator
    pkg3 --> Orchestrator
    pkg4 --> Orchestrator

    %% Click Events
    click Example "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/ExampleUsage.js"
    click Validate "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/src/validation.js"
    click Build "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/src/createNodeTree.js"
    click Generate "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/src/convertToMermaid.js"
    click Orchestrator "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/src/index.js"
    click Test1 "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/tests/buildJsonCanvasHierarchy.test.js"
    click Test2 "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/tests/generateMermaidFlowchart.test.js"
    click pkg1 "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/package.json"
    click pkg2 "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/bun.lockb"
    click pkg3 "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/.npmignore"
    click pkg4 "https://github.com/alexwiench/json-canvas-to-mermaid/blob/main/jsconfig.json"

    %% Styles
    classDef blue fill:#B3D4FC,stroke:#333,stroke-width:1px
    classDef green fill:#C2FABC,stroke:#333,stroke-width:1px
    classDef orange fill:#FFD8A9,stroke:#333,stroke-width:1px
```
