Skip to content

Quickstart

Create a Next.js app with sign-in and a working Todos feature. Then change one validation rule and see it take effect in the form, API, and OpenAPI document. You will use this same app for the Projects tutorial.

The starter gives API contracts, business workflows, and infrastructure defined places in the application. Next.js handles pages and rendering. Read the mental model for how those responsibilities fit together, or follow the steps below to see the structure in a running app.

Prefer to work with a coding agent? Follow the agent quickstart to build the same starter and make the same first change.

Alpha software: Beignet's 0.0.x APIs can change between releases. Compare the documentation version with your installed packages when following an example.

Before you start

Install Node.js 22.12 or newer and Bun. This walkthrough uses the full-stack Next.js starter with SQLite, which needs no separate database server. Keep those defaults and skip optional providers when creating the app.

Run commands in your terminal. After creating the app, run every subsequent command from its root directory, next to package.json. Leave the development server running in one terminal and use a second terminal for checks and migrations.

Create an app

Choose a new directory name in place of my-app. If you are resuming the same starter, skip creation and keep your existing .env.local values.

bash
bun create beignet my-app
cd my-app
bun install
cp .env.example .env.local

The starter includes Better Auth sign-in and sign-up, a shadcn/Tailwind UI shell, and a Todos feature with data stored in SQLite through Drizzle. The copied environment file contains the defaults needed for local development.

The starter installs @beignet/cli locally. Use bun beignet <command> from this directory to run the version installed with your app.

Other package managers, API-only apps, and existing projects

npm create beignet@latest, pnpm create beignet, and yarn create beignet are also supported. Use your chosen package manager for installation, scripts, and app-local CLI commands throughout the guide.

Use --api to omit the UI; it still runs on Next.js. The Projects tutorial uses the full-stack starter. To adopt Beignet incrementally, follow Add Beignet to an existing Next.js app. For another runtime, see packages and imports and Web Fetch runtimes.

See the CLI reference for all setup prompts and flags.

Prepare the database

Apply the starter's migrations and check the result:

bash
bun beignet db migrate
bun beignet db status

Expect Database migrations are current. The starter includes its initial SQL migrations in drizzle/; you do not need to generate another migration before this first run. SQLite stores the data in the local file selected by SQLITE_DB_URL in .env.local.

If you chose Postgres or MySQL

Start your database server before running db migrate. For a local database matching the generated settings, use the command for your selected database:

bash
# Postgres 14+
docker run --rm -d -e POSTGRES_USER=beignet -e POSTGRES_PASSWORD=beignet -e POSTGRES_DB=my_app -p 5432:5432 postgres:17-alpine

# MySQL 8.0+
docker run --rm -d -e MYSQL_ROOT_PASSWORD=beignet -e MYSQL_DATABASE=my_app -p 3306:3306 mysql:8.4

The generated database name is the app directory with punctuation replaced by underscores (my-app becomes my_app). Keep the database name and credentials aligned with POSTGRES_DB_URL or MYSQL_DB_URL in .env.local.

The Projects tutorial uses SQLite-specific schema and adapter examples.

Start the app

bash
bun run dev

Open the sign-up page and create an account. Signing up takes you to the dashboard. Open Todos in the sidebar, create Try Beignet, complete it with the checkbox, and delete it.

The sidebar also links to Settings, plus Devtools and the OpenAPI document in development. You can explore those after making the first change.

This guide uses port 3000, matching APP_URL and BETTER_AUTH_URL in the starter's environment file. If Next.js chooses another port, either free port 3000 or update both URLs to match and restart the development server.

Make your first change

A schema describes the data a feature accepts or returns. The todo creation schema is shared by the form, API, and OpenAPI document. Make new titles at least three characters long.

In features/todos/schemas.ts, update CreateTodoInputSchema to require a three-character title and provide a useful validation message:

features/todos/schemas.ts

Check the form

With the development server running, open Todos, type hi, and press Add. The form displays Give the todo at least 3 characters. without sending a create request. Try Ship the app next; it should create a todo.

Check the API

While signed in on your local app, open your browser's developer console and run this request. It sends the invalid input directly to the server, bypassing the form. Your browser includes the current session cookie.

javascript
const response = await fetch("/api/todos", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "idempotency-key": crypto.randomUUID(),
  },
  body: JSON.stringify({ title: "hi" }),
});
console.log(response.status, await response.json());

Expect status 422 and error code VALIDATION_ERROR. The response includes the title validation issue, and no todo is created.

Check the OpenAPI document

OpenAPI is a machine-readable description of your HTTP API. Open the OpenAPI document and find paths → /api/todos → post → requestBody.

Under content → application/json → schema, the $ref points to a schema in components.schemas. Find that named schema and check its title property: it has "minLength": 3.

You changed one schema. The browser form, server validation, and API description all use that rule.

Inspect and verify the app

In your second terminal, inspect the feature and run the checks:

bash
bun beignet routes
bun beignet map --feature todos
bun run format
bun beignet check
CommandWhat to look for
routesThe registered Todo endpoints and their HTTP handlers
map --feature todosThe contracts, use cases, and dependencies connected to Todos
formatFormatting applied to the schema edit
checkArchitecture lint, strict doctor checks, and the app's lint, typecheck, and tests passing

check helps catch misplaced dependencies, missing wiring, and failing app checks. Review any failures before continuing. Missing app scripts are reported as skipped; the default starter provides all three scripts. For structured output your agent can read, add --json to map or check.

Checkpoint: your first change works

Before moving on, confirm that:

  • You can sign in and create, complete, and delete a todo.
  • A two-character title is rejected in both the form and the API.
  • The OpenAPI document describes the three-character minimum.
  • bun beignet check passes after formatting.

These files connect the behavior you just tried:

FileResponsibility
features/todos/schemas.tsShared data shapes and validation
features/todos/contracts.tsHTTP inputs and responses that use those schemas
features/todos/use-cases.tsApplication behavior and authorization
features/todos/components/todo-app.tsxThe form and typed queries and mutations
server/routes.tsRegistration of the feature's routes
infra/port-wiring.tsThe implementations available to use cases through app ports

Keep this app, account, and database. Next, build your first feature: Projects, with a persisted API, ownership rules, and a React UI. Use Mental model for unfamiliar terms and App architecture for the full folder map.