Opinionated coding standards and architecture rules for Next.js + TypeScript projects. Designed to be consumed by AI coding agents (Claude Code, Cursor, etc.) and human developers alike.
A single .rules/ directory with markdown files covering:
- Architecture — Next.js App Router folder structure, Server vs Client Components
- TypeScript — strictness, naming, generics, unions over enums
- Components — layering (
ui/,forms/,layout/), props typing - State management — Zustand + React Query, with RSC boundary rules
- API layer — Server Components, Route Handlers, Server Actions, Zod validation
- Styling — Tailwind CSS conventions, theme tokens,
next/font,next/image - Forms — React Hook Form + Zod, error recovery, server actions
- Testing — Jest + React Testing Library, Playwright for E2E
- Git — commit format, branch naming, rebase workflow, PR size limits
- Code quality — ESLint, Prettier, file-length guidelines, imports, JSDoc
- Security — env var handling, CSP, cookies, CSRF, XSS prevention
- Error handling —
error.tsx,not-found.tsx, toast system, network error mapping - Accessibility — semantic HTML, ARIA, keyboard navigation, WCAG contrast
- Firebase — web SDK setup, account deletion flow, security rules
- Performance —
next/image,next/font, bundle size, Core Web Vitals - SEO — Metadata API,
sitemap.ts,robots.ts, Open Graph - Deployment — Vercel, env vars, preview deploys, branch → environment mapping
- AI agent behavior — mandatory rules every agent must follow before writing code
- Projects using: Next.js (App Router), TypeScript, Tailwind CSS, Zustand, React Query, React Hook Form + Zod, Firebase web SDK.
- Projects hosting on: Vercel (primary), though most rules are host-agnostic.
- AI-assisted development: these rules are written to be consumed by AI agents (Claude Code, Cursor, Continue, etc.) via a top-level
CLAUDE.mdorAGENTS.mdpointing agents here.
If your project doesn't match this stack, adapt or fork.
- Copy the
.rules/folder into the root of your project. - Copy
CLAUDE.md.exampleto your project root asCLAUDE.md(orAGENTS.md). - Gitignore
.rules/,CLAUDE.md, andAGENTS.mdif you want them to be local-only. Commit them if the whole team should share the rules.
git submodule add <this-repo-url> .rulesAdd to your top-level CLAUDE.md:
# Project Rules
You MUST read and follow all rule files in the `.rules/` directory before writing any code.
Start by reading `.rules/ai-agent-behavior.md`.ln -s ~/path/to/nextjs-coding-rules/.rules .rulesThen gitignore the symlink.
RULES.md— table of contents and tech stack summary.ai-agent-behavior.md— mandatory agent rules (read before writing any code).- Any file relevant to the task at hand.
These rules evolve. When you change a rule:
- Update the file.
- Bump a mental version — if behavior changes materially, consider tagging a release.
- Notify teammates / your agent that the rules have changed.
MIT — see LICENSE.