Typebase.
CLI

typebase-io-cli init

Scaffold a new Typebase project structure.

Last updated on

Scaffold a new Typebase project structure.

npx typebase-io-cli init

Creates a typebase/ directory with:

  • tsconfig.json: TypeScript config
  • db/schema.ts: example database schema
  • db/relations.ts: example relations
  • actions/queries/todos.ts: example query actions
  • actions/mutations/todos.ts: example mutation actions
  • env.ts: an empty env schema with a commented-out example key
  • _generated/: auto-generated type files

It also creates a typebase.json at the project root if there isn't one, holding a $schema reference so your editor autocompletes the config as you fill it in. On the first command in a project, the file also gets a telemetry entry recording that the telemetry notice was shown. Every option stays on its default until you set it. Running init over an existing typebase.json keeps the values already in it.

Options

FlagDescription
-f, --forceOverwrite tsconfig.json and regenerate the scaffolded example files.
--with-authInclude an example auth.ts with email/password authentication.
--with-db-publisherInclude a publisher.ts, the events table it needs, and actions that use it.
--with-storageInclude a storage.ts with a public and a private bucket, and actions that use them.
--skip-exampleSkip generating the example schema, actions, and env.ts.
--with-migrationsRecord schema changes as migrations instead of pushing them.

--with-auth

Sets up authentication with better-auth, using email and password. On top of the usual scaffold it writes:

  • auth.ts: a defineAuth config with emailAndPassword enabled and http://localhost:3000 trusted
  • db/schema.ts: the users, sessions, accounts, and verifications tables better-auth needs
  • db/relations.ts: those tables registered, plus the relations between them and todos
  • actions/custom-actions.ts: an authedAction that rejects requests without a valid session
  • actions/queries/todos.ts and actions/mutations/todos.ts: built on authedAction, and scoped to the signed-in user
It cannot be combined with --skip-example, which skips the example this flag adds to.

--with-migrations

Starts the project in migrations mode, so it has schema history from its first commit rather than needing conversion later. On top of the usual scaffold it writes:

  • db/migrations/<timestamp>_initial/: one migration holding the creation SQL for the scaffolded schema, plus the snapshot the next migration is diffed against

The migration is generated from your actual schema files, so combining this with --with-auth or --with-db-publisher puts those tables in the same first migration. It is one migration, not one per flag: with auth the example table references the auth users table, so a migration holding the example table alone would reference a table nothing had created.

From then on, db <target> push refuses to run and you use db migrations generate and db <target> migrate instead.

Already have a project? You don't need to start over. db migrations init adopts migrations on an existing project without recreating your databases.

--with-db-publisher

Sets up a publisher, so actions can publish events and stream them to clients. On top of the usual scaffold it writes:

  • publisher.ts: a db publisher declaring one example event, todo.created
  • db/schema.ts: the events table the publisher keeps events in
  • db/relations.ts: an events: {} entry registering that table
  • actions/mutations/todos.ts: create publishes todo.created after inserting
  • actions/queries/todos.ts: getMany becomes a streaming action that re-sends the list on every new todo
It cannot be combined with --skip-example, which skips the example this flag adds to.

--with-storage

Sets up storage, so actions can keep files in buckets and hand out URLs to them. On top of the usual scaffold it writes:

  • storage.ts: a vercel storage provider with a public avatars bucket and a private documents bucket
  • actions/queries/storage.ts: getAvatarUploadUrl, which returns a signed upload URL for an avatar, and getDocumentUrl, which returns a signed URL to read a document

Nothing is created on Vercel yet. A local run uses local storage and works straight away; run storage sync dev or deploy when you want the real buckets. To keep files somewhere else, change provider in storage.ts before your first sync.

It cannot be combined with --skip-example, which skips the example this flag adds to.

On this page