Skip to content

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.


Install the Layeron CLI globally on your system to manage projects, run local development environments, and orchestrate deployments:

Terminal window
npm install -g @layeron/cli

Create a new directory for your backend and initialize a Layeron project. This sets up a clean TypeScript project pre-configured for Cloudflare compilation:

Terminal window
layer init my-app
cd my-app

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:

Terminal window
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 capability
const database = db({
name: "main",
sql: `
create table if not exists users (
id text primary key,
email text unique not null,
createdAt text not null
);
insert or ignore into users (id, email, createdAt)
values ('user_1', 'user@example.com', '2026-05-24T00:00:00.000Z');
`,
})
// 2. Register the database capability
app.use(database)
// 3. Expose a public HTTP API route
app.get("/api/users", () => {
return database.sql("select id, email from users").as("users")
})
export default app

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:

Terminal window
layer dev

You can now test your endpoint by making a request in a new terminal window:

Terminal window
curl http://127.0.0.1:8787/api/users

Sign in to your Cloudflare account:

Terminal window
layer login

Deploy your backend application directly to your Cloudflare account. The CLI compiles your code into a production resource graph, applies safe pending database migrations, and deploys Workers and D1 databases natively inside your account:

Terminal window
layer deploy

Once completed, the CLI will output your live public URL (e.g., https://my-app.yoursubdomain.workers.dev/api/users).


  • 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.