# sameergoyal/diagrammer architecture

> Architecture diagram of the GitHub repository sameergoyal/diagrammer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sameergoyal/diagrammer
- Repository: https://github.com/sameergoyal/diagrammer

## Overview

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: [`src/state/ActionDispatcher.ts`](https://github.com/sameergoyal/diagrammer/blob/master/src/state/ActionDispatcher.ts) (Dispatcher), [`src/service/ui/UIEventManager.ts`](https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UIEventManager.ts) (UI Events), [`src/state/createStore.ts`](https://github.com/sameergoyal/diagrammer/blob/master/src/state/createStore.ts) (Store), [`src/components/view/ConnectedView.ts`](https://github.com/sameergoyal/diagrammer/blob/master/src/components/view/ConnectedView.ts) (Connected View)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_src_index["Entry<br/>barrel<br/>[index.ts]"]
  node_diagrammer_ts["Diagrammer<br/>facade<br/>[Diagrammer.ts]"]
  node_diagrammer_api["API Service<br/>service api<br/>[DiagrammerApi.ts]"]
end

subgraph group_state["State Core"]
  node_store["Store<br/>[createStore.ts]"]
  node_initial_state["Initial State<br/>bootstrap<br/>[getInitialState.ts]"]
  node_dispatcher["Dispatcher<br/>action router"]
  node_node_state["Node State<br/>domain reducer<br/>[nodeReducer.ts]"]
  node_edge_state["Edge State<br/>domain reducer<br/>[edgeReducer.ts]"]
  node_layout_state["Layout<br/>[layoutReducer.ts]"]
  node_plugin_state["Plugins<br/>extension state<br/>[pluginReducer.ts]"]
  node_mode_filters["Mode Filters<br/>policy layer<br/>[rootEventFilter.ts]"]
end

subgraph group_ui["UI Layer"]
  node_connected_view["Connected View<br/>react bridge<br/>[ConnectedView.ts]"]
  node_workspace_view["Workspace<br/>[Workspace.tsx]"]
  node_canvas_view["Canvas<br/>render surface<br/>[Canvas.tsx]"]
  node_graph_primitives["Primitives<br/>[index.ts]"]
  node_panel_menu["Panels & Menu<br/>ui chrome<br/>[Panel.tsx]"]
end

subgraph group_services["Services"]
  node_config_service["Config<br/>[ConfigService.ts]"]
  node_ui_event_manager["UI Events<br/>event boundary<br/>[UIEventManager.ts]"]
  node_ui_event_normalizer["Event Norm<br/>normalizer"]
  node_ui_target_normalizer["Target Norm<br/>normalizer"]
  node_observer_utils["Observers<br/>utility services<br/>[Observer.ts]"]
end

subgraph group_docs["Docs & Verification"]
  node_storybook_docs["Storybook<br/>docs site<br/>[Introduction.mdx]"]
  node_integration_demos["Demos<br/>sample scenarios<br/>[demos.stories.ts]"]
  node_e2e_tests["Cypress<br/>e2e suite<br/>[index.cy.ts]"]
end

node_src_index -->|"exports"| node_diagrammer_ts
node_src_index -->|"exports"| node_diagrammer_api
node_diagrammer_ts -->|"uses"| node_config_service
node_diagrammer_api -->|"configures"| node_config_service
node_diagrammer_ts -->|"creates"| node_store
node_store -->|"seeds"| node_initial_state
node_store -->|"wires"| node_dispatcher
node_dispatcher -->|"routes"| node_node_state
node_dispatcher -->|"routes"| node_edge_state
node_dispatcher -->|"routes"| node_layout_state
node_dispatcher -->|"routes"| node_plugin_state
node_dispatcher -->|"filters"| node_mode_filters
node_ui_event_manager -->|"normalizes"| node_ui_event_normalizer
node_ui_event_manager -->|"targets"| node_ui_target_normalizer
node_ui_event_manager -->|"dispatches"| node_dispatcher
node_connected_view -->|"renders"| node_workspace_view
node_workspace_view -->|"contains"| node_canvas_view
node_canvas_view -->|"draws"| node_graph_primitives
node_workspace_view -->|"hosts"| node_panel_menu
node_connected_view -->|"subscribes"| node_store
node_graph_primitives -->|"reads"| node_node_state
node_graph_primitives -->|"reads"| node_edge_state
node_layout_state -->|"positions"| node_graph_primitives
node_config_service -->|"selects"| node_layout_state
node_config_service -->|"governs"| node_mode_filters
node_observer_utils -->|"supports"| node_ui_event_manager
node_storybook_docs -->|"references"| node_integration_demos
node_integration_demos -->|"demonstrates"| node_connected_view
node_e2e_tests -->|"verifies"| node_connected_view

click node_src_index "https://github.com/sameergoyal/diagrammer/blob/master/src/index.ts"
click node_diagrammer_ts "https://github.com/sameergoyal/diagrammer/blob/master/src/Diagrammer.ts"
click node_diagrammer_api "https://github.com/sameergoyal/diagrammer/blob/master/src/service/DiagrammerApi.ts"
click node_config_service "https://github.com/sameergoyal/diagrammer/blob/master/src/service/ConfigService.ts"
click node_ui_event_manager "https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UIEventManager.ts"
click node_ui_event_normalizer "https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UIEventNormalizer.ts"
click node_ui_target_normalizer "https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UITargetNormalizer.ts"
click node_store "https://github.com/sameergoyal/diagrammer/blob/master/src/state/createStore.ts"
click node_initial_state "https://github.com/sameergoyal/diagrammer/blob/master/src/state/getInitialState.ts"
click node_dispatcher "https://github.com/sameergoyal/diagrammer/blob/master/src/state/ActionDispatcher.ts"
click node_node_state "https://github.com/sameergoyal/diagrammer/blob/master/src/state/node/nodeReducer.ts"
click node_edge_state "https://github.com/sameergoyal/diagrammer/blob/master/src/state/edge/edgeReducer.ts"
click node_layout_state "https://github.com/sameergoyal/diagrammer/blob/master/src/state/layout/layoutReducer.ts"
click node_plugin_state "https://github.com/sameergoyal/diagrammer/blob/master/src/state/plugin/pluginReducer.ts"
click node_mode_filters "https://github.com/sameergoyal/diagrammer/blob/master/src/state/mode/rootEventFilter.ts"
click node_connected_view "https://github.com/sameergoyal/diagrammer/blob/master/src/components/view/ConnectedView.ts"
click node_workspace_view "https://github.com/sameergoyal/diagrammer/blob/master/src/components/workspace/Workspace.tsx"
click node_canvas_view "https://github.com/sameergoyal/diagrammer/blob/master/src/components/canvas/Canvas.tsx"
click node_graph_primitives "https://github.com/sameergoyal/diagrammer/blob/master/src/components/index.ts"
click node_panel_menu "https://github.com/sameergoyal/diagrammer/blob/master/src/components/panel/Panel.tsx"
click node_observer_utils "https://github.com/sameergoyal/diagrammer/blob/master/src/service/observer/Observer.ts"
click node_storybook_docs "https://github.com/sameergoyal/diagrammer/blob/master/storybook/Introduction.mdx"
click node_integration_demos "https://github.com/sameergoyal/diagrammer/blob/master/integ/demos.stories.ts"
click node_e2e_tests "https://github.com/sameergoyal/diagrammer/blob/master/cypress/e2e/index.cy.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_index,node_diagrammer_ts,node_diagrammer_api toneBlue
class node_store,node_initial_state,node_dispatcher,node_node_state,node_edge_state,node_layout_state,node_plugin_state,node_mode_filters toneAmber
class node_connected_view,node_workspace_view,node_canvas_view,node_graph_primitives,node_panel_menu toneMint
class node_config_service,node_ui_event_manager,node_ui_event_normalizer,node_ui_target_normalizer,node_observer_utils toneRose
class node_storybook_docs,node_integration_demos,node_e2e_tests toneIndigo
```

## Components

### Public API

Library entrypoints and consumer-facing service boundary

- [Entry](https://github.com/sameergoyal/diagrammer/blob/master/src/index.ts): barrel · Top-level library export surface · `src/index.ts`
- [Diagrammer](https://github.com/sameergoyal/diagrammer/blob/master/src/Diagrammer.ts): facade · Main library facade component · `src/Diagrammer.ts`
- [API Service](https://github.com/sameergoyal/diagrammer/blob/master/src/service/DiagrammerApi.ts): service api · Consumer methods and imperative integration boundary · `src/service/DiagrammerApi.ts`

### State Core

Redux-style store, reducers, dispatchers, and policy layers

- [Store](https://github.com/sameergoyal/diagrammer/blob/master/src/state/createStore.ts): redux store · Store creation and reducer wiring · `src/state/createStore.ts`
- [Initial State](https://github.com/sameergoyal/diagrammer/blob/master/src/state/getInitialState.ts): bootstrap · Seeds the editor state tree · `src/state/getInitialState.ts`
- [Dispatcher](https://github.com/sameergoyal/diagrammer/blob/master/src/state/ActionDispatcher.ts): action router · Shared action dispatch and routing layer · `src/state/ActionDispatcher.ts`
- [Node State](https://github.com/sameergoyal/diagrammer/blob/master/src/state/node/nodeReducer.ts): domain reducer · Node data, actions, and potential-node preview state · `src/state/node/nodeReducer.ts`
- [Edge State](https://github.com/sameergoyal/diagrammer/blob/master/src/state/edge/edgeReducer.ts): domain reducer · Edge data, actions, and potential-edge preview state · `src/state/edge/edgeReducer.ts`
- [Layout](https://github.com/sameergoyal/diagrammer/blob/master/src/state/layout/layoutReducer.ts): layout pipeline · Workflow and hierarchical layout computation · `src/state/layout/layoutReducer.ts`
- [Plugins](https://github.com/sameergoyal/diagrammer/blob/master/src/state/plugin/pluginReducer.ts): extension state · Plugin-relevant state and extension hooks · `src/state/plugin/pluginReducer.ts`
- [Mode Filters](https://github.com/sameergoyal/diagrammer/blob/master/src/state/mode/rootEventFilter.ts): policy layer · Interaction filters such as read-only behavior · `src/state/mode/rootEventFilter.ts`

### UI Layer

React rendering tree and interaction surfaces

- [Connected View](https://github.com/sameergoyal/diagrammer/blob/master/src/components/view/ConnectedView.ts): react bridge · Bridges store state into the main visual tree · `src/components/view/ConnectedView.ts`
- [Workspace](https://github.com/sameergoyal/diagrammer/blob/master/src/components/workspace/Workspace.tsx): workspace shell · Top-level diagram workspace and viewport container · `src/components/workspace/Workspace.tsx`
- [Canvas](https://github.com/sameergoyal/diagrammer/blob/master/src/components/canvas/Canvas.tsx): render surface · Main drawing surface and background patterns · `src/components/canvas/Canvas.tsx`
- [Primitives](https://github.com/sameergoyal/diagrammer/blob/master/src/components/index.ts): diagram primitives · Nodes, edges, connectors, and potential elements · `src/components/index.ts`
- [Panels & Menu](https://github.com/sameergoyal/diagrammer/blob/master/src/components/panel/Panel.tsx): ui chrome · Side panels and context menu interactions · `src/components/panel/Panel.tsx`

### Services

Normalization, config, and utility services

- [Config](https://github.com/sameergoyal/diagrammer/blob/master/src/service/ConfigService.ts): runtime config · Centralized configuration and feature flags · `src/service/ConfigService.ts`
- [UI Events](https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UIEventManager.ts): event boundary · Coordinates browser and UI event normalization · `src/service/ui/UIEventManager.ts`
- [Event Norm](https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UIEventNormalizer.ts): normalizer · Converts raw UI events into consistent editor events · `src/service/ui/UIEventNormalizer.ts`
- [Target Norm](https://github.com/sameergoyal/diagrammer/blob/master/src/service/ui/UITargetNormalizer.ts): normalizer · Normalizes event targets across canvas, nodes, edges, and workspace · `src/service/ui/UITargetNormalizer.ts`
- [Observers](https://github.com/sameergoyal/diagrammer/blob/master/src/service/observer/Observer.ts): utility services · Environment checks, positioning, and change observation · `src/service/observer/Observer.ts`

### Docs & Verification

Storybook demos, integration samples, and tests

- [Storybook](https://github.com/sameergoyal/diagrammer/blob/master/storybook/Introduction.mdx): docs site · Interactive documentation and design references · `storybook/Introduction.mdx`
- [Demos](https://github.com/sameergoyal/diagrammer/blob/master/integ/demos.stories.ts): sample scenarios · Integration examples and styled demo setups · `integ/demos.stories.ts`
- [Cypress](https://github.com/sameergoyal/diagrammer/blob/master/cypress/e2e/index.cy.ts): e2e suite · End-to-end interaction verification · `cypress/e2e/index.cy.ts`

## Connections

- 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
