Quickstart
This guide walks you through initializing a new Layeron backend, writing a basic API route with a SQL database, running the project locally, and deploying it directly to your own Cloudflare account.
1. Install the CLI
Section titled “1. Install the CLI”Install the Layeron CLI globally on your system to manage projects, run local development environments, and orchestrate deployments:
npm install -g @layeron/cli2. Initialize a Project
Section titled “2. Initialize a Project”Create a new directory for your backend and initialize a Layeron project. This sets up a clean TypeScript project pre-configured for Cloudflare compilation:
layer init my-appcd my-app3. Write Your Backend Code
Section titled “3. Write Your Backend Code”Open index.ts in your preferred editor. Define your backend application, declare a relational SQL database capability, and register a GET route to retrieve data:
import { backend } from "@layeron/core"import { db } from "@layeron/modules"
const app = backend({ project: "my-app", compatibilityDate: "2026-05-24",})
// 1. Declare a Cloudflare-native SQL database capabilityconst database = db({ name: "main", sql: ` create table if not exists users ( id text primary key, email text unique not null, createdAt text not null ); `,})
// 2. Register the database capabilityapp.use(database)
// 3. Expose a public HTTP API routeapp.get("/api/users", () => { return database.sql("select id, email from users").as("users")})
export default app4. Run Locally
Section titled “4. Run Locally”Start the Layeron local development server. Layeron compiles your TypeScript application, spins up an isolated, edge-compatible local runtime (using Miniflare), provisions a local SQLite replica for your database, applies migrations, and establishes hot-reloading:
layer devYou can now test your endpoint by making a request in a new terminal window:
curl http://127.0.0.1:4321/api/users[!NOTE] During local development, Layeron keeps database state and metadata isolated inside your project’s local
.layeron/folder.
5. Deploy to Cloudflare
Section titled “5. Deploy to Cloudflare”Deploy your backend application directly to your Cloudflare account. The CLI will authenticate you, compile your code into a production resource graph, apply safe pending database migrations, and deploy Workers and D1 databases natively inside your account:
layer deployOnce completed, the CLI will output your live public URL (e.g., https://my-app.yoursubdomain.workers.dev/api/users).
Next Steps
Section titled “Next Steps”- Introduction: Review the product model, BYOC boundary, and deployment pipeline.
- Backend: Learn how project config, backend entries, modules, routes, and namespaces fit together.
- Database: Declare tables, run typed queries, and manage migrations for the SQL database used in this guide.
- CLI: Review install, local dev, deploy, resources, secrets, logs, and environment commands.