Backend
Layeron backends are declared in TypeScript.
A backend project has one project config and one or more backend entry files:
layeron.config.tspoints Layeron at the backend entry and defines environment values.- The backend entry exports a
backend(...)app with modules, routes, middleware, and native Cloudflare declarations.
import { project } from "@layeron/core"
export default project({ app: "./src/app.ts",})import { backend } from "@layeron/core"import { db, log, storage } from "@layeron/modules"
const app = backend({ project: "billing", compatibilityDate: "2026-05-24",})
const database = db({ name: "main" })const files = storage.bucket({ name: "uploads" })const appLog = log({ namespace: "app", name: "billing" })
app.use(database)app.use(files)app.use(appLog)
app.get("/api/health", () => ({ ok: true }))
export default appLayeron compiles this backend into an AppSpec, RuntimeTopology, resource graph, deployment plan, and deployment state.
Use project({ backends }) when one project has several backend entry files.
All entries compile into the same project resource graph for the selected
environment. Equal module declarations share one logical resource.
- Project config: Configure the project entry and environment values.
- Multiple backends: Split one project into several backend entry files that compile together.
- Backend entry: Define the backend app and app-wide runtime defaults.
- Modules: Register capability instances with
app.use(...). - Namespaces: Keep named capability instances distinct.
- Routes: Declare public HTTP routes.
- Middleware: Add shared request handling.
- Native Cloudflare resources: Declare Cloudflare resources inside the backend model.