What is a Workflow?
Think of a workflow as a graph where:- Nodes are the vertices (operations)
- Connections are the edges (data flow)
- Execution follows the topological order
Creating a Workflow
Workflow Properties
string
Unique identifier for the workflow
string
Human-readable name for the workflow
Map<string, Node>
Collection of all nodes in the workflow
Connection[]
Array of connections between nodes
Record<string, any>
Global variables accessible during execution
Adding Nodes
There are several ways to add nodes to a workflow:From Class
From Type String
Setting Initial Values
Connecting Nodes
Connections define how data flows between nodes:Connection Example
Multiple Connections
One output can connect to multiple inputs:Disconnecting Nodes
Remove connections between nodes:Removing Nodes
Remove a node and all its connections:Workflow Validation
Validate the workflow before execution:Validation Checks
Cycle Detection
Cycle Detection
Ensures there are no circular dependencies in the workflow
Connection Validation
Connection Validation
Verifies all connections are valid (ports exist, types compatible)
Required Inputs
Required Inputs
Checks that all required inputs are connected or have values
Type Compatibility
Type Compatibility
Ensures connected ports have compatible types
Execution Order
Workflows execute nodes in topological order:- Identify nodes with no dependencies (entry points)
- Execute those nodes
- Propagate data to connected nodes
- Repeat until all nodes are executed
Workflow Variables
Global variables can be accessed by all nodes:Serialization
Workflows can be serialized to/from JSON:To JSON
From JSON
JSON Format
Workflow Lifecycle
1
Creation
Create a new workflow instance
2
Building
Add nodes and create connections
3
Validation
Validate the workflow structure
4
Execution
Execute nodes in topological order
5
Results
Collect and process execution results
Best Practices
Validate Before Execution
Validate Before Execution
Always validate workflows before executing to catch structural issues early.
Use Meaningful IDs
Use Meaningful IDs
Consider using descriptive IDs for nodes to make debugging easier.
Handle Cycles
Handle Cycles
Design workflows without circular dependencies. CrystalFlow will detect and reject cycles.
Test Incrementally
Test Incrementally
Build and test workflows incrementally, adding nodes one at a time.
Document Workflows
Document Workflows
Add names and descriptions to workflows for better maintainability.
Example: Data Processing Workflow
Next Steps
Execution Engine
Learn how workflows are executed
Workflow Builder
Build visual workflow interfaces
Serialization
Save and load workflows as JSON
API Reference
Complete Workflow API docs