Skip to content

Get Started

This guide walks through adding Cloudflare-native configuration to a Layeron backend. You will move Wrangler-shaped binding config into the app, use the native bindings in handlers, and use convenience helpers for common sections.

A normal Wrangler config can declare bindings like this:

Terminal window
{
"kv_namespaces": [
{
"binding": "FEATURE_FLAGS",
"id": "kv-prod",
"preview_id": "kv-preview"
}
],
"r2_buckets": [
{
"binding": "UPLOADS",
"bucket_name": "shop-uploads",
"preview_bucket_name": "shop-uploads-preview"
}
],
"d1_databases": [
{
"binding": "DB",
"database_name": "shop-db",
"database_id": "db-prod"
}
],
"vars": {
"NATIVE_MODE": "local"
}
}

In Layeron, put the same fragment under app.cloudflare.wrangler.

Terminal window
import { backend } from "@layeron/core"
const app = backend({ project: "shop" })
app.cloudflare.wrangler({
kv_namespaces: [
{
binding: "FEATURE_FLAGS",
id: "kv-prod",
preview_id: "kv-preview",
},
],
r2_buckets: [
{
binding: "UPLOADS",
bucket_name: "shop-uploads",
preview_bucket_name: "shop-uploads-preview",
},
],
d1_databases: [
{
binding: "DB",
database_name: "shop-db",
database_id: "db-prod",
},
],
vars: {
NATIVE_MODE: "local",
},
})

Layeron generates the Worker deployment fields in the native artifact:

  • name
  • main
  • account_id
  • compatibility_date
  • compatibility_flags

Write the Cloudflare product config you would normally put in Wrangler, such as bindings, queues, Durable Object bindings, migrations, routes, triggers, assets, observability, vars, and new Cloudflare product sections. When multiple app.cloudflare.wrangler calls define the same array section, Layeron combines the entries into the generated artifact.

2. Add Queue And Runtime Entrypoint Config

Section titled “2. Add Queue And Runtime Entrypoint Config”

Queue producers and consumers use the same Wrangler-shaped fields.

Terminal window
app.cloudflare.wrangler({
queues: {
producers: [
{
binding: "ORDER_QUEUE",
queue: "orders",
},
],
consumers: [
{
queue: "orders",
max_batch_size: 10,
max_batch_timeout: 5,
max_retries: 3,
dead_letter_queue: "orders-dlq",
},
],
},
})

The queue consumer config adds a queue entrypoint to the generated Worker and is tracked as a native runtime unit.

Durable Object and Workflow declarations also stay close to Cloudflare’s configuration shape.

Terminal window
app.cloudflare.wrangler({
durable_objects: {
bindings: [
{
name: "ROOMS",
class_name: "RoomObject",
},
],
},
workflows: [
{
binding: "ORDER_WORKFLOW",
name: "order-workflow",
class_name: "OrderWorkflow",
},
],
})

Handlers access native bindings and plain-text vars through request.env. Cast request.env to the binding shape declared in your app.

Terminal window
type NativeEnv = {
FEATURE_FLAGS: {
get(key: string): Promise<string | null>
}
ORDER_QUEUE: {
send(message: unknown): Promise<void>
}
NATIVE_MODE: string
}
app.post("/orders", async (request) => {
const env = request.env as NativeEnv
const enabled = await env.FEATURE_FLAGS.get("orders_enabled")
await env.ORDER_QUEUE.send({
id: crypto.randomUUID(),
enabled,
mode: env.NATIVE_MODE,
})
return { queued: true, mode: env.NATIVE_MODE }
})

Layeron provides small helpers for common Wrangler sections. These helpers write the same internal native declaration as app.cloudflare.wrangler.

Terminal window
app.cloudflare.kv({
binding: "FEATURE_FLAGS",
id: "kv-prod",
})
app.cloudflare.r2({
binding: "UPLOADS",
bucket_name: "shop-uploads",
})
app.cloudflare.d1({
binding: "DB",
database_name: "shop-db",
database_id: "db-prod",
})
app.cloudflare.queue.producer({
binding: "ORDER_QUEUE",
queue: "orders",
})
app.cloudflare.queue.consumer({
queue: "orders",
max_batch_size: 10,
})

Use app.cloudflare.wrangler for new Cloudflare sections, advanced Wrangler fields, or product surfaces that Layeron has not named yet.

Deploy with the local CLI:

Terminal window
layer deploy --env prod

Layeron writes the generated native config here:

Terminal window
.layeron/deploy/prod/cloudflare-native/wrangler.jsonc

Then it runs:

Terminal window
wrangler deploy --config .layeron/deploy/prod/cloudflare-native/wrangler.jsonc

The generated config uses the same generated Worker bundle as the rest of the Layeron app, so native bindings and new Cloudflare products attach to the deployed Worker through Wrangler.

  • Resource model: See how native declarations become graph nodes, bindings, deployment artifacts, vars, and secret references.
  • Backend native resources: Use native Cloudflare declarations from the broader backend authoring guide.
  • CLI resources: Inspect the resources Layeron tracks after local runs and deploys.