Skip to content

Backend entry

The backend entry default-exports a backend(...) app.

Terminal window
import { backend } from "@layeron/core"
const app = backend({
project: "billing",
compatibilityDate: "2026-05-24",
})
export default app

Create a Layeron backend app.

Terminal window
backend(options: BackendOptions): BackendApp

Options accepted by backend().

FieldTypeRequiredDescription
projectstringyesStable project slug used for compilation, deployment state, and resource naming.
namestring | undefinednoHuman-readable app display name.
endpointstring | undefinednoApp endpoint metadata recorded with the app spec.
gatewayLayeron.Runtime.Gateway.GatewayConfig | undefinednoPublic Gateway runtime configuration.
compatibilityDatestring | undefinednoCloudflare Workers compatibility date.
compatibilityFlagsstring[] | undefinednoCloudflare Workers compatibility flags.
observabilityLayeron.Observability.ObservabilityConfig | undefinednoApp-level observability policy.
placementLayeron.Common.Placement.LayeronPlacement | undefinednoApp-level placement defaults for compute, data resources, and Durable Objects.
  • project: stable project slug used for compilation and naming.
  • gateway: public ingress policy, CORS, request ids, traces, and Gateway logs.
  • compatibilityDate: Workers runtime compatibility version.
  • compatibilityFlags: extra Workers runtime flags.
  • observability: app-level logging, events, and trace policy.
  • placement: app-level placement defaults for Workers compute, data resources, and Durable Objects.

Use placement on backend(...) to set app-wide defaults. Use placement on an individual product to override one product instance.

Terminal window
import { backend } from "@layeron/core"
import { db, realtime, storage } from "@layeron/modules"
const app = backend({
project: "media",
placement: {
compute: {
mode: "smart",
locationHint: "weur",
},
data: {
locationHint: "weur",
},
durableObjects: {
locationHint: "weur",
},
},
})
const database = db({
name: "main",
placement: {
data: {
locationHint: "enam",
},
},
})
const files = storage.bucket({ name: "uploads" })
const rooms = realtime({ name: "rooms" })
app.use(database)
app.use(files)
app.use(rooms)
export default app

Product placement merges with backend placement by field. data applies to D1 and R2 resources. compute applies to Workers. durableObjects applies to Durable Object namespaces and runtime stub selection.

Data placement accepts wnam, enam, weur, eeur, apac, and oc. Compute and Durable Object placement also accept sam, afr, and me. jurisdiction accepts eu and fedramp for data and Durable Object placement.