Workflow Management
Relevant source files
The following files were used as context for generating this wiki page:
- packages/frontend/editor-ui/src/utils/templates/samples/agents/task_management_agent_with_google_sheets.json
- packages/frontend/editor-ui/src/Interface.ts
- packages/frontend/editor-ui/src/constants.ts
- packages/@n8n/db/src/repositories/workflow.repository.ts
- packages/nodes-base/nodes/Start/Start.node.json
- packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json
- packages/nodes-base/nodes/If/If.node.json
- packages/nodes-base/nodes/Cron/Cron.node.json
- packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/ExecuteWorkflow.node.json
A workflow is the core concept in n8n, representing an automated process defined by a series of connected nodes. Each workflow is a data-driven graph where nodes perform specific tasks, such as triggering the flow, manipulating data, or integrating with external services. Workflows are stored as JSON objects and managed through a dedicated repository layer that interacts with the database.
Workflow execution can be initiated in various ways: manually, via a schedule (e.g., Cron), or through external events captured by trigger nodes like Webhooks. The system is designed to be modular, allowing complex processes to be broken down into smaller, reusable sub-workflows.
Workflow Structure
A workflow is defined by a JSON object with several key top-level properties. These properties describe the workflow's metadata, its constituent nodes, the connections that define the data flow, and its operational settings.
This diagram illustrates the main components of a workflow's JSON structure.
A typical workflow JSON structure is as follows:
{
"name": "Task management agent (with Google Sheets)",
"meta": {
"templateCredsSetupCompleted": false,
"templateId": "task_management_agent_with_google_sheets"
},
"nodes": [
{
"parameters": {},
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"typeVersion": 1.3,
"position": [-656, -32],
"id": "3eb00ee5-cab6-4a07-b3d5-cee733bae08d",
"name": "When chat message received"
}
],
"connections": {
"When chat message received": {
"main": [
[
{
"node": "Task management agent",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"tags": []
}
Key Properties
| Property | Description | Source File |
|---|---|---|
name | A user-defined name for the workflow. | packages/frontend/editor-ui/src/utils/templates/samples/agents/task_management_agent_with_google_sheets.json:2 |
nodes | An array of node objects that make up the workflow. Each node has parameters, a type, position, and a unique ID. | packages/frontend/editor-ui/src/utils/templates/samples/agents/task_management_agent_with_google_sheets.json:6 |
connections | An object defining the links between nodes. It maps a source node's output to a target node's input. | packages/frontend/editor-ui/src/utils/templates/samples/agents/task_management_agent_with_google_sheets.json:210 |
settings | An object containing workflow-specific settings, such as executionOrder, errorWorkflow, and timezone. | packages/frontend/editor-ui/src/Interface.ts:250-258 |
tags | An array of tags associated with the workflow for organization and filtering. | packages/frontend/editor-ui/src/Interface.ts:203 |
pinData | An object to store pinned data for nodes, which is useful for debugging and development. | packages/frontend/editor-ui/src/Interface.ts:204 |
active | A boolean flag indicating whether the workflow is active and can be triggered. | packages/frontend/editor-ui/src/Interface.ts:199 |
Nodes
Nodes are the fundamental building blocks of a workflow. Each node performs a specific function, such as starting a workflow, making an HTTP request, executing custom code, or implementing conditional logic. Node definitions are stored in .json files that describe their properties, categories, and documentation links.
*Sources: packages/nodes-base/nodes/Start/Start.node.json, packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json, packages/nodes-base/nodes/If/If.node.json, packages/nodes-base/nodes/Cron/Cron.node.json, packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/ExecuteWorkflow.node.json, packages/frontend/editor-ui/src/constants.ts
Common Node Types
Node Type (type) | Description | Category |
|---|---|---|
n8n-nodes-base.start | The default starting point for a workflow when executed manually. | Core Nodes |
n8n-nodes-base.cron | Triggers a workflow based on a CRON schedule for periodic executions. | Core Nodes |
n8n-nodes-base.webhook | Provides a URL to trigger the workflow from external services. | Development, Core Nodes |
n8n-nodes-base.httpRequest | Makes HTTP requests to any API or URL. | Development, Core Nodes |
n8n-nodes-base.function | Executes custom JavaScript code to perform complex data transformations. | Development, Core Nodes |
n8n-nodes-base.if | Implements binary conditional logic to route data down different paths (true/false). | Core Nodes |
n8n-nodes-base.set | Sets, modifies, or renames fields in the data stream. | Core Nodes |
n8n-nodes-base.executeWorkflow | Calls another workflow, allowing for modular and reusable logic (sub-workflows). | Core Nodes |
Sources: packages/frontend/editor-ui/src/constants.ts:153-210, packages/nodes-base/nodes/Start/Start.node.json, packages/nodes-base/nodes/Cron/Cron.node.json, packages/nodes-base/nodes/Webhook/Webhook.node.json, packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json, packages/nodes-base/nodes/Function/Function.node.json, packages/nodes-base/nodes/If/If.node.json, packages/nodes-base/nodes/Set/Set.node.json, packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/ExecuteWorkflow.node.json
Database Persistence
Workflows are persisted in a database, and the WorkflowRepository class is responsible for all database operations related to workflows. It handles creating, reading, updating, and deleting workflow records.
*Sources: packages/@n8n/db/src/repositories/workflow.repository.ts
Entity Relationship Diagram
The following diagram shows the database schema for a workflow and its relationship with tags and webhooks.
Sources: [packages/@n8n/db/src/repositories/workflow.repository.ts:15, 452-459, 503-506]
WorkflowRepository
The WorkflowRepository provides an abstraction layer for querying workflow data. It includes methods for fetching workflows and folders, counting active workflows, and updating specific properties like the trigger count.
This flowchart shows the logic for the getWorkflowsAndFoldersUnion method, which retrieves a combined list of workflows and folders for display in the UI.
Sources: [packages/@n8n/db/src/repositories/workflow.repository.ts:208-223, 303-321]
Key Methods
| Method | Description | Source File |
|---|---|---|
get(where, options) | Retrieves a single workflow entity based on a where clause. | packages/@n8n/db/src/repositories/workflow.repository.ts:49-55 |
getAllActiveIds() | Returns an array of IDs for all active workflows. | packages/@n8n/db/src/repositories/workflow.repository.ts:57-64 |
updateWorkflowTriggerCount(id, count) | Updates the triggerCount for a specific workflow. | packages/@n8n/db/src/repositories/workflow.repository.ts:117-132 |
getWorkflowsAndFoldersUnion(ids, options) | Fetches a paginated and sorted list of workflows and folders, typically for a specific project or folder view. | packages/@n8n/db/src/repositories/workflow.repository.ts:208-223 |
getManyQuery(ids, options) | Constructs a flexible SelectQueryBuilder to fetch multiple workflows with support for filtering, sorting, relations, and pagination. | packages/@n8n/db/src/repositories/workflow.repository.ts:399-410 |
findWorkflowsWithNodeType(types) | Finds all workflows that contain one or more specified node types. | packages/@n8n/db/src/repositories/workflow.repository.ts:635-650 |
updateActiveState(id, state) | Activates or deactivates a single workflow. | packages/@n8n/db/src/repositories/workflow.repository.ts:656-658 |
deactivateAll() | Deactivates all workflows in the system. | packages/@n8n/db/src/repositories/workflow.repository.ts:660-662 |
Workflow Constants
Several constants are defined in the frontend to govern workflow behavior, such as size limits and default values.
| Constant | Value | Description |
|---|---|---|
MAX_WORKFLOW_SIZE | 1024 * 1024 * 16 | The maximum size of a workflow in bytes (16MB). |
MAX_PINNED_DATA_SIZE | 1024 * 1024 * 12 | The maximum size of pinned data in a workflow in bytes (12MB). |
DEFAULT_NEW_WORKFLOW_NAME | 'My workflow' | The default name assigned to a newly created workflow. |
MAX_WORKFLOW_NAME_LENGTH | 128 | The maximum number of characters allowed in a workflow name. |
PLACEHOLDER_EMPTY_WORKFLOW_ID | '__EMPTY__' | A placeholder ID used for an empty workflow state in the UI. |
NEW_WORKFLOW_ID | 'new' | The ID used in the URL to signify the creation of a new workflow. |
Sources: [packages/frontend/editor-ui/src/constants.ts:13-40]
Summary
Workflow management in n8n is a comprehensive system that encompasses a flexible JSON-based structure for defining automation logic, a robust database schema for persistence, and a powerful repository layer for data access and manipulation. The modular design, centered around nodes and connections, allows users to build anything from simple, linear tasks to complex, branching processes. Key features like sub-workflows, detailed settings, and tagging provide the tools necessary for creating, organizing, and maintaining sophisticated automations.