Configuring Protobase
Protobase reads its config from one file in the project’s root: protobase.config.ts, or protobase.config.json for the same object as JSON. The file describes the whole app as one flat object of data: its address and secret, sign-in, the jobs, the file providers and the API’s settings. Every key is optional; Protobase has a default for each, and a project without a config file is a config of defaults.
import { defineConfig } from '@protobase/config'
export default defineConfig({ timezone: 'Europe/Amsterdam', auth: { roles: ['admin', 'sales'], organizations: true }, jobs: { 'send-invoice': { description: 'Mails an invoice to its customer.', arguments: { invoiceId: 'bigint' }, maxAttempts: 5 }, }, writeHooks: ['queue-sent-invoice'],})The config names things; it never holds or imports their code. Protobase finds the code by its path, so the job above runs jobs/send-invoice.ts and the write hook is hooks/queue-sent-invoice.ts.
Each key is described with its type and default in the option pages:
| Page | Keys |
|---|---|
| App options | name, url, secret, previousSecrets, locale, timezone, themeColor, backgroundColor, mobile, resources |
| Sign-in options | auth, authenticate, signingKeyDays, signingKeyGraceDays |
| API options | apiPath, apiKeys, cors, defaultAccess, rowPermissions, statementTimeoutMs, scanGuard, errorReporting, writeHooks, mcpEndpoint, remoteResources, runtimeUpdates, realtime, calls, userTables |
| Admin app options | assistant, maps, plugins |
| Jobs and events options | jobs, events, history, webhooks, workflows, notifications, status, unsubscribe, mailFeedback |
| Files options | files |
Config types
Section titled “Config types”defineConfig from @protobase/config types every key and returns its argument as it is, so the editor completes and checks the config without anything running. The package exports the types too: ProtobaseConfig is the object, and AuthConfig and FilesConfig are its auth and files.
import type { ProtobaseConfig } from '@protobase/config'
const config: ProtobaseConfig = { timezone: 'Europe/Amsterdam' }export default configConditional config
Section titled “Conditional config”defineConfig also takes a function, which gets the command that reads the config, the environment and the project’s folder, and returns a config:
export default defineConfig(({ command, env }) => ({ auth: { trustedOrigins: env.TUNNEL_URL ? [env.TUNNEL_URL] : undefined }, errorReporting: command === 'dev' ? false : undefined,}))command |
dev, build (also protobase mobile, which builds the app’s files as a deploy bundle), serve (also protobase worker and the serve runtime’s create-admin; the runtime’s migrate never reads the config), or tool, any other command over the project, such as migration, users or doctor |
env |
process.env, with the project’s .env loaded |
root |
the project’s folder |
protobase serve reads a bundle’s config again where it runs, with that environment, so a bundle built once serves with each host’s own variables. The types are ConfigEnv, ConfigCommand and ConfigFunction.
Async config
Section titled “Async config”The function may be async, and return its config as a promise:
import { readFile } from 'node:fs/promises'
export default defineConfig(async ({ root }) => ({ maps: JSON.parse(await readFile(`${root}/maps.json`, 'utf8')),}))A config may read files of its own with Node’s fs, and import values from other files, such as a list of map layers, as any module can.
Environment variables
Section titled “Environment variables”Secrets are values like any other, read from the environment. Several keys fall back to a variable of their own when the config leaves them out, such as url to PROTOBASE_URL; each option names its variable. A TypeScript config reads any other variable from env (or process.env, which holds the same):
export default defineConfig(({ env }) => ({ auth: { trustedOrigins: env.TUNNEL_URLS?.split(',') },}))A JSON config reads one with an $env value: { "$env": "NAME" }, with "default" for when the variable is unset or empty, and "split": "," for a list of its non-empty parts, each trimmed. A value whose variable is unset and has no default is left out, as if the key were not written (an item of a list stays, as undefined). An $env value is always text, the variable’s or the default as written: "30" is not the number 30, and "false" is not false, so a key that takes a number or a boolean takes it written in the config, or from a TypeScript config that converts it. A TypeScript config may write $env values too, but its types do not know them; env is the typed way.
The app’s database is DATABASE_URL’s, with the pool size of PROTOBASE_DB_CONNECTIONS; neither is a key of the config.
The same config as JSON
Section titled “The same config as JSON”protobase.config.json holds the same object as JSON, with $env values for what the environment gives:
{ "$schema": "./node_modules/@protobase/config/schema.json", "url": { "$env": "PROTOBASE_URL" }, "timezone": "Europe/Amsterdam", "auth": { "roles": ["admin", "sales"], "trustedOrigins": { "$env": "TUNNEL_URLS", "split": "," } }, "jobs": { "send-invoice": { "arguments": { "invoiceId": "bigint" }, "maxAttempts": 5 } }, "writeHooks": ["queue-sent-invoice"]}JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. $schema points the editor at the file’s JSON Schema, which @protobase/config ships as schema.json, made from the same types as a TypeScript config: it completes and checks every key and value as it is typed, and takes an $env value wherever text, a number or a list goes, but not for a boolean or an object, which $env text cannot be. Protobase itself leaves $schema out. Where a key holds the settings of a library underneath, such as auth.socialProviders, the schema takes any object, and the app checks it when it starts.
One config per project
Section titled “One config per project”A project has one config file: one with both protobase.config.ts and protobase.config.json stops every command with an error that names both. A config cannot extend another itself; extensions merge folders instead.
Reading it
Section titled “Reading it”Every command reads the config, in a few milliseconds: reading it runs the config’s file and what that file imports, and none of the project’s code. A config may not load part of itself later: an import() in protobase.config.ts stops every command with an error that names it. Code belongs in the files below.
Where the code is
Section titled “Where the code is”Protobase loads each file below only when the app needs it, never while the config is read. Sign-in’s hooks in auth/hooks.ts get the app’s database, { db } (Kysely, as jobs get it), as their last argument; a write hook gets the write’s transaction. A job named in the config without its jobs/<name>.ts, or a write hook without its hooks/<name>.ts, stops the app at start with an error that names the file.
The resources and roles have no key of their own:
| File | What it holds | See |
|---|---|---|
config/index.ts, config/<dir>/ui.ts |
the resources, views and pages, and the webhook subscriptions, as exports | Data config |
config/roles.ts |
the roles export (or the default export), made with defineRoles |
Access |
functions/<name>.ts, or functions/<name>/index.ts for a function of several files |
an API function, as its default export; a file or folder whose name starts with _ or ., a test and a .d.ts are not functions |
API functions |
The other files belong to an option, and are described with it:
| File | Option |
|---|---|
auth/hooks.ts, auth/mailer.ts |
auth |
auth/authenticate.ts |
authenticate |
hooks/<name>.ts |
writeHooks |
hooks/error.ts, audit/queue.ts |
Code of the API |
assistant/tools.ts |
assistant |
mcp/tools.ts |
mcpEndpoint |
jobs/<name>.ts |
jobs |
derived/<resource>.<name>.ts |
a resource’s .derived() |
webhooks/owner-roles.ts |
webhooks |
workflows/saved-by-roles.ts |
workflows |
workflows/plugins/<name>.ts |
workflows.plugins |
notifications/store.ts, notifications/history-store.ts, notifications/senders.ts |
notifications |
files/<name>.ts |
files.providers |
Extensions
Section titled “Extensions”protobase dev --extend <dir> and protobase build --extend <dir> merge an extension’s folder into the app, before the project, and so do protobase migration and protobase mobile with the same option. The extension’s folder has a config and code of its own, found by the same paths in that folder; its config is a protobase.config.ts, since an extension’s protobase.config.json is not read.
import { defineUi } from '@protobase/ui'import * as tasksUi from 'some-extension/protobase.ui'
export default defineUi({ extends: [tasksUi] })| What | How it merges | The same name twice |
|---|---|---|
resources, views and pages of config/ |
all kept | an error naming both folders |
| user menu | at most one among all folders | an error |
assistant tools of assistant/tools.ts |
the extensions’ first, in order, then the app’s | an error naming the tool and both folders |
MCP tools of mcp/tools.ts |
the extensions’ first, in order, then the app’s | an error naming the tool and both folders |
jobs, functions, file providers (files.providers) |
all kept, by name | an error naming the name and both folders |
workflow plugins of workflows/plugins/ |
all kept | an error naming the plugin and both sources |
files.types |
all kept, by type | an error naming the type and both folders |
files.trustedHosts |
all kept | |
the other keys of files |
each the app’s own; otherwise the last config that sets it | |
writeHooks |
all run, in the same order | |
config/roles.ts, auth/authenticate.ts, audit/queue.ts, hooks/error.ts, webhooks/owner-roles.ts, workflows/saved-by-roles.ts, notifications/*.ts |
the app’s own; otherwise the last extension’s | |
auth/hooks.ts, auth/mailer.ts |
those of the last folder whose config sets auth; otherwise the app’s |
|
every other key (auth, authenticate, assistant, …) |
the app’s own; otherwise the last config that sets it | |
UI components (exported by name or in components), actions |
all kept | an error naming the name and both configs |
UI shell.actions, shell.rightPanel |
all drawn, the extended configs’ first | |
UI shell.logo |
the app’s own; otherwise the last config that sets it |
Errors name an extension by its folder. Nothing is namespaced, so a collision is always an error, never a silent override. Names starting with Protobase (components) and protobase_ (tools) belong to Protobase’s own extensions, such as ProtobaseCloudTask and protobase_cloud_create_proposal; give yours other names.