.agents/features/flows.md
Flows are the core automation primitive in Activepieces. Each flow is a versioned directed graph of trigger and action steps stored as a JSONB tree. The module handles the full lifecycle: draft editing via a single-endpoint operation dispatch, publishing (locking a version and registering the trigger source), enabling/disabling, folder organization, sample data capture for testing, human-input forms/chat interfaces, and the visual builder frontend powered by XYFlow. All 26 flow modification types are dispatched through one endpoint (POST /v1/flows/:id) with a discriminated-union body.
packages/server/api/src/app/flows/flow/flow.service.ts — core service (operations, publish, enable/disable)packages/server/api/src/app/flows/flow/flow.controller.ts — REST controllerpackages/server/api/src/app/flows/folder/ — folder CRUDpackages/server/api/src/app/flows/step-run/ — sample data capture and test-step executionpackages/server/api/src/app/flows/human-input/ — form and chat public endpointspackages/shared/src/lib/automation/flows/flow.ts — Flow, PopulatedFlow typespackages/shared/src/lib/automation/flows/flow-version.ts — FlowVersion, FlowVersionStatepackages/shared/src/lib/automation/flows/operations/ — FlowOperationRequest union and all 26 op typespackages/shared/src/lib/automation/flows/actions/action.ts — FlowAction discriminated unionpackages/shared/src/lib/automation/flows/triggers/trigger.ts — FlowTrigger discriminated unionpackages/web/src/features/flows/api/flows-api.tsx — flowsApi (list, create, update, get, versions, delete, count)packages/web/src/features/flows/hooks/flow-hooks.tsx — flowHooks (status change, export, import, test, version management)packages/web/src/features/flows/components/ — FlowStatusToggle, ImportFlowDialog, ShareTemplateDialog, ChangeOwnerDialogpackages/web/src/features/flows/utils/flows-utils.tsx — download, zip, template parsing helperspackages/web/src/app/builder/index.tsx — visual flow builder entry pointpackages/web/src/app/builder/flow-canvas/ — XYFlow canvas (nodes, edges, drag layer, context menu)packages/web/src/app/builder/state/ — Zustand-based builder state (flow, run, canvas, notes, step form, piece selector)packages/web/src/app/builder/step-settings/ — step configuration panelpackages/web/src/app/builder/pieces-selector/ — piece/action browserpackages/web/src/app/routes/automations/index.tsx — flows list pagePOST /v1/flows/:id.LOCK_AND_PUBLISH snapshots it to LOCKED and optionally enables the flow.IMPORT_FLOW operations)./form/:flowId) or chat interface (/chat/:flowId) as their trigger UI.Flow: id, projectId, folderId (nullable), status (ENABLED/DISABLED), externalId, publishedVersionId (nullable, unique FK), metadata (JSONB), operationStatus (NONE/DELETING/ENABLING/DISABLING), timeSavedPerRun, ownerId, templateId. Relations: project, folder, owner, publishedVersion (one-to-one), versions (one-to-many), runs, events, tableWebhooks.
FlowVersion: id, flowId, displayName, schemaVersion, trigger (JSONB — full flow graph), connectionIds[], agentIds[], updatedBy, valid, state (DRAFT/LOCKED), backupFiles (JSONB), notes[] (JSONB). Relations: flow, updatedByUser.
Folder: id, projectId, displayName. Used to organize flows and tables. Case-insensitive uniqueness.
All flow modifications go through POST /v1/flows/:id with a FlowOperationRequest discriminated union. 26 operation types:
flow.publishedVersionIdWhen LOCK_AND_PUBLISH or CHANGE_STATUS to ENABLED:
When CHANGE_STATUS to DISABLED:
human-input/)GET /form/:flowId): Public endpoint returning form UI config from flow definition. Supports ?useDraft=true.GET /chat/:flowId): Public endpoint returning chat UI config. Supports sessionId, message, file attachments.step-run/)The visual builder (packages/web/src/app/builder/) uses XYFlow for the canvas. State is split into focused Zustand slices:
flow-state.ts — current flow and version, pending operationsrun-state.ts — active test run, step resultscanvas-state.ts — viewport, selected node, drag statestep-form-state.ts — open/focused step configurationpiece-selector-state.ts — piece browser visibility and searchnotes-state.tsx — sticky notes overlayflowHooks.useChangeFlowStatus handles both publish and enable/disable, surfaces TRIGGER_UPDATE_STATUS errors via an ApErrorDialog, and maps gateway timeout errors to a user-readable message. flowHooks.importFlowsFromTemplates replaces externalId references across a multi-flow template import to maintain cross-flow links.