Building with Valcraven
Practical, copy-paste recipes for extending the template — features, API routes, admin pages, migrations, realtime channels, chat tools, and API-key auth.
Building with Valcraven
This section is the how-to half of the docs: short, opinionated recipes for adding your own code on top of the template. Where Features explains what already ships, these pages show you how to extend it without fighting the conventions the template is built around.
Every recipe follows the same golden path — new authenticated features live inside /app, inside the existing app shell, and every route and query scopes its data to the signed-in user. Start with Add a feature; it ties the other recipes together end to end.
- Add a feature — The golden path, start to finish: model the data, add the API route, and render the UI inside the
/appshell (never a new public route, never a full-screen overlay). - Add an API route — The standard route handler:
force-dynamic+nodejs, resolve the session, and return errors througherrorResponse(). - Add an admin page — How the
/adminsection is structured, how the RBAC gate works, and how to add a page plus its sidebar link. - Database migrations — Add a table to the schema, write a numbered migration, apply it locally, and ship it to Cloudflare D1.
- Add a realtime channel — Publish server-side events and subscribe from the client with
useRealtime, plus the single authorization seam you extend. - Add a chat tool — Give the AI agent a new tool it can call mid-conversation, following the built-in
create_item/generate_imagepattern. - Protect a route with API keys — Opt a route into
sk_…API-key auth withauthenticateRequest()andrequireApiPermission().
Two conventions pages are worth reading alongside these: Code conventions for the house rules, and Gotchas for the sharp edges. Power users can go deeper in the admin-only dev wiki.
Theming & dark mode
The useTheme hook, the ThemeToggle, system-aware light/dark switching, and the input text-color rule you must follow.
Add a feature
The golden path for adding an authenticated feature — model the data, add a scoped API route, and render the UI inside the /app shell without breaking the conventions the template relies on.