# Lakebed Examples

Use these capsules as patterns for app-building agents. Each example is a complete Lakebed app with the same file layout your generated app should use:

```txt
server/index.ts
client/index.tsx
shared/
```

## What To Copy

- Put schema, queries, and mutations in `server/index.ts`.
- Keep validation helpers and shared types in `shared/`.
- Export `App` from `client/index.tsx`.
- Use `ctx.auth.userId` for user-owned rows.
- Declare indexes for filtered queries and use `withIndex`, `order`, and an async terminal such as `collect` or `take`.
- Await database reads and writes in server handlers.
- Use `useQuery` and `useMutation` rather than inventing a client API.
- Style with Tailwind classes in JSX.

Both checked-in examples use database API v1. For an older capsule that still uses `where`, `orderBy`, `limit`, `all`,
or synchronous database calls, follow the [Database API v1 migration guide](../docs/database-migration.md).

## Examples

- [`todo`](./todo): per-user rows, ownership checks, checkbox mutation, clear-completed mutation.
- [`guestbook`](./guestbook): shared feed, author metadata from auth, bounded text validation.

Run the checked-in todo example:

```sh
npx lakebed dev examples/todo
```

Open separate tabs with different guest identities:

```txt
http://localhost:3000/?lakebed_guest=alice
http://localhost:3000/?lakebed_guest=bob
```
