# hizzgdev/jsmind architecture

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

- Interactive diagram: https://gitdiagram.com/hizzgdev/jsmind
- Repository: https://github.com/hizzgdev/jsmind

## Overview

##### Project type and purpose
- jsMind is an open‑source pure‑JavaScript library for rendering and editing mind maps on the web, based on HTML5 Canvas and SVG.
- It is a front‑end reusable component (not a full‑stack app), embeddable via script tags or module bundlers.
- Key use cases: embedding a mind‑map viewer/editor in any web page or SPA; providing a plugin API for extensions.

##### File structure
- Top‑level:
- config files (.prettierrc, rollup.config.js, GitHub workflows, .gitignore, .npmignore) → build, lint, CI/CD
- src/ → core library source modules (common, data_provider, dom, graph, layout_provider, mind, node, option, plugin, shortcut_provider, util, view_provider)
- src/plugins/ → first‑class plugins (draggable‑node, screenshot)
- js/ and es6/ and js‑legacy/ → distributed builds (ES5/legacy, ES6, UMD or requirejs)
- style/ → CSS for themes
- example/ → HTML/JS samples showing integration
- docs/ → multi‑language user/developer documentation
- tests/ → unit and legacy tests
- Patterns: modular architecture with clear separation of concerns (data, layout, rendering, DOM interaction, plugins).

##### README for additional insights
- Confirms HTML5 Canvas & SVG rendering layers.
- Mentions three supported data formats.
- Highlights plugin mechanism and theme options.
- Build and distribution via NPM, CDN; CI on GitHub Actions.

