Build
Add a feature
Scaffold a workspace-scoped feature in one command.
01Scaffold it
npm run new:feature -- invoices
npm run db:generate -- --name invoices
npm run db:migrateThe generator writes or edits:
- a table in
db/schema.ts features/invoices/schema.ts,server/queries.tsandserver/actions.ts- a create form and
pages/invoices-page.tsx - routes for both personal and team workspaces, and a nav link
tests/unit/invoices.test.ts, plus the slug in the reserved list
02Scope every query
Every workspace-owned row has an organizationId. Get the workspace on the server, never from the browser:
const ctx = await requireWorkspace(workspace);
await db.insert(invoices).values({ ...input, organizationId: ctx.organization.id });Pages use workspaceFromParams(params); actions and routes use requireWorkspace(workspace).
03Checklist
- New
/dashboard/<segment>route: add the segment tofeatures/teams/reserved-slugs.ts. - Security-relevant actions call
audit(). - Server code logs with
loggerfromlib/logger.ts. - Finish with
npm run check.