Application backend

The backend capability is the HTTP server for a Backify app. A web app has a frontend and backend; an API app has a backend only; a worker app has no HTTP server. One immutable image runs as web, worker and migrate process roles. The shared gateway serves the frontend, forwards verified identity and routes backend requests.

Start with backify new <name> --template web|api|worker. Keep intent in backify.config.ts; declare routes, jobs, schedules and event handlers at module top level with literal names using @backifydev/sdk/app.

import { defineBackend, z } from "@backifydev/sdk/app";
export const api = defineBackend();
api.get("/api/me", { auth: "user", response: z.object({ id: z.string() }) },
  ({ user }) => ({ id: user.id }));

Every route declares auth: "public", "user", { role: "admin" } or { permission: "orders.read" }. Input schemas are validated before the handler. Scope every database query to the verified caller. Browser checks do not authorize access.

backify lock extracts the catalog and OpenAPI into backify.lock.json; commit it. backify check runs the app checks and rejects a stale lockfile. The portal Backend page shows active endpoints, schemas, health and scale, with an OpenAPI download. Jobs and schedules appear on the Jobs page.

Run npm run dev for the local database, roles, gateway and frontend. CI builds and verifies one image; promotion reuses the image, lockfile, migrations and frontend unchanged. See Backend, local development, application support, and the runtime contract.