Skip to content

API Reference

NodeUI is built on an event-driven, modular, class-based architecture. Every core system -- the canvas, nodes, edges, and collaboration layer -- communicates through a central event bus, keeping modules decoupled and extensible.

Architecture Overview

                    +----------------+
                    |  EventEmitter  |  (Global Pub/Sub Bus)
                    +-------+--------+
                            |
         +------------------+-------------------+
         |                  |                   |
   +-----+------+    +-----+------+    +-------+------+
   |   Canvas    |    |   Edges    |    | Collaboration|
   | (SVG render)|    | (drawing,  |    | (WebSocket   |
   |             |    |  routing)  |    |  sync)       |
   +-----+------+    +-----+------+    +--------------+
         |                  |
   +-----+------+    +-----+------+
   |   Nodes    |    |  BaseEdge  |
   | (BaseNode, |    | (path data,|
   |  subtypes) |    |  labels)   |
   +------------+    +------------+

Core Modules

ModuleFileResponsibility
EventEmittersrc/core/events.jsGlobal pub/sub bus for all inter-module communication
Canvassrc/core/canvas.jsSVG rendering, pan/zoom transforms, snap guides, selection
Edgessrc/core/edges.jsEdge drawing state, routing cuts, edge routing points
Collaborationsrc/core/collaboration.jsWebSocket sessions, state sync, presence
BaseNodesrc/nodes/basenode.jsBase class for all node types
BaseEdgesrc/nodes/baseedge.jsBase class for all edge types

Design Principles

Event-driven communication. Modules never call each other directly. A node move publishes node:moved, and any module that cares subscribes to it. This means you can add new behaviors (logging, collaboration sync, undo history) without modifying existing code.

Class-based extensibility. Nodes and edges use classical inheritance. BaseNode provides rendering, handles, and content editing. Specialized types like GroupNode, SubGraphNode, and ThreeJSNode extend it with custom behavior.

Zero dependencies at the core. The core architecture uses vanilla JavaScript with no framework or build tool. External libraries (Three.js, Marked.js) load on demand via CDN only when a node type requires them.

Rendering Layers

The canvas uses a layered rendering approach with four stacked layers:

LayerTechnologyContains
GridSVG with <pattern>Dot grid background
GroupsHTML <div>GroupNode containers
EdgesSVG <g>Edge paths, arrowheads, labels
NodesHTML <div>All node elements, selection box

All layers share the same translate and scale transform, keeping nodes and edges visually synchronized during pan and zoom.

State Storage

NodeUI stores graph state as a flat structure of nodes and edges:

javascript
// Nodes stored in a Map<string, BaseNode>
nodeUI.nodes.get('node-id')  // => BaseNode instance

// Edges stored in a Map<string, BaseEdge>
nodeUI.edges.get('edge-id')  // => BaseEdge instance

The graph serializes to JSON for file save/load and collaboration sync:

json
{
  "nodes": [
    { "id": "abc-123", "type": "BaseNode", "x": 100, "y": 200, "width": 200, "height": 120, "title": "My Node", "content": "Hello", "color": "yellow" }
  ],
  "edges": [
    { "id": "edge-456", "startNodeId": "abc-123", "endNodeId": "def-789", "startHandleId": "right", "endHandleId": "left" }
  ]
}

What is in This Section

Released under the MIT License.