TypebaseTypebase
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 just a $schema reference so your editor autocompletes the config as you fill it in. 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.
--skip-exampleSkip generating the example schema, actions, and env.ts.

--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-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.

On this page