Quickback Docs

Declared Workers

Split Durable Object classes into their own lean Workers with `workers`, `runsOn` and `bindTo`. The edge binds them by script_name and deploys after them. Phase 1.

Phase 1. Declared Workers host your own Durable Object classes in lean Workers: no auth, no database, no generated routes. The full profile, path mounts on the API hostname, actions, queues and schedules on a declared Worker, and brokered or quickback deploy support come in later phases. Build with the CLI and deploy with the generated npm scripts (quickback deploy refuses a project that declares Workers).

By default every Durable Object class you declare in bindings.durableObjects runs in the edge Worker, the generated Worker that also serves auth, routes and the database. workers declares more Workers in the same project. Set runsOn on a class to host it on one of them.

A Worker owns the Durable Object namespaces of the classes it exports. Splitting a class out gives it its own deploy, bundle and CPU budget, and keeps auth and the ORM out of that bundle. The edge still reaches the class through env.<NAME>, bound with script_name.

quickback/quickback.config.ts
import { defineConfig, defineRuntime, defineDatabase, defineAuth } from "@quickback/compiler";

export default defineConfig({
  name: "events-app",
  template: "hono",
  workers: {
    live: {
      profile: "lean",
      vars: { LIVE_REGION: "global" },
      routing: { domain: "live.events-app.com" },
    },
  },
  bindings: {
    durableObjects: [
      // Hosted by "live", bound by the edge (default bindTo) and routed publicly.
      { name: "ROOM", className: "RoomDO", from: "lib/live/RoomDO", runsOn: "live", access: "public" },
      // Hosted by "live" and bound only there: RoomDO calls it by RPC.
      { name: "TALLY", className: "TallyDO", from: "lib/live/TallyDO", runsOn: "live", bindTo: ["live"] },
    ],
  },
  providers: {
    runtime: defineRuntime("cloudflare"),
    database: defineDatabase("cloudflare-d1"),
    auth: defineAuth("better-auth"),
  },
});

The class files live under quickback/lib/ or quickback/features/<feature>/lib/, as for any in-worker Durable Object. A class reads its own Worker's bindings:

quickback/lib/live/RoomDO.ts
import { DurableObject } from "cloudflare:workers";

interface LiveBindings {
  TALLY: DurableObjectNamespace<import("./TallyDO").TallyDO>;
}

export class RoomDO extends DurableObject<LiveBindings> {
  async fetch(request: Request): Promise<Response> {
    const name = new URL(request.url).pathname.split("/").pop() ?? "";
    const votes = await this.env.TALLY.get(this.env.TALLY.idFromName(name)).count();
    return Response.json({ room: name, votes });
  }
}

workers

