Automation Engine
Relevant source files
The following files were used as context for generating this wiki page:- packages/types/src/documents/workspace/automation/automation.ts
- packages/frontend-core/src/api/automations.ts
- packages/builder/src/pages/builder/workspace/[application]/automation/index.svelte
- packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte
- packages/server/src/api/routes/tests/automation.spec.ts
- packages/server/src/api/controllers/webhook.ts
- packages/builder/src/components/automation/SetupPanel/BlockData.svelte
- packages/builder/src/components/automation/Shared/CreateWebhookModal.svelte
- packages/server/src/automations/tests/steps/bash.spec.ts
- packages/shared-core/src/automations/steps/ai/generate.ts
- packages/server/src/automations/tests/executeScriptV2.spec.ts
The Budibase Automation Engine allows users to create automated workflows to handle tasks, process data, and integrate with external systems. These automations are constructed visually in the Budibase builder, connecting a trigger to a series of action steps. The engine is responsible for both the user-facing builder interface and the backend execution of these workflows.
Automations can be initiated by various events, such as a row being created in a table, a schedule (cron), an incoming webhook, or a manual action within an app. Once triggered, the automation executes a sequence of steps, which can range from running queries and executing custom JavaScript or Bash scripts to sending emails and interacting with AI services. The engine is designed to be extensible, allowing for new triggers and actions to be added.
Architecture
The Automation Engine is split between the frontend (packages/builder) and the backend (packages/server), communicating via a REST API.
- Frontend (Builder): A Svelte-based UI that provides a visual flowchart editor for constructing automations. It handles creating, updating, and deleting automations, as well as configuring triggers and steps.
- Backend (Server): A Koa-based server that exposes the API for managing automations and is responsible for their execution. It processes triggers and runs the corresponding steps.
- API Client: The
packages/frontend-corecontains the API client that bridges the builder and the server.
This diagram shows the high-level architecture of the Automation Engine.
Data Model
The core data structure for an automation is defined by the Automation interface. It contains all the information needed to define, execute, and manage a workflow.
Key Automation Fields
| Field | Type | Description |
|---|---|---|
_id | string | The unique identifier for the automation document. |
name | string | The user-defined name of the automation. |
definition | AutomationDefinition | Contains the trigger and steps that define the workflow logic. |
disabled | boolean | If true, the automation is switched off and will not run. |
testData | object | Sample data used for testing the automation within the builder. |
layoutDirection | "TB" | "LR" | The visual layout direction of the flowchart in the builder ('Top-to-Bottom' or 'Left-to-Right'). |
publishStatus | PublishStatus | Indicates the publishing state of the automation (e.g., PUBLISHED, DISABLED). |
Sources: packages/types/src/documents/workspace/automation/automation.ts:10-53, packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte:207-215
Core Components
An automation consists of one trigger and one or more steps.
Triggers
A trigger is the event that starts an automation. Each automation has exactly one trigger.
Common Trigger Types:
- App Action: Triggered manually from within a Budibase application.
- Webhook: Triggered by an HTTP POST request to a unique URL.
- Row Created/Updated/Deleted: Triggered when a row in a specified table is modified.
- Cron: Triggered on a defined schedule.
- Email: Triggered by an incoming email to a monitored inbox.
When a webhook trigger is created, the system provides a URL to receive data. The schema of the incoming data can be automatically generated by sending a sample POST request.
Sources: packages/builder/src/components/automation/Shared/CreateWebhookModal.svelte, packages/server/src/api/routes/tests/automation.spec.ts:712-731
Steps (Actions)
Steps are the individual actions that make up the workflow. The output of one step can be used as input for subsequent steps.
Example Step Types:
- Query Rows: Fetches rows from a data source.
- Create/Update/Delete Row: Modifies data in a table.
- Execute Script: Runs custom JavaScript code. The V2 version uses a
{{ js "..." }}handlebars helper to encode the script. - Execute Bash: Runs a shell command on the server.
- Generate Text (AI): Uses AI to generate text content based on instructions.
- Branch: Implements conditional logic, allowing different paths based on defined conditions.
- Server Log: Logs a message to the server, useful for debugging.
The test files demonstrate how step outputs are chained. For example, a bash command can use data from a trigger, and its output (stdout) can be passed to a subsequent logging step.
// Example from bash.spec.ts
const result = await createAutomationBuilder(config)
.onAppAction()
.bash(
{ code: "echo '{{ trigger.fields.command }}'" },
{ stepName: "Echo Command" }
)
.serverLog(
{ text: "Bash output was: {{ steps.[Echo Command].stdout }}" },
{ stepName: "Log Output" }
)
.test({ fields: { command: "hello world" } })
expect(result.steps[0].outputs.stdout).toEqual("hello world\n")
Sources: packages/server/src/automations/tests/steps/bash.spec.ts:28-43, packages/shared-core/src/automations/steps/ai/generate.ts:11-14, packages/server/src/automations/tests/executeScriptV2.spec.ts:25-28, packages/server/src/api/routes/tests/automation.spec.ts:110-123
Execution Flow
When an event occurs that matches an automation's trigger, the backend execution process begins.
Webhook Trigger Execution Flow
This sequence diagram illustrates the flow when a webhook-triggered automation is executed in a production environment.
The externalTrigger function is responsible for initiating the automation run. For synchronous automations (a premium feature) that include a "Collect" step, the server waits for the result and returns it in the response. Otherwise, it triggers the automation asynchronously and returns an immediate success message.
Automation Builder UI
The frontend provides a rich interface for building and managing automations.
- Automation List (
index.svelte): The main landing page that lists all automations for an application. It allows users to create, edit, duplicate, and delete automations. - FlowChart (
FlowChart.svelte): A visual drag-and-drop editor built with@xyflow/sveltefor arranging triggers and steps. It supports both vertical and horizontal layouts. - Setup Panel (
BlockHeader.svelte,BlockData.svelte): A side panel that appears when a block (trigger or step) is selected. It allows users to configure the block's inputs, view its "Data In" (context from previous steps) and "Data Out" (results from a test run), and see any errors. - Test Modal (
TestDataModal.svelte): A modal for inputting test data. This data is used to simulate a trigger event when running a test.
This diagram shows the relationship between the main UI components in the builder.
Sources: packages/builder/src/pages/builder/workspace/[application]/automation/index.svelte, packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte, packages/builder/src/components/automation/SetupPanel/BlockData.svelte, packages/builder/src/components/automation/AutomationBuilder/FlowChart/TestDataModal.svelte
API Endpoints
The automations.ts API client defines the frontend's interface to the backend automation services.
| Method | Endpoint | Description |
|---|---|---|
GET | /api/automations | Fetches all automations for the current application. |
GET | /api/automations/definitions/list | Retrieves the definitions for all available triggers and steps. |
POST | /api/automations | Creates a new automation. |
PUT | /api/automations | Updates an existing automation. |
DELETE | /api/automations/:automationId/:automationRev | Deletes an automation. |
POST | /api/automations/:automationId/trigger | Triggers an "App Action" automation. |
POST | /api/automations/:automationId/test | Runs a test of the automation with the provided data. |
GET | /api/automations/:automationId/test/status | Gets the status of an asynchronous test run. |
POST | /api/automations/logs/search | Searches for automation execution logs. |
Sources: packages/frontend-core/src/api/automations.ts:16-140
Summary
The Budibase Automation Engine is a powerful and flexible system for creating automated workflows. Its architecture cleanly separates the visual builder on the frontend from the execution logic on the backend. By combining various triggers and a rich set of action steps, developers can automate complex processes, integrate with other tools, and add dynamic logic to their applications with minimal code. The built-in testing and debugging features, such as the test data modal and data viewers, provide a robust development experience.