Backend Architecture (Server & Worker)
Relevant source files
The following files were used as context for generating this wiki page:
The Budibase backend is a Node.js-based system responsible for all server-side logic, including API services, data processing, automations, and background jobs. It is structured as a monorepo containing several distinct packages that work together to power the platform. The primary backend components are the server and worker processes, which rely on a shared backend-core library for common functionality.
This architecture separates the synchronous API request/response cycle, handled by the server, from asynchronous, long-running tasks, which are managed by the worker. This separation ensures that the user-facing API remains responsive and scalable, while computationally intensive or time-consuming operations are processed in the background.
Core Components
The backend is primarily composed of three packages within the Lerna monorepo.
| Package | Description |
|---|---|
@budibase/server | A Koa.js application that serves as the main API server. It handles all client requests, authentication, and interaction with data sources. |
@budibase/worker | A background service that processes jobs from a queue, such as automations, email sending, and other asynchronous tasks. |
@budibase/backend-core | A shared library containing core logic, utilities, and database connectors used by both the server and worker packages. |
The following diagram illustrates the high-level relationship between these core backend packages.
@budibase/server
The @budibase/server package is the heart of the Budibase backend. It is a Koa.js application responsible for serving the Budibase builder and generated applications, as well as providing the entire API for interacting with the database and file system.
Key responsibilities include:
- Handling all HTTP requests from the frontend builder and deployed applications.
- Managing user authentication and session management using JSON Web Tokens (JWT).
- Providing a public API for external integrations and interoperability.
- Interacting with various data sources (PostgreSQL, MongoDB, REST APIs, etc.).
- Managing plugin lifecycle, including uploading and storage.
- Emitting real-time updates to clients via WebSockets.
Sources: README.md, packages/server/src/sdk/plugins/index.ts:10, 99
The server relies on @budibase/backend-core for fundamental operations like database access and tenancy management.
API Request Flow
This diagram shows a simplified sequence for an API request to the server.
@budibase/worker
The @budibase/worker package is a separate Node.js process that handles background jobs. Its primary purpose is to execute tasks asynchronously, preventing long-running operations from blocking the main API server.
The worker uses the Bull library to manage a job queue backed by Redis. When the server needs to perform a task in the background (like running an automation), it adds a job to the queue. The worker process picks up jobs from this queue and executes them.
Key responsibilities include:
- Executing automations.
- Sending emails.
- Processing webhooks.
- Running scheduled tasks.
Sources: README.md, packages/worker/package.json:44, packages/backend-core/package.json:40
Worker Job Processing Flow
@budibase/backend-core
This package is a critical shared library that provides common functionality to both the server and worker. Centralizing this logic prevents code duplication and ensures consistency across the backend services.
Key modules and functionalities provided by @budibase/backend-core can be inferred from its dependencies:
| Dependency | Purpose |
|---|---|
@budibase/nano | A CouchDB client for interacting with the primary Budibase DB. |
knex | A SQL query builder for connecting to external SQL databases. |
bull | A robust job queue system based on Redis. |
ioredis | A high-performance Redis client. |
jsonwebtoken | For creating and verifying JSON Web Tokens for authentication. |
pouchdb | Used for database operations, often in conjunction with CouchDB. |
@aws-sdk/client-s3 | AWS S3 client for object storage (e.g., file uploads). |
google-auth-library | For Google OAuth authentication. |
passport-* modules | Authentication strategies for different identity providers (OIDC, Google, Local). |
Sources: packages/backend-core/package.json:36-66
Configuration
The backend services are configured using environment variables. These variables control database connections, security secrets, and service ports.
The following table lists some of the key environment variables for the backend, as defined for a Portainer deployment.
| Variable | Description | Default Value |
|---|---|---|
MAIN_PORT | The main port for the Budibase platform. | 10000 |
WORKER_PORT | The internal port for the worker service. | 4003 |
JWT_SECRET | Secret key for signing JSON Web Tokens. | change-me |
MINIO_ACCESS_KEY | Access key for MinIO object storage. | change-me |
MINIO_SECRET_KEY | Secret key for MinIO object storage. | change-me |
COUCH_DB_PASSWORD | Password for the CouchDB user. | change-me |
REDIS_PASSWORD | Password for the Redis instance. | change-me |
INTERNAL_API_KEY | API key for internal service communication. | change-me |
Sources: hosting/portainer/template.json:15-53
Data and Storage
The backend architecture relies on several stateful services for data persistence, caching, and queuing.
This diagram shows how the server and worker interact with various data storage systems.
Sources: packages/backend-core/package.json, hosting/portainer/template.json