Flow Studio
workflowStore Overview
workflowStore is the central Zustand store holding the canvas graph — nodes, edges, and viewport. It is the single source of truth: React Flow reads from it, and all canvas mutations go through its actions.
Role in the System
The Flow Studio canvas is built on React Flow, but React Flow is not the source of truth. workflowStore is. All canvas state — which nodes exist, where they are positioned, how they are connected — lives in workflowStore. React Flow renders whatever workflowStore says.
| Concern | Owner |
|---|---|
| Canvas graph state (nodes, edges) | workflowStore |
| Canvas mode (design / execution / readonly) | designerModeStore |
| Observer Panel UI state | flowObserverPanelStore |
| Live execution data (statuses, logs) | executionStore |
| Undo/redo history | historyMiddleware (wraps workflowStore) |
Store Architecture
// workflowStore.ts (simplified)
import { create } from 'zustand';
import { historyMiddleware } from './history/historyMiddleware';
export interface WorkflowState {
nodes : WorkflowNode[];
edges : WorkflowEdge[];
viewport : Viewport;
selectedNodes : string[];
selectedEdges : string[];
processId : string | null;
}
export interface WorkflowActions {
// Node mutations
addNode : (node: WorkflowNode) => void;
updateNode : (id: string, patch: Partial<WorkflowNode>) => void;
removeNode : (id: string) => void;
moveNode : (id: string, position: XYPosition) => void;
selectNode : (id: string | null) => void;
// Edge mutations
addEdge : (edge: WorkflowEdge) => void;
updateEdge : (id: string, patch: Partial<WorkflowEdge>) => void;
removeEdge : (id: string) => void;
setEdgeLabel : (id: string, label: string) => void;
// Viewport
setViewport : (vp: Viewport) => void;
fitView : () => void;
zoomIn : () => void;
zoomOut : () => void;
// Persistence
loadWorkflow : (processId: string) => Promise<void>;
saveWorkflow : () => Promise<void>;
serializeWorkflow : () => SerializedWorkflow;
}
export const useWorkflowStore = create<WorkflowState & WorkflowActions>()(
historyMiddleware(
(set, get) => ({
nodes: [], edges: [], viewport: defaultViewport,
selectedNodes: [], selectedEdges: [], processId: null,
// ... action implementations
})
)
);
What This Guide Covers
| Page | Topic |
|---|---|
| Store State Shape | nodes, edges, viewport, selectedNodes, selectedEdges, processId |
| Node Actions | addNode, updateNode, removeNode, moveNode, selectNode |
| Edge Actions | addEdge, updateEdge, removeEdge, setEdgeLabel |
| Viewport Actions | setViewport, fitView, zoomIn, zoomOut |
| Subscribing to Slices | Selector pattern, shallow equality, performance |
| Persistence | serializeWorkflow, deserializeWorkflow, auto-save |
| React Flow Sync | How workflowStore syncs with ReactFlow's internal state |
History middleware: workflowStore is wrapped in the
historyMiddleware Zustand middleware. This gives the store undo/redo capabilities. See Guide27_UndoRedoHistory for the full history system documentation.