NextBase Architecture
Use this repository's existing structure as the source of truth. Inspect neighboring files before creating a new pattern.
Repository Map
apps/webis the Next.js application.apps/databaseowns the local Supabase project, declarative schemas, generated migrations, and pgTap tests.- Root commands delegate work through Turborepo. Put package-specific commands in the owning package, then expose them through
turbo.jsonwhen the whole repository needs them. - Shared packages belong under
packagesonly when more than one app consumes them. Do not create a package to avoid a local import.
Web Placement
src/app/(external-pages): public marketing and informational routes.src/app/(auth-pages): sign-in, sign-up, password, and auth callback routes.src/app/(app-pages): authenticated application routes.src/components/ui: shadcn primitives owned by this repository.src/components: product-level composition around those primitives.src/data/anon: reads that do not require an authenticated action context. The name does not waive RLS.src/data/auth: authentication actions.src/data/user: authenticated mutations and user-scoped queries.src/rsc-data: request-memoized server reads used by React Server Components.src/supabase-clients: browser, server, and middleware Supabase client factories.src/lib: shared application infrastructure;src/utils: focused helpers and adapters.
Boundaries
- Default to Server Components. Add
'use client'only to the smallest interactive leaf. - Keep secrets, cookie access, database clients, and authenticated data access on the server. Mark server-only infrastructure with
import 'server-only'where appropriate. - Treat route protection and hidden UI as navigation conveniences, not authorization. RLS and server-side ownership checks are the trust boundary.
- Validate every mutation at the server action boundary. Never accept an owner or user ID from form input when it is available from authenticated context.
- Use aliases from the existing TypeScript and shadcn configuration. Do not reach across packages with relative imports.
- Preserve route-group intent. Route groups organize layouts and access patterns without changing public URLs.
Change Workflow
- Inspect the closest route, data module, component, and package scripts.
- Choose the owning layer before writing code.
- Reuse an existing client, action client, schema, component, or task rather than introducing a parallel abstraction.
- Verify the narrow package first, then the relevant root task:
pnpm lint,pnpm typecheck,pnpm test, andpnpm buildas risk requires. - For schema, auth, cache, UI, or testing work, also load the matching NextBase overlay and relevant maintainer skill.