CLI
The zeroback CLI manages development, code generation, and deployment of your Zeroback application.
Commands
Section titled “Commands”zeroback init [dir]
Section titled “zeroback init [dir]”Scaffold a new Zeroback project.
zeroback init [dir]| Argument | Default | Description |
|---|---|---|
dir | "." | Project directory |
Creates:
| File | Description |
|---|---|
zeroback/schema.ts | Starter schema with a tasks table |
zeroback/tasks.ts | Example query and mutation functions |
zeroback/_generated/server.ts | Stub file so imports resolve before first codegen |
wrangler.toml | Cloudflare Workers configuration (if not present) |
.zeroback/entry.ts | Worker entry point — imports manifest and wires to runtime |
.gitignore | Ignores .zeroback/* except entry.ts (creates or appends) |
Skips scaffolding if the zeroback/ directory already exists.
Example:
mkdir my-app && cd my-appnpm init -ynpx @zeroback/cli initzeroback dev [functionsDir]
Section titled “zeroback dev [functionsDir]”Start the development server with hot reload.
zeroback dev [functionsDir]| Argument | Default | Description |
|---|---|---|
functionsDir | "./zeroback" | Path to your functions directory |
Behavior:
- Scaffolds
.zeroback/entry.tsif missing (worker entry point) - Analyzes schema and functions, generates types and
_generated/manifest.ts - Starts Wrangler dev server on port 8788
- Watches
zeroback/for changes (ignoring_generated/andnode_modules/) - On file changes: re-analyzes, re-generates manifest
Generated files:
| File | Description |
|---|---|
zeroback/_generated/api.ts | Typed function references (api.tasks.create, etc.) |
zeroback/_generated/server.ts | Typed function factories bound to your DataModel |
zeroback/_generated/dataModel.ts | Standalone DataModel type |
zeroback/_generated/manifest.ts | Function registrations, schema, HTTP router, cron jobs |
Example:
npx @zeroback/cli dev# or with a custom functions directorynpx @zeroback/cli dev ./src/zerobackzeroback deploy [functionsDir] [--dry-run] [-- wranglerArgs...]
Section titled “zeroback deploy [functionsDir] [--dry-run] [-- wranglerArgs...]”Build and deploy to Cloudflare.
zeroback deploy [functionsDir] [--dry-run] [-- wranglerArgs...]| Argument | Default | Description |
|---|---|---|
functionsDir | "./zeroback" | Path to your functions directory |
--dry-run | false | Run codegen only, skip wrangler deploy |
-- args... | — | Extra arguments passed through to wrangler deploy |
Prerequisites:
You must be authenticated with Cloudflare before deploying. Either:
- Run
npx wrangler loginto log in via your browser (recommended for local development) - Set the
CLOUDFLARE_API_TOKENenvironment variable (recommended for CI/CD)
The deploy command will check authentication before deploying and provide guidance if you’re not logged in.
Behavior:
- Runs codegen (same as
zeroback devbuild step) - If
--dry-run: stops after codegen - Verifies Cloudflare authentication
- Runs
wrangler deploywith any extra arguments
Requires wrangler.toml at the project root.
Examples:
# First-time setup: log in to Cloudflarenpx wrangler login
# Deploynpx @zeroback/cli deploy
# Dry run (codegen only)npx @zeroback/cli deploy --dry-run
# Pass args to wranglernpx @zeroback/cli deploy -- --env production
# CI/CD: use an API token instead of interactive loginCLOUDFLARE_API_TOKEN=your-token npx @zeroback/cli deployzeroback codegen [functionsDir]
Section titled “zeroback codegen [functionsDir]”Run code generation without starting a dev server.
zeroback codegen [functionsDir]| Argument | Default | Description |
|---|---|---|
functionsDir | "./zeroback" | Path to your functions directory |
Runs the same build step as zeroback dev (analyze, codegen, bundle) but exits immediately. Useful for CI or pre-commit hooks.
npx @zeroback/cli codegenzeroback reset
Section titled “zeroback reset”Reset the local development database.
zeroback resetDeletes the .wrangler/state directory, which contains all local Durable Object and SQLite data. Restart zeroback dev afterwards to start with a fresh database.
npx @zeroback/cli resetzeroback run <functionName> [jsonArgs] [--url <url>]
Section titled “zeroback run <functionName> [jsonArgs] [--url <url>]”Invoke a function (query, mutation, or action) on the running dev server.
zeroback run <functionName> [jsonArgs] [--url <url>]| Argument | Default | Description |
|---|---|---|
functionName | (required) | Function to call, e.g. tasks:list |
jsonArgs | {} | JSON object of arguments |
--url | http://localhost:8788 | URL of the Zeroback server |
Behavior:
- Sends a POST request to the server’s
/__admin/runendpoint - Executes the function and prints the JSON result to stdout
- Both public and internal functions can be called (useful for debugging)
Examples:
# Run a querynpx @zeroback/cli run tasks:list
# Run a mutation with argumentsnpx @zeroback/cli run tasks:create '{"title": "Buy groceries", "projectId": "proj:abc", "status": "todo"}'
# Run an internal functionnpx @zeroback/cli run tasks:countInternal '{"projectId": "proj:abc"}'
# Target a deployed servernpx @zeroback/cli run tasks:list --url https://my-worker.example.comProject Structure
Section titled “Project Structure”After running zeroback init and zeroback dev, your project looks like:
my-app/ zeroback/ schema.ts # Your schema definition tasks.ts # Your function files _generated/ api.ts # Generated: typed function references server.ts # Generated: typed factories + DataModel dataModel.ts # Generated: DataModel type .zeroback/ entry.ts # Scaffolded by init, user-owned — imports manifest + wires to runtime wrangler.toml # Cloudflare Workers configurationKey conventions:
- Function files go in
zeroback/(any.tsfile exceptschema.tsand files starting with_) - Nested directories are supported:
zeroback/utils/stats.tsproduces function names like"utils/stats:functionName" - Schema is always
zeroback/schema.ts - Never edit files in
zeroback/_generated/— they are overwritten on every build .zeroback/entry.tsis user-owned and can be customized (e.g. to add middleware or env bindings)