nextjs-conventions
Applies Next.js conventions: schema-validated input, Server Components by default, Server Actions with typed results, forward-only migrations and consented analytics.
- Group
- Conventions
- Kind
- Read-only
- Loads when
- Writing or reviewing Next.js app code or
next.configfiles
When it runs
When Next.js app code or next.config files are being written or reviewed. Claude loads it on its own when the description matches the file or the task; it never writes anything itself. It matches:
- Next.js app code
- next.config files
The conventions
- Validate every input. Form and API input goes through a schema validator, for example Zod with
.safeParse(). - Server Components by default.
'use client'only for state or event handling. - Server Actions with typed results. Preferred over API routes when possible, returning a typed result whose
erroris the{ code, message, details? }object from error-handling-conventions. - Forward-only migrations. Follow the project's migration policy; without one, write forward-only migrations.
- One source of truth for tokens. When the project has a
DESIGN.md, record indocs/decisions/whether it generates the Tailwind theme or the reverse, and keep the other side in sync. - Analytics through the wrapper. Route analytics calls through the project's tracking wrapper when one exists, behind a consent gate where the platform requires consent.
{ ok: true, data? } | { ok: false, error }
Related
- error-handling-conventions defines the error object.
- typescript-conventions: TypeScript rules that apply alongside.
- testing-conventions: how to test the new code.