Principle:Langgenius Dify Node Graph Composition
| Knowledge Sources | Dify |
|---|---|
| Domains | Workflow, DAG, Frontend |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Description
Node Graph Composition is the principle that defines how Dify workflows are structured as directed acyclic graphs (DAGs) of typed processing nodes. Every workflow is composed of nodes (vertices) connected by edges (directed links), where each node represents a discrete processing step with a specific BlockEnum type. The visual graph editor is built on top of the ReactFlow library, which provides the canvas, node positioning, edge routing, and interaction model.
The Dify platform defines a comprehensive set of node types through the BlockEnum enumeration, covering the full spectrum of workflow operations:
- Control Flow: Start, End, Answer, IfElse, QuestionClassifier, Iteration, Loop, HumanInput
- Data Processing: LLM, Code, TemplateTransform, HttpRequest, KnowledgeRetrieval, DocExtractor, ListFilter
- Variable Management: VariableAssigner, VariableAggregator, Assigner
- Integration: Tool, Agent, DataSource, KnowledgeBase
- Triggers: TriggerSchedule, TriggerWebhook, TriggerPlugin
Each node in the graph conforms to the CommonNodeType interface, which provides the shared structure for all node types including metadata (title, description, type), layout (position, width, height), runtime state (running status, iteration index), and error handling configuration.
Usage
When composing a workflow graph:
- Select node types from the BlockEnum enumeration and add them to the canvas.
- Connect nodes via directed edges to establish data flow and execution order.
- Each node's CommonNodeType provides both persistent configuration (title, desc, type, error_strategy) and transient UI state (prefixed with underscore, e.g., _runningStatus, _isCandidate).
- Nodes can be nested inside container nodes (Iteration, Loop) via the isInIteration/isInLoop flags and corresponding iteration_id/loop_id references.
- The graph is serialized as
{ nodes: Node[], edges: Edge[], viewport: Viewport }for persistence.
Theoretical Basis
This principle is based on:
- Directed Acyclic Graph (DAG) Computation: The workflow graph enforces acyclicity (except within explicit Loop/Iteration containers) to guarantee termination and enable topological execution ordering. This is the same model used by Apache Airflow, Prefect, and similar pipeline orchestrators.
- Component-Based Node Architecture: Each BlockEnum value maps to a self-contained component with its own configuration panel, validation logic, and output schema. This follows the Strategy pattern, where the node type selects the concrete processing strategy at runtime.
- ReactFlow Integration: By extending ReactFlow's
Node<T>andEdge<T>generic types with Dify-specific data (CommonNodeTypeandCommonEdgeType), the platform inherits battle-tested graph rendering, interaction handling, and layout algorithms while maintaining full control over the business logic layer. - Convention over Configuration: Transient UI-only properties are prefixed with an underscore (e.g.,
_runningStatus,_isBundled) to distinguish them from persistent node configuration. This convention prevents accidental serialization of ephemeral state.