Creating Plugins
Relevant source files
The following files were used as context for generating this wiki page:
- packages/server/src/api/controllers/plugin/index.ts
- packages/cli/src/plugins/index.ts
- packages/server/src/sdk/plugins/index.ts
- packages/frontend-core/src/api/plugins.ts
- packages/builder/src/settings/pages/plugins/_components/AddPluginModal.svelte
- packages/server/src/utilities/fileSystem/plugin.ts
- packages/server/src/api/routes/tests/plugin.spec.ts
Budibase's plugin system allows developers to extend the platform's functionality by creating custom components, datasources, and automations. This provides a powerful way to integrate with other services and tailor the Budibase experience to specific needs. Plugins can be developed locally using the Budibase CLI, packaged into a tarball, and then imported into a Budibase installation from various sources.
The system is designed to be developer-friendly, with a clear structure and a set of tools to streamline the development, building, and management lifecycle. Plugins are validated against a schema and stored securely, with support for different distribution methods including file upload, URL, NPM, and GitHub repositories.
Plugin Structure
A Budibase plugin is a directory containing a few key files that define its metadata and functionality. The two most important files are package.json and schema.json.
package.json: Standard Node.js package manifest. It must containname,version, anddescriptionfields.schema.json: A Budibase-specific file that defines the plugin's type (e.g., component, datasource), properties, and other metadata.
The system verifies these files during the build and import process to ensure the plugin is valid.
// packages/server/src/utilities/fileSystem/plugin.ts:9-25
export const getPluginMetadata = async (
path: string
): Promise<PluginUpload> => {
let pkg: Package
let schema: PluginSchema
try {
pkg = JSON.parse(fs.readFileSync(join(path, "package.json"), "utf8"))
schema = JSON.parse(fs.readFileSync(join(path, "schema.json"), "utf8"))
if (!pkg.name) {
throw new Error("package.json is missing 'name'.")
}
if (!pkg.version) {
throw new Error("package.json is missing 'version'.")
}
if (!pkg.description) {
throw new Error("package.json is missing 'description'.")
}
//...
Sources: packages/server/src/utilities/fileSystem/plugin.ts:9-25, packages/cli/src/plugins/index.ts:141-147
Plugin Development with the CLI
The @budibase/cli package is the primary tool for developing plugins. It provides commands to initialize, build, and test plugins in a local development environment.
CLI Commands
The following table summarizes the available plugin commands:
| Command | Description |
|---|---|
budi plugin --init [type] | Initializes a new plugin project. type can be component, datasource, or automation. |
budi plugin --build | Verifies and builds the plugin into a distributable .tar.gz file in the dist/ directory. |
budi plugin --watch | Automatically rebuilds the plugin when source files change. |
budi plugin --dev | Starts a local Budibase development environment that watches the current plugin directory for changes. |
budi plugin --migrate-svelte5 | Migrates a plugin to be compatible with Svelte 5. |
Sources: packages/cli/src/plugins/index.ts:308-339
Development Workflow
The diagram below illustrates the typical development lifecycle for a Budibase plugin using the CLI.
This diagram shows the process of initializing, developing, building, and deploying a plugin.
Sources: packages/cli/src/plugins/index.ts:80-112, 163-170, 172-184
Plugin Management
Plugins can be managed through the Budibase UI, which interacts with a set of REST APIs on the server.
Plugin Sources
Budibase supports importing plugins from several sources, providing flexibility for distribution and private use.
| Source | Description |
|---|---|
File Upload | Upload a built plugin .tar.gz archive directly. |
URL | Install a plugin from a direct URL pointing to a .tar.gz archive. Supports authentication via headers. |
NPM | Install a plugin from a public NPM package URL. |
GitHub | Install a plugin from a GitHub repository's releases. Supports private repositories via a GitHub token. |
Sources: packages/builder/src/settings/pages/plugins/_components/AddPluginModal.svelte:15-20, packages/server/src/api/controllers/plugin/index.ts:58-90
The following diagram shows the backend components involved in processing a new plugin.
This diagram illustrates how different plugin sources are handled by the API controller, which then uses various SDKs and helpers to process, validate, and store the plugin.
Sources: packages/server/src/api/controllers/plugin/index.ts, packages/server/src/sdk/plugins/index.ts
API Endpoints
Plugin management is handled by a series of REST API endpoints. The frontend interacts with these endpoints to upload, create, list, and delete plugins.
| Method | Endpoint | Description |
|---|---|---|
POST | /api/plugin/upload | Uploads a plugin from a .tar.gz file. |
POST | /api/plugin | Creates a plugin from a URL, NPM, or GitHub source. |
GET | /api/plugin | Fetches a list of all installed plugins. |
DELETE | /api/plugin/:pluginId | Deletes a specified plugin. |
Sources: packages/frontend-core/src/api/plugins.ts:10-43, packages/server/src/api/controllers/plugin/index.ts
Plugin Import Sequence
The sequence diagram below details the process of adding a new plugin from a GitHub URL.
This diagram shows the end-to-end flow from a user action in the UI to the plugin being stored in the system.
Sources: packages/server/src/api/controllers/plugin/index.ts:70-75, packages/server/src/api/routes/tests/plugin.spec.ts:151-183, packages/builder/src/stores/portal/plugins.ts:31-48
Svelte 5 Migration
Budibase includes a mechanism to upgrade plugins to be compatible with Svelte 5. The migrate-svelte5 CLI command analyzes the plugin, proposes changes, and applies them.
Key Migration Steps:
- Analysis: The CLI analyzes
package.json,schema.json, and build configurations. - Backup: Creates
.pre-svelte5backups of modified files. - Migration: Updates dependencies in
package.json, setssvelteMajor: 5inschema.json, and updates build configurations (e.g.,rollup.config.mjs). - Installation: Runs
npm installto get new dependencies. - Verification: Re-verifies the plugin structure.
- Build: Attempts to build the migrated plugin.
- Cleanup: On successful build, removes the backup files.