This document describes the orchestration logic and execution flow of the n8n visual workflow builder system. The workflow engine coordinates multiple specialized agents (WorkflowExecutionAgent, NodeValidationAgent, CanvasManagerAgent, IntegrationAgent, and ExportImportAgent) to provide a seamless visual workflow creation and execution experience.
The system architecture centers around five core agents that handle different aspects of workflow management:
- WorkflowExecutionAgent: Orchestrates workflow execution and state management
- NodeValidationAgent: Ensures workflow integrity and validates configurations
- CanvasManagerAgent: Manages the visual interface and collaborative editing
- IntegrationAgent: Handles external service connections and API interactions
- ExportImportAgent: Manages workflow serialization and template operations
TODO: Provide high-level workflow architecture diagram showing agent interactions and data flow.
- Canvas Loading: Initialize ReactFlow canvas with saved state
- Agent Registration: Register all agents with the event bus system
- Service Connection: Establish connections to n8n API and external services
- State Restoration: Load previous workflow state and user preferences
- Validate workflow JSON schema compliance
- Check node parameter compatibility and required fields
- Verify connection integrity between nodes
- Assess performance impact and provide optimization suggestions
- Render visual workflow on the ReactFlow canvas
- Enable drag-and-drop functionality for nodes
- Manage collaborative editing sessions via WebSocket
- Handle undo/redo operations and state persistence
- Authenticate with external services and APIs
- Validate credential integrity and permissions
- Set up webhook endpoints for real-time triggers
- Configure rate limiting and quota management
- Node Branching: If/Else nodes that evaluate conditions and route execution paths
- Switch Operations: Multi-path routing based on data values or patterns
- Error Handling: Automatic fallback agents for failed node executions
- Loop Control: Iterative execution with conditional termination
- User Action → CanvasManagerAgent captures UI interaction
- Validation Request → NodeValidationAgent validates node configuration
- Integration Check → IntegrationAgent verifies external service connectivity
- State Update → Event bus broadcasts changes to all registered agents
- Persistence → ExportImportAgent saves workflow state
TODO: Add detailed flowcharts showing agent interaction patterns and decision trees.
- n8n JSON: Standard n8n workflow JSON format with full compatibility
- Node Parameters: Structured configuration data for each node type
- Canvas State: Visual layout and positioning information
- User Credentials: Encrypted authentication data for external services
- Schema Validation: JSON Schema validation against n8n workflow specification
- Node Resolution: Resolve node types and validate parameter schemas
- Connection Mapping: Build execution graph from visual connections
- Dependency Analysis: Determine topological execution order
- State Initialization: Set up execution context and variable scoping
- n8n Workflow JSON: Export-compatible workflow definitions
- Execution Results: Structured output from workflow runs
- Canvas State: Visual layout and node positioning data
- Template Files: Reusable workflow templates for sharing
The system maintains real-time data synchronization through:
- WebSocket Updates: Live collaboration and state synchronization
- Event-driven Architecture: Reactive updates triggered by agent actions
- State Management: Centralized state management via Zustand stores
- Optimistic Updates: Immediate UI feedback with server reconciliation
- System Errors: Infrastructure and platform failures
- Agent Errors: Individual agent processing failures
- Data Errors: Invalid input or corrupted data issues
- Timeout Errors: Processing deadlines exceeded
- Exponential Backoff: Progressive delay between retry attempts
- Maximum Attempts: Configurable retry limits per operation type
- Retry Conditions: Define which errors should trigger retries
- Circuit Breaker: Prevent cascade failures in distributed systems
- Alternative Agents: Backup agents for critical operations
- Graceful Degradation: Continue with reduced functionality
- Default Values: Provide sensible defaults when operations fail
- Manual Override: Human intervention points for complex failures
- Structured Logging: Consistent error format across all components
- Metrics Collection: Performance and error rate tracking
- Alert Configuration: Automated notifications for critical failures
- Error Correlation: Link related errors across the workflow
TODO: Define specific error codes, recovery procedures, and monitoring dashboards.