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:
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
Appfromclient/index.tsx. - Declare Lakebed user references with
userId(). Read the caller's identity withctx.auth.requireIdentity()and filter user-owned rows by itsuserId. - Use
isGuestandisSignedInto distinguish protected guests from accounts. UserequireSignedIn()for account-only operations. - Set
auth: { requireSignIn: true }to block all app data access before sign-in. - Declare indexes for filtered queries and use
withIndex,order, and an async terminal such ascollectortake. - Await database reads and writes in server handlers.
- Create one
createClient<typeof app>()and useclient.useQueryandclient.useMutationrather than inventing a client API.client.useQueryreturnsundefineduntil the first result arrives. - 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.
Examples
todo: per-user rows, ownership checks, checkbox mutation, clear-completed mutation.guestbook: shared feed, author metadata from auth, bounded text validation.
Both examples use userId() fields, so guest references transfer on Google sign-in. Todo lists combine with an existing account's todos. Guestbook entries remain shared, and their author references follow the account. Stored author names and pictures are snapshots and do not change during transfer.
Run the checked-in todo example:
npx lakebed dev examples/todo
Guest access uses protected browser sessions by default. For local tests only, open separate tabs with named guest overrides:
http://localhost:3000/?lakebed_guest=alice
http://localhost:3000/?lakebed_guest=bob
Named overrides cannot upgrade to accounts. Test sign-in and transfer with the default browser session instead. See the auth guide for session limits and merge hooks.