a. Main components
- Core Library Modules
– Data Provider: parses & normalizes mind‑map data formats
– Graph Manager: constructs node/edge graph model
– Layout Provider: computes node positions
– View Provider: renders via canvas/SVG
– DOM Adapter: attaches event handlers, resizing, container management
– Utilities & Options Manager: default configs, theming, i18n
– Plugin Manager: lifecycle hooks, plugin registry
- Plugins (draggable‑node, screenshot, future custom plugins)
- Consumer Application (HTML page or SPA)
– Embedding container div
– jsMind API invocations (new jsMind, show, edit callbacks)
- Build & Distribution
– Rollup bundler → produce UMD/ES6/CJS builds
– Prettier & linting → code style
– NPM registry & CDN (jsDelivr, UNPKG)
- Testing
– Unit tests (tests/unit)
– Legacy tests (tests/legacy)
- Documentation & Examples (docs/, example/)
b. Relationships & interactions
- Consumer app calls the Core API → Core loads data via Data Provider → Graph Manager builds model → Layout Provider computes positions → View Provider renders to Canvas/SVG within DOM container → Plugin Manager invokes plugin hooks before/after each stage → DOM Adapter wires user interactions (drag, click, keyboard shortcuts) back to Core → Core updates model and re‑renders
- Build pipeline takes src/ and src/plugins/ → Rollup → output to es6/, js/, js‑legacy/ → published to NPM/CDN
- Tests import core modules or built outputs and run via test runner
c. Architectural patterns
- Modular, layered architecture (data → model → layout → view → DOM)
- Observer/event hook pattern in Plugin Manager
- Separation of concerns: core engine distinct from plugins & UI
- Build/distribution pipeline decoupled from runtime library
d. Key technologies/frameworks
- JavaScript (ES6 modules)
- HTML5 Canvas & SVG for rendering
- Rollup for bundling
- Prettier/ESLint for style
- Mocha/Jest (or similar) for tests
- GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer Application
    subgraph "Consumer Application" 
        style CA fill:#f2f2f2,stroke:#ccc
        CA["Consumer App (Embedding)"] 
        click CA "https://github.com/hizzgdev/jsmind/blob/master/example/1_basic.html"
        click CA "https://github.com/hizzgdev/jsmind/blob/master/example/2_features.html"
        click CA "https://github.com/hizzgdev/jsmind/blob/master/example/3_requirejs.html"
    end

    %% Core Engine Modules
    subgraph "Core Engine"
        DP["Data Provider"]:::core
        click DP "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.data_provider.js"
        FM["Format Module"]:::core
        click FM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.format.js"
        GM["Graph Manager"]:::core
        click GM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.graph.js"
        LP["Layout Provider"]:::core
        click LP "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.layout_provider.js"
        VP["View Provider"]:::core
        click VP "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.view_provider.js"
        DA["DOM Adapter"]:::core
        click DA "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.dom.js"
        UM["Utilities Manager"]:::core
        click UM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.util.js"
        OM["Options Manager"]:::core
        click OM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.option.js"
        SM["Shortcut Provider"]:::core
        click SM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.shortcut_provider.js"
        PLM["Plugin Manager"]:::core
        click PLM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.plugin.js"
        CM["Core Entry (mind controller)"]:::core
        click CM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.mind.js"
        NM["Node Model"]:::core
        click NM "https://github.com/hizzgdev/jsmind/blob/master/src/jsmind.node.js"
    end

    %% Plugins
    subgraph "Plugins" 
        style P fill:#e0f7e0,stroke:#5cb85c
        DRAG["Draggable‑Node Plugin"]:::plugin
        click DRAG "https://github.com/hizzgdev/jsmind/blob/master/src/plugins/jsmind.draggable-node.js"
        SCREEN["Screenshot Plugin"]:::plugin
        click SCREEN "https://github.com/hizzgdev/jsmind/blob/master/src/plugins/jsmind.screenshot.js"
    end

    %% Build & Distribution
    subgraph "Build & Distribution" 
        ROLL["Rollup Configuration"]:::build
        click ROLL "https://github.com/hizzgdev/jsmind/blob/master/.config/rollup.config.js"
        PKG["NPM Package Definition"]:::build
        click PKG "https://github.com/hizzgdev/jsmind/blob/master/package.json"
        SRC["Source Modules & Plugins"]:::build
        ES6["ES6 Build Outputs"]:::build
        click ES6 "https://github.com/hizzgdev/jsmind/blob/master/es6/README.md"
        JS["UMD/CommonJS Build Outputs"]:::build
        click JS "https://github.com/hizzgdev/jsmind/blob/master/js/README.md"
        LEG["Legacy JS Build (UMD)"]:::build
        click LEG "https://github.com/hizzgdev/jsmind/blob/master/js-legacy/jsmind.js"
        LEG_PLUG1["Legacy Draggable‑Node Build"]:::build
        click LEG_PLUG1 "https://github.com/hizzgdev/jsmind/blob/master/js-legacy/jsmind.draggable-node.js"
        LEG_PLUG2["Legacy Screenshot Build"]:::build
        click LEG_PLUG2 "https://github.com/hizzgdev/jsmind/blob/master/js-legacy/jsmind.screenshot.js"
        SRC --> ES6
        SRC --> JS
        SRC --> LEG
        SRC --> LEG_PLUG1
        SRC --> LEG_PLUG2
        ROLL --> SRC
        PKG --> SRC
    end

    %% Documentation & Tests
    subgraph "Documentation & Tests"
        DOC_EN["Docs (EN)"]:::misc
        click DOC_EN "https://github.com/hizzgdev/jsmind/blob/master/docs/en/index.md"
        DOC_ZH["Docs (ZH)"]:::misc
        click DOC_ZH "https://github.com/hizzgdev/jsmind/blob/master/docs/zh/index.md"
        STYLE["CSS Themes"]:::misc
        click STYLE "https://github.com/hizzgdev/jsmind/blob/master/style/jsmind.css"
        subgraph "Unit Tests"
            UT_DP["data_provider.test.js"]:::misc
            click UT_DP "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.data_provider.test.js"
            UT_GM["graph.test.js"]:::misc
            click UT_GM "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.graph.test.js"
            UT_LP["layout_provider.test.js"]:::misc
            click UT_LP "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.layout_provider.test.js"
            UT_VP["view_provider.test.js"]:::misc
            click UT_VP "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.view_provider.test.js"
            UT_DA["dom.test.js"]:::misc
            click UT_DA "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.dom.test.js"
            UT_UM["util.test.js"]:::misc
            click UT_UM "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.util.test.js"
            UT_OM["option.test.js"]:::misc
            click UT_OM "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.option.test.js"
            UT_PLM["plugin.test.js"]:::misc
            click UT_PLM "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.plugin.test.js"
            UT_SM["shortcut_provider.test.js"]:::misc
            click UT_SM "https://github.com/hizzgdev/jsmind/blob/master/tests/unit/jsmind.shortcut_provider.test.js"
        end
        subgraph "Legacy Tests"
            LT_CM["mind.test.js"]:::misc
            click LT_CM "https://github.com/hizzgdev/jsmind/blob/master/tests/legacy/jsmind.mind.test.js"
            LT_NM["node.test.js"]:::misc
            click LT_NM "https://github.com/hizzgdev/jsmind/blob/master/tests/legacy/jsmind.node.test.js"
            LT_UM2["util.test.js"]:::misc
            click LT_UM2 "https://github.com/hizzgdev/jsmind/blob/master/tests/legacy/jsmind.util.test.js"
        end
    end

    %% Relationships
    CA -->|"new jsMind()"| CM
    CM --> DP
    CM --> FM
    DP --> GM
    GM --> LP
    LP --> VP
    VP --> DA
    DA -->|user events| CM
    CM --> UM
    CM --> OM
    CM --> SM
    CM --> PLM
    PLM --> DRAG
    PLM --> SCREEN
    PLM -.-> DP
    PLM -.-> GM
    PLM -.-> LP
    PLM -.-> VP
    PLM -.-> DA

    %% Styles
    classDef core fill:#cce5ff,stroke:#004085,color:#004085;
    classDef plugin fill:#e0f7e0,stroke:#5cb85c,color:#3c763d;
    classDef build fill:#ffe5b4,stroke:#b36b00,color:#8a6d3b;
    classDef misc fill:#f2f2f2,stroke:#ccc,color:#636363;
```
