How sameergoyal/diagrammer works
1. What this repo is
Diagrammer is a TypeScript/React-based library for rendering and editing graph-like diagrams. It is not an application; it is a reusable editor framework that consumers embed into their own products.
2. Public entrypoints and configuration
The main API surface lives in src/index.ts, src/Diagrammer.ts, and src/service/DiagrammerApi.ts. ConfigService centralizes runtime options and feature flags, so consumers configure behavior, layout, interaction, and customization through a single library boundary.
3. Core state architecture
The editor is organized around a Redux-style store under src/state. State is split by domain: node, edge, panel, workspace, layout, editor, global, plugin, and mode. getInitialState seeds the store, and createStore wires reducers and middleware together.
4. State flow from actions to rendering
User interactions and API calls are converted into actions, dispatched through domain-specific action dispatchers, reduced into state updates, and then reflected back into the UI through connected components. This is the central loop of the system: input -> action -> reducer -> store -> React render.
5. Event normalization and input boundary
Raw browser/UI events are normalized in src/service/ui by UIEventManager, UIEventNormalizer, and UITargetNormalizer. This layer shields the rest of the app from low-level event details and makes input handling consistent across canvas, nodes, edges, and workspace interactions.
6. Rendering layer
The visual editor is built from React components in src/components. Major UI subsystems are workspace, view, canvas, node, edge, connector, panel, selectionMarquee, and contextMenu. ConnectedView bridges store state to the main visual tree.
7. Canvas and diagram primitives
The canvas subsystem handles the main drawing surface and background patterns (DotPattern, GridPattern). Nodes, edges, connectors, and “potential” elements are rendered as separate primitives so the editor can show both committed graph elements and interactive previews during drag/create operations.
8. Layout subsystem
Layout is isolated under src/state/layout, with separate workflow and hierarchical layout logic. This suggests diagram arrangement is computed as a distinct concern from rendering, allowing the same graph data to be laid out differently depending on configuration or diagram type.
9. Interaction features and editing modes
The editor supports read-only filtering, selection marquess, edge/node creation previews, and context menus. The mode subtree contains event filters, which act as a policy layer to enable/disable interaction classes without rewriting UI components.
10. Middleware and extensibility
undoMiddleware provides history support, and createInterceptorMiddleware enables plugin-style interception of actions. The plugin state and ActionInterceptor integration demos indicate the library is designed for extensibility and consumer-defined behavior hooks.
11. Support services
Utility services such as browserUtils, positionUtils, and observer support environment checks, coordinate calculations, and change observation. There is also a small polyfill layer, implying the library targets browsers with some compatibility concerns.
12. Documentation, demos, and verification
The repo uses Storybook for documentation and interactive demos, Cypress for end-to-end interaction tests, and Jest for unit/component tests and snapshots. The integ folder contains demo stories and sample styles/data, which act as architecture references for how the library is meant to be composed by consumers.
13. Build and release shape
The project is packaged as a library with webpack build config, npm publishing metadata, and GitHub Actions for build/test and docs deployment. This reinforces that the primary output is a distributable component library plus documentation site, not a standalone runtime service.
Main entry points: ActionDispatcher.ts Dispatcher · UIEventManager.ts UI Events · createStore.ts Store · ConnectedView.ts Connected View
Components 24
Public API
Library entrypoints and consumer-facing service boundary
- Entry · Top-level library export surface
src/index.ts - Diagrammer · Main library facade component
src/Diagrammer.ts - API Service · Consumer methods and imperative integration boundary
src/service/DiagrammerApi.ts
State Core
Redux-style store, reducers, dispatchers, and policy layers
- Store · Store creation and reducer wiring
src/state/createStore.ts - Initial State · Seeds the editor state tree
src/state/getInitialState.ts - Dispatcher · Shared action dispatch and routing layer
src/state/ActionDispatcher.ts - Node State · Node data, actions, and potential-node preview state
src/state/node/nodeReducer.ts - Edge State · Edge data, actions, and potential-edge preview state
src/state/edge/edgeReducer.ts - Layout · Workflow and hierarchical layout computation
src/state/layout/layoutReducer.ts - Plugins · Plugin-relevant state and extension hooks
src/state/plugin/pluginReducer.ts - Mode Filters · Interaction filters such as read-only behavior
src/state/mode/rootEventFilter.ts
UI Layer
React rendering tree and interaction surfaces
- Connected View · Bridges store state into the main visual tree
src/components/view/ConnectedView.ts - Workspace · Top-level diagram workspace and viewport container
src/components/workspace/Workspace.tsx - Canvas · Main drawing surface and background patterns
src/components/canvas/Canvas.tsx - Primitives · Nodes, edges, connectors, and potential elements
src/components/index.ts - Panels & Menu · Side panels and context menu interactions
src/components/panel/Panel.tsx
Services
Normalization, config, and utility services
- Config · Centralized configuration and feature flags
src/service/ConfigService.ts - UI Events · Coordinates browser and UI event normalization
src/service/ui/UIEventManager.ts - Event Norm · Converts raw UI events into consistent editor events
src/service/ui/UIEventNormalizer.ts - Target Norm · Normalizes event targets across canvas, nodes, edges, and workspace
src/service/ui/UITargetNormalizer.ts - Observers · Environment checks, positioning, and change observation
src/service/observer/Observer.ts
Connections 29
- Entry → Diagrammer: exports · Public entrypoint exposes the main facade
- Entry → API Service: exports · Public entrypoint exposes the imperative API
- Diagrammer → Config: uses · Facade reads runtime options and feature flags
- API Service → Config: configures · API boundary applies consumer configuration
- Diagrammer → Store: creates · Main component initializes the store
- Store → Initial State: seeds · Store initialization starts from default state
- Store → Dispatcher: wires · Store is connected to action dispatchers
- Dispatcher → Node State: routes · Actions are routed to node domain reducers
- Dispatcher → Edge State: routes · Actions are routed to edge domain reducers
- Dispatcher → Layout: routes · Actions are routed to layout computations
- Dispatcher → Plugins: routes · Actions can be intercepted or extended by plugins
- Dispatcher → Mode Filters: filters · Interaction policy filters actions before state changes
- UI Events → Event Norm: normalizes · Raw events are normalized into editor events
- UI Events → Target Norm: targets · Targets are normalized for diagram hit testing
- UI Events → Dispatcher: dispatches · Normalized interactions become editor actions
- Connected View → Workspace: renders · Connected view composes the workspace shell
- Workspace → Canvas: contains · Workspace includes the main drawing surface
- Canvas → Primitives: draws · Canvas renders nodes, edges, connectors, and previews
- Workspace → Panels & Menu: hosts · Workspace also hosts panels and contextual UI
- Connected View → Store: subscribes · View tree reflects store state changes
- Primitives → Node State: reads · Node primitives render from node domain state
- Primitives → Edge State: reads · Edge primitives render from edge domain state
- Layout → Primitives: positions · Layout results feed primitive placement
- Config → Layout: selects · Configuration determines layout mode and behavior
- Config → Mode Filters: governs · Configuration can enable read-only or interaction modes
- Observers → UI Events: supports · Utilities assist event and environment handling
- Storybook → Demos: references · Docs showcase the integration examples
- Demos → Connected View: demonstrates · Demos illustrate how consumers embed the library
- Cypress → Connected View: verifies · E2E tests exercise the main interactive view