workers maps a Worker name to its settings. The name is lowercase letters, digits and dashes, starts with a letter, and is at most 31 characters. It names wrangler.<name>.jsonc, src/workers/<name>/ and the npm scripts. main (the edge Worker), tenant, files and broadcast are reserved, and so is first (deploy:first is the edge's own script). A name whose deploy:<name> or dev:<name> script another generator already emits fails with WORKER_OUTPUT_COLLISION.

workers: {}, runsOn: 'main' or bindTo: ['main'] on their own declare nothing and leave the output unchanged.

FieldDefaultNotes
profile'lean''lean' only. 'full', the generated runtime with routes assigned to it, arrives in phase 5 and is refused until then.
vars—Non-secret [vars] for this Worker only. Strings, numbers or booleans.
durableObjects—{ codeUpdateStrategy } for this Worker's classes. See Durable Object code updates. retry is refused: a lean Worker acquires no Quickback-owned stubs.
routing—{ domain }: the Worker's own custom domain. { mount }, a path on the API hostname, is not supported yet.
dependencies[]npm packages the Worker's bundle may import. cloudflare:*, node:* and zod are always allowed.
compatibilityDatethe runtime'sThis Worker's compatibility date.

runsOn and bindTo

Two fields on a bindings.durableObjects entry place a class.

FieldDefaultNotes
runsOn'main'The Worker that exports the class and owns its namespace. Requires from. Cannot be combined with scriptName, which means a script outside this project.
bindTo['main']Workers that bind the class, besides its host. The host always binds its own classes.

A class on a declared Worker with bindTo including main (the default) is bound in the edge's wrangler.toml with script_name, and typed in CloudflareBindings through a type-only import, so c.env.ROOM is a typed DurableObjectNamespace. The edge never bundles the class.

bindTo naming a declared Worker on a class that main hosts is refused (WORKER_BIND_UNSUPPORTED). It would make the edge a dependency of that Worker and the two could not deploy in order. Host the class on the Worker instead.

bindings.durableObjectMigrations[].runsOn puts a lifecycle step (a delete or a rename) on a declared Worker. Steps without runsOn stay on the edge, so a step without runsOn that names a class a declared Worker hosts (or hosted at the last build) fails with WORKER_RUNS_ON_INVALID. Transfers into a declared Worker are refused in phase 1.

A class has one host. Declaring the same className on two hosts (main and a Worker, or two Workers) fails with WORKER_RUNS_ON_INVALID; bind it from the second one with bindTo instead.

Deleting or renaming a class on a Worker

Removing a class from bindings.durableObjects while it is live on its Worker fails with WORKER_DO_LIFECYCLE: the Worker's exports map would name a class it no longer exports. Add a migration on that Worker and confirm the delete:

bindings: {
  durableObjectMigrations: [{ tag: "drop-tally", runsOn: "live", deletedClasses: ["TallyDO"] }],
  confirmDurableObjectDeletes: ["TallyDO"],
},

The Worker's exports map then marks TallyDO deleted, which destroys its data. A rename is a renamedClasses step with the same runsOn.

Access

A lean Worker has no session, firewall or database, so only two forms of access work on a class it hosts:

  • access: 'public' routes the class at /realtime/<kebab-binding>/<roomId> on the Worker's hostname. The room id names the object (idFromName). Percent-encoded ids are refused.
  • No access makes the class reachable by RPC only, from the Workers that bind it.

Any other access fails with WORKER_ACCESS_NEEDS_DB. The edge does not auto-mount a route for a class hosted elsewhere. The lean entry forwards the request unchanged and sets no PartyServer room headers. Read the room id from the URL.

What a lean Worker may import

The compiler walks each lean Worker's import closure from src/workers/<name>/index.ts and fails the compile with WORKER_CLOSURE_FORBIDDEN when it reaches:

  • Better Auth (src/lib/auth*, src/auth/, the better-auth and @better-auth/* packages);
  • the database layer (src/db/, drizzle-orm), the scoped db, the firewall registry or the security audit writer;
  • edge middleware, routes or the edge entry (src/index.ts);
  • a package not listed in dependencies;
  • a module the compiler cannot resolve, a relative specifier that leaves the generated src/ (for example into node_modules), a computed import() or require(), or require used as a value (const r = require).

Every module reference counts: static and dynamic import, require, export * from, and a class extends clause such as extends require("../auth").Base. .js, .mjs and .cjs helpers are followed like .ts files.

The message names the Worker, the module and the import chain:

WORKER_CLOSURE_FORBIDDEN: worker "live" (profile lean) reaches src/lib/auth.ts — Better Auth — via src/workers/live/index.ts → src/lib/live/RoomDO.ts → src/lib/live/shared.ts → src/lib/auth.ts (src/lib/live/shared.ts imports ("../auth")). A lean Worker bundles only its own classes and stateless helpers: move the shared code out of that module, or keep this code on main.

Type-only imports are not followed.

Env reads

Every file in a lean Worker's bundle may read only that Worker's env: its own classes, the classes it binds and its vars. Reading anything else, such as the edge's DB or BETTER_AUTH_SECRET, fails with WORKER_CAPABILITY_MISSING, naming the file, the binding and the Worker:

WORKER_CAPABILITY_MISSING: src/lib/live/TallyDO.ts:3 reads env.DB (`this.env.DB`), but Worker "live" (profile lean) has no binding DB — DB is a binding of main only. The file is in Worker "live"'s bundle via src/workers/live/index.ts → src/lib/live/TallyDO.ts. Worker "live" provides: LIVE_REGION, ROOM, TALLY. …

A file the edge bundles is checked against the edge's env (ENV_UNDECLARED), so a Worker's vars are not visible there. A file both bundle must satisfy both.

The reverse is checked too: the edge importing a class module that another Worker hosts by value fails with WORKER_CLASS_VALUE_IMPORT, because that class would be bundled into the edge and run there. Use import type.

Script names and environments

Without named environments, Worker live deploys as <project>-live.

With named environments, every target names each declared Worker's script, and its hostname when the Worker sets routing.domain:

environments: {
  dev: {
    name: "events-app-dev",
    workers: { live: { name: "events-app-live-dev", domain: "live.dev.events-app.com" } },
  },
  production: {
    name: "events-app",
    workers: { live: { name: "events-app-live", domain: "live.events-app.com" } },
  },
},

environments.<k>.workers is never inherited through extends. A missing name fails with WORKER_NAME_REQUIRED. A name already used by an edge, tenant or files Worker, by another declared Worker, or by an inert placeholder fails with WORKER_NAME_COLLISION. A Worker's hostname may not be one the edge serves (WORKER_DOMAIN_COLLISION).

Script names, default or declared, must be valid Cloudflare script names: lowercase letters, digits and dashes, not starting or ending with a dash, at most 63 characters (WORKER_NAME_INVALID).

The script name owns the namespaces. Renaming a deployed script would bind the edge to an empty namespace, so the next build refuses it. See Continuity.

Output

For each declared Worker the compiler emits:

FileContents
wrangler.<name>.jsoncname, main, the exports lifecycle for its own classes, durable_objects.bindings (its classes, plus script_name bindings to classes other declared Workers host), vars, routes. With named environments, the top level has an inert placeholder name and no main, and each target is an env.<name> block, so a deploy without --env fails.
src/workers/<name>/index.tsRe-exports the hosted classes and routes the public ones.
src/workers/<name>/env.d.tsWorkerEnv: this Worker's bindings, typed per class.

Declared Workers always use the exports lifecycle, never [[migrations]]. With named environments every target sets workers_dev and preview_urls = false, as the edge does.

The edge's wrangler.toml gains the script_name bindings and comment lines recording which script hosts which class:

# quickback:worker-script live events-app events-app-live
# quickback:worker-export live RoomDO created:sqlite

[[durable_objects.bindings]]
name = "ROOM"
class_name = "RoomDO"
script_name = "events-app-live"

Keep these lines. The next build reads them back, even after workers is removed from the config, and a malformed one fails with WORKER_DO_HOST_UNKNOWN.

reports/ops.manifest.json lists each target's declared Workers (targets[].workers: name, script, config, Wrangler env and npm script) in deploy order.

Deploying

A Worker must be live before the edge binds its classes. The generated scripts deploy declared Workers first, in dependency order (a Worker after every Worker whose classes it binds):

ScriptRuns
npm run deploythe edge's migrations, then deploy:<worker> for each declared Worker, then the edge
npm run deploy:<worker>wrangler deploy -c wrangler.<worker>.jsonc
npm run dev:<worker>wrangler dev -c wrangler.<worker>.jsonc (with named environments, --env of the dev target)
npm run deploy:<env>with named environments: deploy:<env>:<worker> for each Worker, then the edge

Brokered deployment and quickback deploy do not deploy declared Workers yet, and both refuse such a project rather than ship the edge alone, whose script_name bindings would point at Workers that are missing or stale:

  • quickback deploy fails with DEPLOY_DECLARED_WORKERS and names the npm script to run. --dry-run and --skip-deploy still provision resources.
  • The brokered deploy's manifest lists declared-workers-unsupported (plus user-binding-unsupported for the classes).

There is no combined dev router: run dev:<worker> beside the edge's dev server.

Continuity

A class's namespace belongs to the script that first exported it. The build fails with WORKER_DO_HOST_CHANGED when, against the deployed wrangler.toml:

  • a class deployed on the edge now has runsOn set to a declared Worker, or one deployed on a Worker moves to the edge or to another Worker;
  • a deployed Worker is removed from workers, including when workers, runsOn and bindTo are all removed (the class would be re-created, empty, on the edge);
  • a target's script name changes, or a deployed script is no longer deployed by any target.

Moving a class between Workers with its storage is a transfer, which arrives in a later phase. Until then, keep the class where it is.

Error codes

CodeRefused
WORKER_CONFIG_INVALIDAn unknown or malformed field under workers.<name>.
WORKER_NAME_INVALIDA Worker key that is not lowercase letters, digits and dashes, or a script name (default or declared) that is not a valid Cloudflare script name.
WORKER_NAME_COLLISIONA reserved key (main, tenant, files, broadcast, first), or a script name another Worker or target already uses.
WORKER_NAME_REQUIREDA named environment without workers.<name>.name.
WORKER_UNKNOWNrunsOn, bindTo or environments.<k>.workers naming an undeclared Worker.
WORKER_RUNS_ON_INVALIDrunsOn without from, or with scriptName; one class on two hosts; a migration without runsOn naming a Worker's class.
WORKER_BIND_UNSUPPORTEDbindTo from a declared Worker to a class the edge hosts.
WORKER_ACCESS_NEEDS_DBA lean-hosted class with an access other than 'public'.
WORKER_FEATURE_UNSUPPORTEDA container on a lean-hosted class, or a transfer into a declared Worker.
WORKER_PROFILE_UNSUPPORTEDprofile: 'full'.
WORKER_ROUTING_UNSUPPORTEDrouting.mount.
WORKER_DOMAIN_REQUIRED / WORKER_DOMAIN_COLLISIONA routed Worker with no hostname for a target, or a hostname the edge or another Worker serves.
WORKER_DEPENDENCY_CYCLEWorkers that bind each other's classes in a cycle.
WORKER_RUNTIMEworkers on a runtime other than Cloudflare.
WORKER_BINDING_COLLISIONA class bound on the edge under a name the edge already uses, or two bindings (classes or vars) with one name in the same Worker.
WORKER_CLOSURE_FORBIDDENA lean Worker's bundle reaching auth, the database, edge code or an undeclared package.
WORKER_CAPABILITY_MISSINGA file in a lean Worker's bundle reading an env name that Worker does not provide.
WORKER_CLASS_VALUE_IMPORTThe edge importing a class another Worker hosts by value.
WORKER_DO_HOST_CHANGEDA change that would leave a deployed class's namespace empty.
WORKER_DO_HOST_UNKNOWNA # quickback:worker-* line in wrangler.toml the build cannot read. Restore it from version control.
WORKER_DO_LIFECYCLEA Worker class's lifecycle that Cloudflare would reject: a live class dropped without a delete migration, or an unconfirmed delete.
WORKER_OUTPUT_COLLISIONA Worker's file or npm script that would overwrite one another generator emitted. Rename the Worker.
WORKER_EMITInternal: the generated src/env.d.ts had no CloudflareBindings to extend. Report it.
DEPLOY_DECLARED_WORKERSquickback deploy on a project with declared Workers. Run npm run deploy or npm run deploy:<env>.

At runtime the lean entry answers unknown paths with 404 WORKER_ROUTE_NOT_FOUND and non-canonical room ids with 404 WORKER_ROOM_ID_INVALID. Both bodies name the Worker.

See also

On this page