← 返回 Skills 市场
anderskev

React Flow Architecture

作者 Kevin Anderson · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ✓ 安全检测通过
191
总下载
0
收藏
1
当前安装
2
版本数
在 OpenClaw 中安装
/install react-flow-architecture
功能描述
Architectural guidance for building node-based UIs with React Flow. Use when designing flow-based applications, making decisions about state management, inte...
使用说明 (SKILL.md)

React Flow Architecture

When to Use React Flow

Good Fit

  • Visual programming interfaces
  • Workflow builders and automation tools
  • Diagram editors (flowcharts, org charts)
  • Data pipeline visualization
  • Mind mapping tools
  • Node-based audio/video editors
  • Decision tree builders
  • State machine designers

Consider Alternatives

  • Simple static diagrams (use SVG or canvas directly)
  • Heavy real-time collaboration (may need custom sync layer)
  • 3D visualizations (use Three.js, react-three-fiber)
  • Graph analysis with 10k+ nodes (use WebGL-based solutions like Sigma.js)

Decision workflow (gates)

Run this sequence before locking the stack or sprinting implementation. Skip only for throwaway prototypes.

  1. Name the interactions — List the top user actions (e.g. drag, connect, delete, group). Pass: Each action maps to a concrete React Flow callback you will implement (onNodesChange, onConnect, …).

  2. Classify scale — Estimate peak nodes (visible canvas or document total). Pass: Your range matches a row in Node Count Guidelines and you accept the listed strategy (e.g. onlyRenderVisibleElements when that row implies it).

  3. Place state — Choose local hooks, an external store, or Redux/other. Pass: One sentence states where persistence, undo, or cross-surface sync will live, or explicitly “not needed yet.”

  4. Re-check alternatives — If the use case matches Consider Alternatives, Pass: One sentence explains why React Flow still fits or which listed alternative you chose instead.

Architecture Patterns

Package Structure (xyflow)

@xyflow/system (vanilla TypeScript)
├── Core algorithms (edge paths, bounds, viewport)
├── xypanzoom (d3-based pan/zoom)
├── xydrag, xyhandle, xyminimap, xyresizer
└── Shared types

@xyflow/react (depends on @xyflow/system)
├── React components and hooks
├── Zustand store for state management
└── Framework-specific integrations

@xyflow/svelte (depends on @xyflow/system)
└── Svelte components and stores

Implication: Core logic is framework-agnostic. When contributing or debugging, check if issue is in @xyflow/system or framework-specific package.

State Management Approaches

1. Local State (Simple Apps)

// useNodesState/useEdgesState for prototyping
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);

Pros: Simple, minimal boilerplate Cons: State isolated to component tree

2. External Store (Production)

// Zustand store example
import { create } from 'zustand';

interface FlowStore {
  nodes: Node[];
  edges: Edge[];
  setNodes: (nodes: Node[]) => void;
  onNodesChange: OnNodesChange;
}

const useFlowStore = create\x3CFlowStore>((set, get) => ({
  nodes: initialNodes,
  edges: initialEdges,
  setNodes: (nodes) => set({ nodes }),
  onNodesChange: (changes) => {
    set({ nodes: applyNodeChanges(changes, get().nodes) });
  },
}));

// In component
function Flow() {
  const { nodes, edges, onNodesChange } = useFlowStore();
  return \x3CReactFlow nodes={nodes} onNodesChange={onNodesChange} />;
}

Pros: State accessible anywhere, easier persistence/sync Cons: More setup, need careful selector optimization

3. Redux/Other State Libraries

// Connect via selectors
const nodes = useSelector(selectNodes);
const dispatch = useDispatch();

const onNodesChange = useCallback((changes: NodeChange[]) => {
  dispatch(nodesChanged(changes));
}, [dispatch]);

Data Flow Architecture

User Input → Change Event → Reducer/Handler → State Update → Re-render
     ↓
[Drag node] → onNodesChange → applyNodeChanges → setNodes → ReactFlow
     ↓
[Connect]   → onConnect → addEdge → setEdges → ReactFlow
     ↓
[Delete]    → onNodesDelete → deleteElements → setNodes/setEdges → ReactFlow

Sub-Flow Pattern (Nested Nodes)

// Parent node containing child nodes
const nodes = [
  {
    id: 'group-1',
    type: 'group',
    position: { x: 0, y: 0 },
    style: { width: 300, height: 200 },
  },
  {
    id: 'child-1',
    parentId: 'group-1',  // Key: parent reference
    extent: 'parent',      // Key: constrain to parent
    position: { x: 10, y: 30 },  // Relative to parent
    data: { label: 'Child' },
  },
];

Considerations:

  • Use extent: 'parent' to constrain dragging
  • Use expandParent: true to auto-expand parent
  • Parent z-index affects child rendering order

Viewport Persistence

// Save viewport state
const { toObject, setViewport } = useReactFlow();

const handleSave = () => {
  const flow = toObject();
  // flow.nodes, flow.edges, flow.viewport
  localStorage.setItem('flow', JSON.stringify(flow));
};

const handleRestore = () => {
  const flow = JSON.parse(localStorage.getItem('flow'));
  setNodes(flow.nodes);
  setEdges(flow.edges);
  setViewport(flow.viewport);
};

Integration Patterns

With Backend/API

