The Application Builder
Relevant source files
The following files were used as context for generating this wiki page:
The Budibase Application Builder is a comprehensive system that enables users to create, design, and manage low-code applications. It consists of a Svelte-based frontend for the user interface, a Koa-based server for backend logic and API, and a client module that renders the final applications. The entire project is structured as a Lerna monorepo, with distinct packages for different functionalities.
The builder allows users to construct single-page applications by connecting to various data sources, designing UIs with pre-made components, automating workflows, and managing deployment. The system is designed to be extensible, with its open-source nature allowing for custom modifications and contributions.
Architecture Overview
Budibase is a monorepo managed by Lerna, with its primary logic separated into packages. The application builder's functionality is distributed across several key packages.
Sources: README.md:120-131, AGENTS.md:3-9
Key Packages
| Package | Description |
|---|---|
packages/builder | The client-side Svelte application that constitutes the Budibase builder UI. |
packages/client | A browser-based module responsible for reading the JSON definition of an app and rendering it into a live web application. |
packages/server | A Koa application that serves the JavaScript for the builder and the final apps. It also provides the API for database and file system interactions. |
packages/bbui | A shared component library used across Budibase projects, providing common UI elements. |
packages/shared-core | A package containing code and types shared between both NodeJS (backend) and browser (frontend) environments. |
Sources: README.md:120-131, AGENTS.md:3-9, packages/bbui/README.md:1-2
The following diagram illustrates the high-level interaction between these packages.
Sources: README.md:120-131, AGENTS.md:3-9
Workspace Management (Backend)
The backend, located in packages/server, handles the core logic for managing workspaces and applications. A "Workspace" is the backend representation of a Budibase application. The workspace.ts controller contains the logic for all CRUD operations and more.
Sources: packages/server/src/api/controllers/workspace.ts
Creating a Workspace
A new workspace can be created via the POST /api/applications endpoint. The creation process can be initiated in several ways:
- Empty App: A blank application with only a default users table.
- From Template: Using a predefined Budibase template, like 'Expense Approval'.
- From File: Importing an exported Budibase application file (
.tar.gz). - Onboarding: A special flow that creates a "Welcome app" with sample data and screens.
Sources: packages/server/src/api/routes/tests/workspace.spec.ts:200-280
The create function in workspace.ts orchestrates this process. It checks for unique names and URLs, creates the database instance, adds the creator to the app's user table, and optionally imports data or templates.
The diagram below shows the flow for creating a new workspace.
The request body for creating a workspace can contain the following parameters:
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the new workspace. Required. |
url | string | The URL slug for the application. If not provided, it's generated from the name. |
isOnboarding | string | If "true", creates a sample "Welcome app". |
useTemplate | string | If "true", indicates creation from a template or file. |
templateKey | string | The key for a predefined Budibase template (e.g., app/expense-approval). |
fileToImport | file | An exported app file to import. |
encryptionPassword | string | Password for encrypted app exports. |
Sources: packages/server/src/api/routes/tests/workspace.spec.ts:203-206, 233-238, 250-254, packages/server/src/api/controllers/workspace.ts:420-440
Fetching Application Data
The builder frontend fetches all necessary application data using the fetchAppPackage controller function, which responds to GET /api/applications/:appId/package. This single request bundles the core application metadata, screens, layouts, and other essential information.
This is the primary data loading mechanism when a user opens an application in the builder.
Sources: packages/builder/src/pages/builder/workspace/[application]/_layout.workspace.svelte:28-32, packages/server/src/api/controllers/workspace.ts:223-288
The sequence diagram below illustrates this data fetching process.
Publishing and Syncing
Budibase maintains separate development (_dev) and production versions of an application.
- Publish (
POST /api/applications/:appId/publish): Copies the current state of the development app to the production app. This makes changes live for end-users. - Sync (
POST /api/applications/:appId/sync): A process to ensure the development and production databases are correctly aligned. This is automatically disabled if theDISABLE_AUTO_PROD_APP_SYNCenvironment variable is true. - Unpublish (
POST /api/applications/:appId/unpublish): Removes the production version of the app, making it inaccessible to end-users but preserving the production data.
Sources: packages/server/src/api/routes/tests/workspace.spec.ts:1003-1006, 1145-1148, 1177-1180
Builder Frontend
The builder frontend is a Svelte application in the packages/builder directory. It provides the user interface for designing screens, managing data, and configuring automations.
Initialization
When a user navigates to a workspace, the main layout component _layout.workspace.svelte is loaded. It is responsible for fetching the complete application package and initializing the builder's state stores.
The getPackage function is the entry point for this initialization.
// packages/builder/src/pages/builder/workspace/[application]/_layout.workspace.svelte:23-37
async function getPackage(appId) {
try {
if ($admin.maintenance.length) {
return
}
if ($builderStore.created) {
builderStore.appCreated(false)
await appsStore.load()
} else {
reset()
appStore.update(state => ({ ...state, appId }))
const pkg = await API.fetchAppPackage(appId)
await initialise(pkg)
}
await deploymentStore.load()
} catch (error) {
// ... error handling
}
}
Sources: packages/builder/src/pages/builder/workspace/[application]/_layout.workspace.svelte:23-37
The initialization flow is as follows:
"Get Started" Flow
For users who do not have access to any workspaces, the "Get Started" page (packages/builder/src/pages/builder/get-started/index.svelte) is displayed. This page prompts the user to create their first workspace by showing a modal (CreateWorkspaceModal.svelte) which triggers the workspace creation API.
Upon successful creation, the initialise function refreshes the user's authentication details and the list of available apps, then redirects them to the newly created workspace.
Sources: packages/builder/src/pages/builder/get-started/index.svelte:11-20
UI Components (@budibase/bbui)
The core UI of the builder and the components available to app creators are provided by the @budibase/bbui package. This package is a Svelte component library that acts as a wrapper around Adobe's Spectrum design system.
Key guidelines for bbui development include:
- Reusability: Components should be designed to be reusable.
- CSS Variables: Use custom properties (variables) from the stylesheet for easy theming and tweaking.
- Event Forwarding: Prefer forwarding events (e.g.,
<button on:click>) over using callbacks. - No Outer Margins: Components should not have margins on their outermost container to allow for flexible composition using CSS Grid or wrapper divs.
Sources: packages/bbui/README.md:14-22
Conclusion
The Budibase Application Builder is a modular system built on a monorepo architecture. The packages/server provides a robust API for workspace lifecycle management, including creation, publishing, and data handling. The packages/builder Svelte application consumes this API to provide a rich, interactive design environment. Shared packages like @budibase/bbui and @budibase/shared-core ensure consistency and code reuse across the platform, from the builder UI to the final rendered application. This separation of concerns creates a powerful and extensible platform for low-code application development.