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.
1. Add A Wrangler Fragment
Section titled “1. Add A Wrangler Fragment”A normal Wrangler config can declare bindings like this:
{ "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.
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:
namemainaccount_idcompatibility_datecompatibility_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.
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.
3. Bind Durable Objects And Workflows
Section titled “3. Bind Durable Objects And Workflows”Durable Object and Workflow declarations also stay close to Cloudflare’s configuration shape.
app.cloudflare.wrangler({ durable_objects: { bindings: [ { name: "ROOMS", class_name: "RoomObject", }, ], }, workflows: [ { binding: "ORDER_WORKFLOW", name: "order-workflow", class_name: "OrderWorkflow", }, ],})4. Use Native Bindings
Section titled “4. Use Native Bindings”Handlers access native bindings and plain-text vars through request.env. Cast
request.env to the binding shape declared in your app.
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 }})5. Use Convenience Helpers
Section titled “5. Use Convenience Helpers”Layeron provides small helpers for common Wrangler sections. These helpers write
the same internal native declaration as app.cloudflare.wrangler.
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.
6. Deploy
Section titled “6. Deploy”Deploy with the local CLI:
layer deploy --env prodLayeron writes the generated native config here:
.layeron/deploy/prod/cloudflare-native/wrangler.jsoncThen it runs:
wrangler deploy --config .layeron/deploy/prod/cloudflare-native/wrangler.jsoncThe 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.
Next Steps
Section titled “Next Steps”- 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.