Database Schema
Relevant source files
The following files were used as context for generating this wiki page:
- packages/@n8n/api-types/src/schemas/tests/project.schema.test.ts
- packages/@n8n/api-types/src/schemas/tests/user.schema.test.ts
- packages/frontend/editor-ui/src/constants.ts
- packages/frontend/editor-ui/src/utils/templates/samples/agents/task_management_agent_with_google_sheets.json
- packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json
- packages/nodes-base/nodes/Webhook/Webhook.node.json
- packages/frontend/editor-ui/src/api/schemaPreview.test.ts
The n8n database schema is not directly defined by traditional SQL table definitions in the provided files, but rather by the structure of the JSON objects that are serialized and stored. The primary data artifact is the Workflow, which is a JSON document containing nodes, connections, and settings. Other key data models include Users, Projects, and Credentials.
This document outlines the logical schema of these core data structures as inferred from application constants, data model validation tests, and example workflow definitions. The system uses these schemas to validate data and to serve schema information via an API endpoint for features like schema preview.
Workflow Schema
A workflow is the central entity in n8n. It is represented as a single JSON object that encapsulates all the logic, configuration, and metadata required for its execution.
The diagram below illustrates the high-level structure of a workflow JSON document.
This diagram shows the main components of a workflow's JSON structure.
Key Workflow Properties
| Property | Type | Description | Source |
|---|---|---|---|
name | string | The user-defined name of the workflow. Must be between 1 and 128 characters. | [constants.ts:33-34](https://github.com/n8n-io/n8n/blob/HEAD/constants.ts#L33-L34) |
nodes | Array<Object> | An array of node objects that make up the workflow logic. | [task_management_agent_with_google_sheets.json:7-210](https://github.com/n8n-io/n8n/blob/HEAD/task_management_agent_with_google_sheets.json#L7-L210) |
connections | Object | An object describing the connections between nodes. | [task_management_agent_with_google_sheets.json:216-267](https://github.com/n8n-io/n8n/blob/HEAD/task_management_agent_with_google_sheets.json#L216-L267) |
settings | Object | Contains workflow-specific settings like execution order and error handling. | [task_management_agent_with_google_sheets.json:269-273](https://github.com/n8n-io/n8n/blob/HEAD/task_management_agent_with_google_sheets.json#L269-L273) |
tags | Array<string> | A list of tags associated with the workflow for organization. Max tag name length is 24. | [constants.ts:37](https://github.com/n8n-io/n8n/blob/HEAD/constants.ts#L37), [task_management_agent_with_google_sheets.json:274](https://github.com/n8n-io/n8n/blob/HEAD/task_management_agent_with_google_sheets.json#L274) |
meta | Object | Metadata about the workflow, such as the template ID if it was created from one. | [task_management_agent_with_google_sheets.json:2-5](https://github.com/n8n-io/n8n/blob/HEAD/task_management_agent_with_google_sheets.json#L2-L5) |
Workflow Data Constraints
The system imposes several size limits on workflow data to ensure performance and stability.
| Constant | Value | Description | Source |
|---|---|---|---|
MAX_WORKFLOW_SIZE | 16 MB | The total size limit for a workflow JSON object in bytes. | [constants.ts:12](https://github.com/n8n-io/n8n/blob/HEAD/constants.ts#L12) |
MAX_PINNED_DATA_SIZE | 12 MB | The size limit for pinned data within a workflow. | [constants.ts:14](https://github.com/n8n-io/n8n/blob/HEAD/constants.ts#L14) |
MAX_WORKFLOW_NAME_LENGTH | 128 | The maximum number of characters allowed for a workflow name. | [constants.ts:34](https://github.com/n8n-io/n8n/blob/HEAD/constants.ts#L34) |
Node Definition Schema
Each node available in n8n is defined by a .node.json file. This file specifies the node's identity, category, documentation links, and other metadata. This is separate from the node's configuration within a workflow.
| Property | Description | Example | Source |
|---|---|---|---|
node | The unique identifier for the node type. | n8n-nodes-base.httpRequest | [HttpRequest.node.json:2](https://github.com/n8n-io/n8n/blob/HEAD/HttpRequest.node.json#L2) |
nodeVersion | The version of the node definition. | 1.0 | [HttpRequest.node.json:3](https://github.com/n8n-io/n8n/blob/HEAD/HttpRequest.node.json#L3) |
categories | An array of categories the node belongs to (e.g., "Development", "Core Nodes"). | ["Development", "Core Nodes"] | [HttpRequest.node.json:5](https://github.com/n8n-io/n8n/blob/HEAD/HttpRequest.node.json#L5) |
resources | An object containing URLs for primary and credential documentation. | { "primaryDocumentation": [...] } | [HttpRequest.node.json:6-10](https://github.com/n8n-io/n8n/blob/HEAD/HttpRequest.node.json#L6-L10) |
alias | An array of alternative names for searching the node. | ["API", "Request", "URL", "Build", "cURL"] | [HttpRequest.node.json:84](https://github.com/n8n-io/n8n/blob/HEAD/HttpRequest.node.json#L84) |
Sources: packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json, packages/nodes-base/nodes/Webhook/Webhook.node.json
Node Schema API
The system exposes an endpoint to retrieve the JSON schema for a specific node's parameters. This is used for dynamic UI generation and validation. The API endpoint follows a structured path.
This diagram shows the flow for retrieving a node's JSON schema.
The endpoint path is constructed dynamically based on the node's properties.
- Example Endpoint:
schemas/n8n-nodes-base.test/1.2.0/contact/create.json
Sources: packages/frontend/editor-ui/src/api/schemaPreview.test.ts:28-32, packages/frontend/editor-ui/src/api/schemaPreview.test.ts:50-54
Data Model Schemas
Beyond workflows, n8n manages other key data entities like Users and Projects. The schemas for these are defined and validated within the application.
User Schema
The user schema defines the structure for user objects. Validation tests confirm the expected fields and their types.
| Field | Type | Description | Source |
|---|---|---|---|
id | string | Unique identifier for the user. | [user.schema.test.ts:20](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L20) |
firstName | string (optional) | User's first name. | [user.schema.test.ts:21](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L21) |
lastName | string (optional) | User's last name. | [user.schema.test.ts:22](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L22) |
email | string (optional) | User's email address, must be a valid email format. | [user.schema.test.ts:23, 45-47](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L23) |
role | string | The role assigned to the user. Must be one of the predefined roles. | [user.schema.test.ts:24](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L24) |
isPending | boolean | Flag indicating if the user invitation is pending. | [user.schema.test.ts:25](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L25) |
lastActive | string (optional) | ISO date string of the user's last activity. | [user.schema.test.ts:26](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L26) |
projects | Array<string> (optional) | An array of project IDs the user is a member of. | [user.schema.test.ts:27](https://github.com/n8n-io/n8n/blob/HEAD/user.schema.test.ts#L27) |
User Roles
The role field is an enum with the following possible values:
global:ownerglobal:memberglobal:admindefault
Sources: packages/@n8n/api-types/src/schemas/tests/user.schema.test.ts:5-13
Project Schema
Projects are used to organize resources like workflows and credentials.
| Field | Type | Description & Constraints | Source |
|---|---|---|---|
name | string | The name of the project. Cannot be empty and must be less than 256 characters. | [project.schema.test.ts:8-12](https://github.com/n8n-io/n8n/blob/HEAD/project.schema.test.ts#L8-L12) |
type | string | The project type. Must be either personal or team. | [project.schema.test.ts:18-22](https://github.com/n8n-io/n8n/blob/HEAD/project.schema.test.ts#L18-L22) |
icon | Object | An object defining the project icon, with type (emoji or icon) and value. | [project.schema.test.ts:28-36](https://github.com/n8n-io/n8n/blob/HEAD/project.schema.test.ts#L28-L36) |
description | string | An optional description for the project, max 512 characters. | [project.schema.test.ts:50-54](https://github.com/n8n-io/n8n/blob/HEAD/project.schema.test.ts#L50-L54) |
relation | Object | Defines a user's relationship to the project, containing userId and role. | [project.schema.test.ts:60-64](https://github.com/n8n-io/n8n/blob/HEAD/project.schema.test.ts#L60-L64) |
The project relation role must be a valid role string, such as project:admin.
Sources: packages/@n8n/api-types/src/schemas/tests/project.schema.test.ts