--- title: "Quickstart" description: "Create a Beignet app, run it locally, and make a first schema change you can watch take effect across the form, API, and OpenAPI." url: "https://www.beignetjs.com/getting-started" markdown_url: "https://www.beignetjs.com/markdown/getting-started.md" framework_version: "0.0.65" documentation_scope: "current-checkout" source_revision: "e5b4771b262efbdd036e3a40a514c08d1508316c" source_modified: true --- # 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](https://www.beignetjs.com/markdown/learn.md). The starter gives API contracts, business workflows, and infrastructure defined places in the application. Next.js handles pages and rendering. Read the [mental model](https://www.beignetjs.com/markdown/concepts.md) 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](https://www.beignetjs.com/markdown/getting-started/agents.md) 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](https://www.beignetjs.com/markdown/stability.md#documentation-versions) > 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 ` 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](https://www.beignetjs.com/markdown/guides/existing-nextjs-app.md). For another runtime, see [packages and imports](https://www.beignetjs.com/markdown/package-reference.md) and [Web Fetch runtimes](https://www.beignetjs.com/markdown/server.md#web-fetch-runtimes). See the [CLI reference](https://www.beignetjs.com/markdown/cli.md) 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](http://localhost:3000/sign-up) 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: ```diff --- a/features/todos/schemas.ts +++ b/features/todos/schemas.ts @@ -32,3 +32,3 @@ export const CreateTodoInputSchema = z.object({ - title: z.string().min(1).max(120), + title: z.string().min(3, "Give the todo at least 3 characters.").max(120), }); ``` ### 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](http://localhost:3000/api/openapi) 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 ``` | Command | What to look for | | --------------------- | ----------------------------------------------------------------------------------------- | | `routes` | The registered Todo endpoints and their HTTP handlers | | `map --feature todos` | The contracts, use cases, and dependencies connected to Todos | | `format` | Formatting applied to the schema edit | | `check` | Architecture 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: | File | Responsibility | | ---------------------------------------- | ------------------------------------------------------------ | | `features/todos/schemas.ts` | Shared data shapes and validation | | `features/todos/contracts.ts` | HTTP inputs and responses that use those schemas | | `features/todos/use-cases.ts` | Application behavior and authorization | | `features/todos/components/todo-app.tsx` | The form and typed queries and mutations | | `server/routes.ts` | Registration of the feature's routes | | `infra/port-wiring.ts` | The implementations available to use cases through app ports | Keep this app, account, and database. Next, [build your first feature](https://www.beignetjs.com/markdown/learn.md): Projects, with a persisted API, ownership rules, and a React UI. Use [Mental model](https://www.beignetjs.com/markdown/concepts.md) for unfamiliar terms and [App architecture](https://www.beignetjs.com/markdown/app-architecture.md) for the full folder map.