How reaviz/reaflow works
Project type and purpose
• It exposes a single high-level API (<Canvas> component) to which consumer apps supply graph data (nodes/edges) and custom symbol components.
File structure
• Top-level:
• Configuration (.eslintrc, tsconfig.json, .storybook, GitHub workflows)
• src/ – the library source (core component, layout, helpers, symbols, utils, types)
• stories/ – Storybook stories showcasing usage examples
• docs/ – documentation and code sandbox templates
• test/ & src/**/*.test.ts – unit tests
• Key patterns:
• src/layout – integration with ELKJS for automatic graph layout
• src/helpers & src/utils – custom React hooks and utility functions (undo/redo, drag, zoom, selection, proximity)
README for additional insights
• Confirms core features: automatic layout, interactions (drag, zoom, pan), nesting, selection, undo/redo, helper abstractions for proximity linking.
• Primary export: Canvas – consumes props (nodes, edges, layout, helpers, event callbacks).
• Development uses Storybook for live examples, GitHub Actions for build and npm publish.
a. Main components
• Consumer Application (user’s React app)
• Reaflow Library
· API Layer: <Canvas> and exported hooks
· Core Engine: CanvasProvider, GraphRenderer, Contexts
· Layout Module: elkLayout (ELKJS wrapper) + useLayout
· Helper Hooks: useZoom, useNodeDrag, useEdgeDrag, useSelection, useProximity, useUndo
· Utilities: shared helper functions, types
• External Services/Dependencies
· ELKJS (layout engine)
· React / ReactDOM
· Testing (Jest)
· Storybook
· CI/CD (GitHub Actions → npm registry)
b. Relationships & interactions
• Consumer passes graph data and configuration into <Canvas>.
• CanvasProvider initializes context and state (nodes, edges, history stack).
• GraphRenderer invokes layout module (ELKJS) or custom layout, computes node/edge positions.
• Symbol components render based on computed positions.
• Helper hooks listen to user events (drag, click, wheel), update context state, trigger re‐renders or layout recalculations.
• Undo/redo hook wraps state updates.
• External services: CI builds/publishes package; Storybook loads the library in an isolated env.
c. Architectural patterns & design principles
• Modular design: symbols, helpers, layout are pluggable.
• Single Context Provider to share state across components.
• Hook-based abstractions for interactivity.
• Separation of concerns: layout vs. rendering vs. interaction vs. API.
• Extensibility: consumers can supply custom node/edge components or override helpers.
d. Key technologies & frameworks
• React & React Hooks
• TypeScript
• ELKJS for graph layout
• Storybook for interactive docs
• Jest for unit tests
• Vite for bundling
Diagramming recommendations
• Use clear labels: “Consumer App,” “Canvas API,” “Layout Module,” “Symbol Components,” “Helper Hooks,” “Context Provider,” “External Services.”
• App → Canvas API → Context → Layout & Render → Browser
• User events → Helper Hooks → Context updates → Re‐render
• Green for external dependencies (ELKJS, React)
• Orange for dev tools (Storybook, CI/CD)
• Related modules visually (e.g., wrap all hooks in a “Helpers” container)