// Load from API
useEffect(() => {
  fetch('/api/flow')
    .then(r => r.json())
    .then(({ nodes, edges }) => {
      setNodes(nodes);
      setEdges(edges);
    });
}, []);

// Debounced auto-save
const debouncedSave = useMemo(
  () => debounce((nodes, edges) => {
    fetch('/api/flow', {
      method: 'POST',
      body: JSON.stringify({ nodes, edges }),
    });
  }, 1000),
  []
);

useEffect(() => {
  debouncedSave(nodes, edges);
}, [nodes, edges]);

With Layout Algorithms

import dagre from 'dagre';

function getLayoutedElements(nodes: Node[], edges: Edge[]) {
  const g = new dagre.graphlib.Graph();
  g.setGraph({ rankdir: 'TB' });
  g.setDefaultEdgeLabel(() => ({}));

  nodes.forEach((node) => {
    g.setNode(node.id, { width: 150, height: 50 });
  });

  edges.forEach((edge) => {
    g.setEdge(edge.source, edge.target);
  });

  dagre.layout(g);

  return {
    nodes: nodes.map((node) => {
      const pos = g.node(node.id);
      return { ...node, position: { x: pos.x, y: pos.y } };
    }),
    edges,
  };
}

Performance Scaling

Node Count Guidelines

Nodes Strategy
\x3C 100 Default settings
100-500 Enable onlyRenderVisibleElements
500-1000 Simplify custom nodes, reduce DOM elements
> 1000 Consider virtualization, WebGL alternatives

Optimization Techniques

\x3CReactFlow
  // Only render nodes/edges in viewport
  onlyRenderVisibleElements={true}

  // Reduce node border radius (improves intersect calculations)
  nodeExtent={[[-1000, -1000], [1000, 1000]]}

  // Disable features not needed
  elementsSelectable={false}
  panOnDrag={false}
  zoomOnScroll={false}
/>

Trade-offs

Controlled vs Uncontrolled

Controlled Uncontrolled
More boilerplate Less code
Full state control Internal state
Easy persistence Need toObject()
Better for complex apps Good for prototypes

Connection Modes

Strict (default) Loose
Source → Target only Any handle → any handle
Predictable behavior More flexible
Use for data flows Use for diagrams
\x3CReactFlow connectionMode={ConnectionMode.Loose} />

Edge Rendering

Default edges Custom edges
Fast rendering More control
Limited styling Any SVG/HTML
Simple use cases Complex labels
安全使用建议
This skill is an offline instruction document (no code executed by the platform). It is coherent and appropriate for designing React Flow apps. When you implement its examples, treat the fetch('/api/flow') endpoints and localStorage usage as placeholders: secure any backend endpoints, add authentication/authorization, and validate/sanitize persisted data. If you later adapt this guidance into code run by your agent or CI, review any new install scripts, network targets, and required credentials at that time.
能力评估
Purpose & Capability
Name and description match the SKILL.md content: architecture patterns, state strategies, integration examples for React Flow. No unrelated credentials, binaries, or installs are requested.
Instruction Scope
SKILL.md contains implementation guidance and example code (React/TypeScript snippets, localStorage, fetch examples). It does not instruct the agent to read arbitrary host files, access environment variables, or transmit data to external endpoints beyond illustrative API examples.
Install Mechanism
No install spec and no code files; the skill is instruction-only so nothing is written to disk or downloaded during install.
Credentials
The skill declares no required environment variables or credentials. Example code references localStorage and generic '/api/flow' endpoints as implementation examples — these are reasonable for the described purpose.
Persistence & Privilege
Skill is not always-on and uses default autonomous invocation settings. It does not request persistent system presence or modify other skills/config — nothing here implies elevated platform privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install react-flow-architecture
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /react-flow-architecture 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.1
- Added a "Decision workflow (gates)" section outlining a four-step checklist to assess React Flow fit before implementation. - The checklist covers mapping interactions to callbacks, estimating node counts, defining state placement, and verifying fit over alternatives. - No other content changes; all existing architecture guidance and examples are unchanged.
v1.1.0
Version 1.1.0 of react-flow-architecture introduces clear, actionable guidance for building node-based UIs with React Flow. - Lists use cases where React Flow excels and where alternatives should be considered. - Details package structure and core architectural patterns (including state management options and the distinction between @xyflow/system and framework wrappers). - Documents patterns for node/edge state handling (local state, Zustand, Redux), integrating with backends, viewport persistence, and layout algorithms. - Provides guidance on optimizing performance at various scales, including rendering strategies and feature toggles. - Explains advanced concepts such as sub-flow (nested node) architecture and trade-offs between controlled and uncontrolled components. - Outlines integration best practices and charts for important configuration trade-offs (connection modes, edge rendering, etc.).
元数据
Slug react-flow-architecture
版本 1.1.1
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 2
常见问题

React Flow Architecture 是什么?

Architectural guidance for building node-based UIs with React Flow. Use when designing flow-based applications, making decisions about state management, inte... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 191 次。

如何安装 React Flow Architecture?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install react-flow-architecture」即可一键安装,无需额外配置。

React Flow Architecture 是免费的吗?

是的,React Flow Architecture 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

React Flow Architecture 支持哪些平台?

React Flow Architecture 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 React Flow Architecture?

由 Kevin Anderson(@anderskev)开发并维护,当前版本 v1.1.1。

💬 留言讨论