init and add
Scaffold the config, the data layer and framework glue for your project, start from a preset, and add blocks.
npx better-supabase init # before better-supabase is installed
pnpm better-supabase init # once it is a dependencyinit reads your package.json and writes:
better-supabase.config.tswithcasingwritten out (--casing snake|camel,snakeby default, as in a config withoutgen.casing) and the conventions that differ from the defaults. It lists the integrations it set up underadapters, and carries commentedgenandtoolingentries for the options you would otherwise pass on every run (see Flags and the config)src/lib/supabase/index.ts, which exportsbetterSupabaseand theModelsandFunctionstypes- glue for every framework it finds, the same files
addwrites
When supabase/config.toml exists and has no [experimental.pgdelta] table,
init adds one with enabled = true, so supabase db schema declarative sync
diffs your schema files with pg-delta, the engine supabase init uses for new
projects. A table that sets enabled = false stays as it is, and init prints
the steps to switch (see BS316).
An existing Supabase project
When the project already has a supabase folder, init counts its
migrations, schema files and the tables in supabase/snapshot.json, prints
them, and changes nothing in the database. It adds no blocks: each later step
(gen, table, add --adopt) is optional and
reversible, and the next steps point at doctor and table. Tables you made
in the dashboard reach the CLI through the snapshot.
--from starts the project from a source. With a postgres:// URL it reads
that database's schema into supabase/snapshot.json, so gen, doctor and
block detection see every table at once:
npx better-supabase init --from "postgresql://postgres:postgres@127.0.0.1:54322/postgres"Any other value (a preset name, a design code, a Create URL or a design file)
behaves like --preset, and passing both flags is an error. --from is the
one flag to remember when you start from something that already exists.
--workflow picks how the SQL modules reach the database (see
Workflows). A project whose supabase/config.toml
lists [db.migrations] schema_paths keeps that file as it is: init skips
enabling pg-delta and prints how to move to it.
pnpm better-supabase init --workflow migrations--workflow | What init does |
|---|---|
pg-delta (default) | Turns pg-delta on in supabase/config.toml and writes no database.sql.workflow |
migra | Writes sql: { workflow: 'migra' } and leaves config.toml alone, for declarative schemas 1.0 |
migrations | Writes sql: { workflow: 'migrations' }: add and upgrade write the modules into a migration |
It then prints the next steps: the install command for your package manager,
supabase start, better-supabase dev env and better-supabase gen. Files that
already exist are never overwritten unless you pass --force or confirm the
prompt. --dry-run shows what would be written, and --check exits 1 when a
file is missing or differs (writing files). The names and the layout are described in Naming.
In a terminal, init asks for the conventions (unless you pass a convention
flag), the integrations, with the detected ones checked (unless you pass
--integration), and whether to overwrite files that exist. add without names asks which
integrations to add. It never asks in CI, when stdin or stdout is not a
terminal, or with --yes, which takes the flags and the defaults.
Found in package.json | Integrations |
|---|---|
next | next (and client) |
hono | hono |
@orpc/server | orpc |
vite | client |
expo | expo (and client) |
@tanstack/react-query | react (and client) |
Add more with --integration edge,mcp. A project with only edge and mcp gets no
src/lib/supabase/index.ts: Edge Functions import betterSupabase from
supabase/functions/_shared/supabase.ts.
Side effects: Writes files.
The Next.js files
The next integration writes the layout that pnpm check:app-architecture
holds the example app to: a synchronous app/(app)/layout.tsx with an
AuthGate, a page that owns the <Suspense> and passes params.then() to a
feature, features/auth and features/account with *-queries.ts
(server-only), *-actions.ts ('use server') and *-cache.ts (pure tags),
and async components that export their *Skeleton. It also writes
app/manifest.ts, public/sw.js and public/offline.html, and lists
NEXT_PUBLIC_VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY in .env.example
without values. The proxy matcher skips html and webmanifest. Existing
files stay yours: init skips them unless you pass --force.
Conventions
The convention flags set what Create sets in its Conventions step, with the same names and defaults:
| Flag | Config key | Values |
|---|---|---|
--casing | casing | snake (default), camel |
--scope | database.sql.owner | tenant (default), user, none |
--tenant-name | blocks.memberships.names.organization | organization (default), workspace, team, or a lowercase name |
--access | blocks.permissions.model | roles (default), catalog, provider, custom |
--id-type | blocks.permissions.idType | uuid (default), text, bigint, integer |
--api | database.sql.api | none (default), api |
Without --preset, init asks for each one in a terminal, in Create's
order: Casing, Row ownership, Tenant name (for tenant scope only), Auth and
permissions, ID type and API schema. Once you pass a convention flag, it
asks for none of them and takes the defaults for the rest. It writes only
the values that differ from the defaults: sql for the scope, tenant name
and API schema, and blocks.permissions for the access model and id type, which
installs the permissions block. With --access provider it also writes a comment
that points you at the authorization key.
Without a preset, init always writes blocks: { 'rls-guard': {} }, which installs the
event trigger that keeps row level security on for every table you create later. Remove the
entry to opt out.
With --preset, each flag overrides that convention of the preset, and
init writes the preset as an object with the fields that differ from the
defaults. Its tenantName takes the names Create offers (organization,
workspace, team), so for another name leave --tenant-name out and set
blocks.memberships.names.organization in the config. add --preset takes
the same flags.
pnpm better-supabase init --scope user --api api
pnpm better-supabase init --preset saas --tenant-name workspace --access catalogStarting from a preset
npx better-supabase init --preset saas
npx better-supabase init --preset 1pWEF3d578B1iGt16--preset takes a named preset, a code from
Create, its whole URL or the path of
a design file. init then
also:
- writes
presetintobetter-supabase.config.ts, whichdefineConfigexpands intoblocksand the preset's conventions; the convention flags override them - adds the preset's integrations and its framework's integration to the ones it found
- writes the module files of every block the preset installs, as
better-supabase upgradedoes - writes
lib/blocks.ts, which wires the blocks that have a TypeScript client withdefineBlocks - writes the wiring the preset's blocks
need: their env keys in
.env.exampleand their provider stubs inproviders.ts - prints a numbered checklist with the
npx shadcn@latest add @better-supabase/...command for the registry glue that fits the preset's framework and platforms
A preset that can't install, such as one whose blocks need tenants under
scope user, stops init with the reason. In a terminal without
--preset, a convention flag or --integration, init first asks for a preset; None
keeps the steps above out. To apply a preset to a project that already has
a config, use add --preset.
A design from Create
When you change the preset or add tables or extra columns on the Create
canvas, its URL carries the design as ?design=, with the preset inside it.
Quote the URL so the shell keeps it whole:
npx better-supabase init --preset "https://app.bettersupabase.com/create?design=0..."init decodes the design locally, with no network call, and writes its
preset into preset, its app tables into tables and its extra columns into
its seeds into database.seed. The canvas positions
stay in the URL. A design that doesn't decode stops init with the reason.
A design is capped at 6000 characters so the URL stays usable. When Create
says a design is too large to share, download the design file instead and
pass its path to --preset:
npx better-supabase init --preset ./better-supabase.design.jsonThe file holds the design as JSON with its preset, with no length limit,
and init reads it like a URL: the same checks, the same config keys and the
same module files. A path ending in .json is read as a design file, relative
to --cwd. add --preset takes the same file. The format
is on Designs and the resolver.
Supabase Lite
pnpm better-supabase init --lite--lite sets the project up for Supabase Lite. The
next steps install @supabase/lite as a dev dependency instead of pg, run
npx lite init and npx lite dev instead of supabase init and
supabase start, and ask you to set jwt_secret = "env(SUPABASE_JWT_SECRET)"
in supabase/config.toml with a secret of 32 or more characters in .env.
Pass backend: 'lite' to createServer (or the framework adapter) so the
server verifies Lite's HS256 tokens.
Content mapper
pnpm better-supabase init --content-mapper--content-mapper sets gen.contentMapper: true, adds the better-supabase
entry to contentMappers in tsconfig.json and adds --runExternalCode to
the typecheck script, so TypeScript 7.1 serves the schema types from the
content mapper instead of database.types.ts. A
tsconfig.json that holds comments or is missing, and a package.json
without a typecheck script that runs tsc, are left alone; the next steps
print the change to make instead.
Agent instructions
When the project already has an AGENTS.md, CLAUDE.md, .cursor, .claude or
.agents, init writes a block into AGENTS.md between
<!-- BEGIN:better-supabase-agent-rules --> and
<!-- END:better-supabase-agent-rules -->. It points agents at the skills, the
docs MCP server and llms.txt, and says not to edit generated files. Each run
rewrites only what sits between the markers, so write your own notes outside
them. A project with none of those files is left alone.
Workspaces
At the root of a pnpm, npm, yarn or bun workspace (a pnpm-workspace.yaml,
or workspaces in package.json), init writes into one package instead of
the root. In a terminal it asks which package owns the runtime, with the one
that already depends on better-supabase (or else the first with a framework)
selected. Otherwise pass it:
pnpm better-supabase init --package packages/runtimeinit then detects the frameworks and tsconfig.json of that package, writes
the config and the glue there, and prints next steps that target it:
pnpm --filter @acme/runtime add ... (or npm install -w, yarn workspace,
bun add --cwd) and better-supabase gen --cwd packages/runtime. Without
--package and without a terminal, init stops with an error that lists the
packages; --package . writes at the root as before.
On Create, turn on Monorepo and enter
the package path (apps/web by default): the install and add commands then
end in --package <dir>. A Create URL carries it as &package=, so init
and add --preset take it from a URL you pass to --preset. The migrations stay in the root supabase/ folder. See
monorepos for how to split the runtime from domain
packages.
add
pnpm better-supabase add comments tags
pnpm better-supabase add --integration hono,mcpadd with block names is how you install blocks. It lists them in blocks
of the config and writes their module files and the modules they require,
rendered next to the blocks you already have, so a block sees what is
installed. --dry-run prints what it would write, --check exits 1 when a
file is out of date, --tests-dir <dir> writes the pgTAP files somewhere
other than database.sql.testsDir, and --allow-hook-overlap installs a
block whose hooks overlap another's (SQL modules). It
also wires the blocks that have a TypeScript client into lib/blocks.ts:
an import and an entry in the object passed to defineBlocks (or
createBlocks). When the file is missing or calls neither with an object
literal, add prints the lines to add instead. Last, it prints the
npx shadcn@latest add @better-supabase/... command for the registry glue
of those blocks that fits the frameworks in the config or package.json,
and the command that turns the files into a migration.
better-supabase blocks list shows the names. --force overwrites files
that exist.
A composite block such as crm or finance is listed in blocks by its own
name, and add writes the modules of all its parts (Composite
blocks).
A new block can change the SQL of blocks you already have: organizations
renders its audit triggers once audit is installed, and entitlements reads
plan quotas once billing is. add renders those installed blocks again, writes
only the files whose output changed, and prints Re-rendered <block>: it integrates with <new block> for each.
The wiring and the checklist
Each block's manifest declares what the app has to provide for it: env keys,
providers, routes and workers. add and init write what they can and print
the rest as a numbered checklist:
- Env keys. Missing keys go to the end of
.env.example, each under its description, soCRON_SECRET=appears once for the outbox and the queue. Set them in.env.localand in every deployed environment. - Providers. A block that takes an implementation (enrichment's
EnrichmentProvider, mail-sync'sMailProviders, the shipping carriers, the order payments and tax) gets a commented stub inproviders.ts, next toblocks.generated.ts. Fill it in and spread it intodefineBlocks:defineBlocks(blockConfig, { ...blocks, ...providers }). - Routes. The outbox relay, the queue drain, the Stripe webhook and the AI
chat route are registry items; the checklist names the
npx shadcn@latest addcommand for your framework. - Workers. The checklist names each route a cron calls, with its schedule
and the
Authorization: Bearer $CRON_SECRETheader, and theschedulesfragment ofvercel.jsonthat calls them as path targets. - Queue and scheduler. With the queue block, the checklist names the wiring
of each queue and scheduler pair:
the Vercel schedule or the
httpTickVault secrets for the drain, the bridge route for Vercel Schedules on Supabase Queues, andjobs.schedulesRoutefor Supabase Cron on Vercel Queues. - Block timers. The SLA, sequences, AI schedules and workflows blocks run
timers on the queue; the checklist lists them and names
jobs.ensureSchedules(blockSchedules(blocks), { prefix: BLOCK_SCHEDULE_PREFIX })and theblockTickHandlerdrain (Block timers). - Actions. The checklist lists the action kinds the installed blocks ship,
such as
tasks.from_conversation, to register in the rules consumer'screateActionRegistryso their default automations run.
Doctor fails on what is left: BS504 on a required env key no env file lists, BS505 on a required provider that is still a comment, and BS512 on queue schedule wiring that misses or doubles runs.
add --preset <name|code|url> applies a preset to the config you have
(--only and --package), and add --adopt <block> --tables <schema.table> maps a block onto tables you already have;
add <block> --over <schema.table> is the short form for one block over one
table, and refuses --adopt, --tables and more than one block. They read
the database through --snapshot, --db-url-stdin or --project-ref when
they need it, and Presets and blocks describes them.
--integration adds glue for integrations instead. add without an argument
or --integration sets up every integration in the config's
adapters list whose files are missing, which is how a fresh checkout
or a new package in a workspace gets its glue. When --integration names
integrations the config doesn't list yet, add prints the adapters
entry to paste.
| Integration | Writes |
|---|---|
client | lib/supabase/client.ts with the framework's public env variables |
next | lib/supabase/server.ts (with import "server-only"), proxy.ts, the feature-sliced app/, features/ and components/ files, and the PWA files (app/manifest.ts, public/sw.js, public/offline.html) |
react | providers.tsx (app/providers.tsx in Next.js) and lib/hooks.ts |
hono | server.ts, which creates bsb and adds the middleware and error handler |
orpc | router.ts, which creates bsb and adds the auth middleware |
edge | supabase/functions/api (server.ts creates bsb) plus supabase/functions/_shared/supabase.ts |
expo | lib/supabase/expo.ts (bsb for API routes), lib/supabase/client.native.ts (the session in secure storage) and app/+middleware.ts |
mcp | supabase/functions/mcp, an MCP server as an Edge Function (server.ts creates bsb) |
Relative imports follow your tsconfig.json: they keep .ts when
allowImportingTsExtensions or rewriteRelativeImportExtensions is on.
Edge Functions always use .ts and get a deno.json import map. CI
typechecks every template against the library, so the files compile as
written. The names and the layout are described in Naming.
Side effects: Writes files, reads the database with --adopt, calls the Supabase Management API with --project-ref.
remove
pnpm better-supabase remove comments --dry-run
pnpm better-supabase remove comments tags
pnpm better-supabase remove crm --with-partsremove takes blocks out of blocks in the config and out of
lib/blocks.ts, and deletes the module files only they wrote. It refuses a
block another installed block requires; remove both together. It writes no
migration: db diff -f remove_comments writes the one
that drops their tables, so you can read the drop statements before they
run. --dry-run prints what it would change, and --check exits 1 while
the files still differ. A module file edited by hand stays, and the command
exits 1 naming it; --force deletes it anyway.
Removing a composite block keeps its parts: remove crm replaces crm in
blocks with the blocks it was made of. --with-parts removes the parts too,
except any part another installed block or composite still needs. --with-parts
on a name that is not a composite is a usage error.
Side effects: Writes files.
upgrade
pnpm better-supabase upgrade
pnpm better-supabase upgrade --checkupgrade writes the module files of every block in the config again, with
the current library and config. When an installed block's version in the
database files is older, it first writes the upgrade steps between the two
versions into a migration stamped before the next schema migration, then
the files. Run it after you bump better-supabase or change a block's
options. --check exits 1 when a file differs and is the CI check,
--dry-run prints the diff, and --tests-dir <dir> writes the pgTAP files
somewhere other than database.sql.testsDir. Rendered modules are cached in
node_modules/.cache/better-supabase/render-blocks.json, keyed on the block
names, the layout and the CLI version, and a file whose hash line no longer
matches is never read from it. --no-cache renders every module again and
leaves the cache alone.
Each block file carries a -- @bsb-hash sha256:... line over its SQL. When
the SQL no longer matches the hash, the file was edited by hand: upgrade
leaves it alone and exits 1 naming it. Move the change into your own schema
file or a SQL hook, or pass --force to overwrite it. --preserve <file>
leaves one hand-edited block file in place and writes the new render beside it
as .new. upgrade also renames
files from earlier releases (2-digit positions such as
900_better_supabase_04_memberships.sql become ..._004_...) and removes
block files that no installed block writes, unless they were edited by hand.
Over a table your own schema already creates, a block adds only the columns it
lacks; see Your own schemas.
Side effects: Writes files.
Last updated on