reactflow-workflow
DevelopmentBuild and harden React Flow diagram surfaces in VeloxDB using @xyflow/react patterns (nodes, edges, viewport, controls, interactions, performance). Use when working on schema diagram canvas behavior, replacing legacy canvas code, or improving diagram UX and scale.
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/veloxbase/veloxdb/blob/HEAD/.cursor/skills/reactflow-workflow/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/reactflow-workflow, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
React Flow Workflow
Use this skill when implementing or improving the schema diagram surface in VeloxDB.
Quick Start
- Keep
@xyflow/reactstyles imported once in the React Flow canvas module. - Ensure the canvas parent has explicit width and height.
- Keep model state ownership in
ModelWorkspace; keepReactFlowCanvasmostly presentational and interaction-focused. - Use
DiagramSurfacePropsas the boundary contract between workspace state and rendering.
VeloxDB Diagram Architecture
src/features/model/components/ModelWorkspace.tsx:- owns diagram state (viewport, selection, on-canvas tables, pending FKs, groups)
- computes display props and passes them into
DiagramSurfaceAdapter
src/features/model/components/DiagramSurfaceAdapter.tsx:- forwards
DiagramSurfacePropstoReactFlowCanvas
- forwards
src/features/model/components/ReactFlowCanvas.tsx:- renders React Flow nodes/edges, connects events to workspace callbacks, and exposes export handle
Keep this separation intact; avoid pushing workspace orchestration logic into the canvas.
React Flow Implementation Patterns
-
Nodes:
- Use memoized custom node components for table rendering.
- Keep node
dataminimal and serializable. - Derive
draggable,selected, and connectability from current tool mode.
-
Edges:
- Use routed edge points from
buildRoutedDiagramEdges. - Keep pending edges visually distinct (dash + stronger color).
- Prefer custom edge component only when built-in edges cannot represent routed geometry.
- Use routed edge points from
-
Connections:
- Gate with
isValidConnectionto block invalid or duplicate FK links. - Parse handles with stable prefixes (
in:/out:) to identify columns.
- Gate with
-
Viewport & controls:
- Persist viewport to workspace via callback.
- Throttle high-frequency viewport updates to avoid rerender storms.
- Provide explicit fit actions (all and selection) in controls.
-
Tool modes:
- Select mode: selection + table dragging.
- Pan mode: canvas drag panning.
- Connect mode: handle-to-handle links; no accidental pan.
- Space key temporarily enables panning in any mode.
UX and Styling Guidance
- Use design tokens (
--diagram-table-header,--border,--muted-foreground) for node and edge visuals. - Keep minimap/background enabled; they improve navigation on medium/large models.
- Show concise mode hints in-canvas when interaction mode changes.
- Keep selected state and focus state obvious for keyboard + mouse users.
Performance Guardrails
- Memoize mapped nodes/edges from workspace props.
- Avoid rebuilding heavy arrays on unrelated state changes.
- Throttle viewport persistence callbacks.
- Keep columns bounded for node rendering (
MAX_ROWSstyle cap). - Avoid unnecessary
useEffect; prefer derived state and event callbacks.
Change Checklist
- Confirm no renderer fallback code is reintroduced.
- Verify interactions: select, pan, connect, marquee, drag, delete/clear.
- Verify controls: zoom, fit all, fit selection, reset behavior.
- Verify exports (PNG/PDF) still work from current viewport/container.
- Run lint/type checks after editing diagram components.
Reference
- React Flow Learn: https://reactflow.dev/learn