@backifydev/sdk
Backify applications declare one server entry and ship one image with web, worker and migrate process roles. Import server APIs from @backifydev/sdk/app, typed configuration from @backifydev/sdk/config, and test helpers from @backifydev/sdk/testing. Browser code calls the application's API with fetch; database credentials and workload tokens stay on the server.
import { defineBackend, database, defineJob, schedule, z } from "@backifydev/sdk/app";
export const api = defineBackend();
api.get("/api/items", { auth: "user" }, async ({ user }) =>
(await database().query("SELECT id, title FROM items WHERE owner_id = $1", [user.id])).rows);
export const cleanup = defineJob("cleanup", async () => {
await database().query("DELETE FROM items WHERE archived AND created_at < now() - interval '30 days'");
});
schedule("nightly-cleanup", { cron: "0 3 * * *" }, cleanup);
Declare routes, jobs, schedules and event subscriptions at module top level with literal names. Every route defaults to authenticated access; use auth: "public" only deliberately. The SDK verifies signed gateway identity and enforces route roles or permissions before handlers run. Handlers must scope all rows and files to the authenticated user or organization.
Use database() for PostgreSQL, transaction() for atomic writes, and events.publish(name, payload, { client: tx }) for a transactional event outbox. bucket(name) gets short-lived scoped storage credentials from the broker. AI, mail, governed HTTP and integrations use broker services. secret(name) and config(key) read platform-injected values.
Create a project with backify new my-app --template web|api|worker. Run backify dev locally, backify lock to generate the deterministic release contract, and backify check before committing. Local development uses real private PostgreSQL and a local broker; test identity helpers never belong in production code.
The legacy root, /server, /local and /runtime imports were removed with functions, browser-direct database access, HCR bindings and workload packaging. See the runtime contract and Expense Manager.