agentleFS
vgpateliyavgpateliya/nextjs-fullstack-ai-toolkit/AGENTS.md

nextjs-fullstack-ai-toolkit

AGENTS.md0 starsChanged 3 months agoMITView on GitHub

Canonical rulebook for every AI coding assistant working in this repository — Claude Code, Cursor, Copilot, Codex, Gemini, or anything else that reads AGENTS.md. Read this first, then .ai/rules/project-rules.md. Companion documents: - .ai/rules/ — the enforceable rules, including auto-loaded .mdc rules (also mirrored into .cursor/rules/ for Cursor) - .ai/skills/ — the workflows (plan → build → review → audit → debug → PR) - DESIGN.md — the design-system contract (tokens, typography, component contracts) Adopting this toolkit into an existing project?…

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Always verify hook dependency arrays.

    line 56
  2. Very specific:

    Check components/ui/ before building a new primitive.

    line 63
  3. Distinctive:

    Prefer composition over deeply nested components and prop drilling.

    line 64
  4. Distinctive:

    Prefer explicit props over "magic" behavior and hidden side effects.

    line 65
  5. Very specific:

    Every data-backed route ships loading.tsx and error.tsx.

    line 71
  6. Very specific:

    Use the singleton DB accessor, never new PrismaClient().

    line 76
  7. Very specific:

    Every response resolves to the standard ApiResponse<T> envelope.

    line 77
  8. Very specific:

    No secret is ever exposed behind a NEXT_PUBLIC_ prefix.

    line 89
  9. Very specific:

    Add it to the theme and DESIGN.md first.

    line 93
  10. Distinctive:

    No fetching inside loops — batch or filter.

    line 106
  11. Distinctive:

    Read before editing. Grep for a symbol instead of guessing.

    line 112
  12. Distinctive:

    Run the gates and report the real output.

    line 114
  13. Distinctive:

    Don't reintroduce commented-out or dead code as a "quick win" without confirming intent first — it may be deliberately superseded.

    line 116
  14. Very specific:

    When a symptom is unexplained, get a direct observation of the actual computed value before trying a second speculative fix.

    line 118
  15. Very specific:

    If this app deploys to a serverless/edge runtime, background work needs the platform's execution extension API (not fire-and-forget), and …

    line 126

≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Project Rules for AI Assistants

Canonical rulebook for every AI coding assistant working in this repository — Claude Code, Cursor, Copilot, Codex, Gemini, or anything else that reads AGENTS.md. Read this first, then .ai/rules/project-rules.md.

Companion documents:

  • .ai/rules/ — the enforceable rules, including auto-loaded .mdc rules (also mirrored into .cursor/rules/ for Cursor)
  • .ai/skills/ — the workflows (plan → build → review → audit → debug → PR)
  • DESIGN.md — the design-system contract (tokens, typography, component contracts)

Adopting this toolkit into an existing project? Follow README.md, then edit the stack section below to describe your actual repo. Everything else works as-is.

Stack assumptions

This toolkit targets a Next.js fullstack application:

  • Next.js (App Router) + React + TypeScript in strict mode
  • PostgreSQL via Prisma (or an equivalent server-only data layer)
  • TanStack React Query for server state; Redux Toolkit (optional) for client UI state
  • React Hook Form + Zod for forms and payload validation
  • Material UI + Tailwind CSS driven by shared design tokens, with dark mode
  • pnpm, ESLint, husky + lint-staged

Adjust the names, keep the boundaries.

Architecture

Client Component
  └─ React Query hook (hooks/queries/)
       └─ Fetcher (lib/api/fetchers/)
            └─ axiosClient / typed HTTP client
                 ↓
              proxy.ts | middleware.ts      ← session guard, explicit public allow-list
                 ↓
        app/api/**/route.ts                 ← withHandler(schema) only, no logic
                 ↓
   server/<domain>/*.controller.ts          ← orchestration, authorization, mapping
                 ↓
   server/<domain>/*.service.ts             ← the ONLY place the DB client is called
                 ↓
        getPrisma() → PostgreSQL

Server Components (page.tsx) own metadata/SEO. Client Components (Client*.tsx) own interactive UI. Full lifecycle and a new-module checklist: .ai/skills/project-development/references/architecture-overview.md.

TypeScript & React

  • TypeScript everywhere, strict mode, no any without an inline justification.
  • Functional components and hooks only; const over let.
  • useMemo / useCallback / memo only when there is a measurable reason.
  • Always verify hook dependency arrays. Never use an array index as a key for dynamic lists.
  • Data fetching goes through React Query hooks — never fetch inside useEffect.
  • Guard API data with Array.isArray() before mapping.

Components & Architecture

  • Soft limit ~400 lines per file, hard limit ~500 — split before exceeding it.
  • Rendering components stay focused on UI; orchestration moves to hooks, business logic to services.
  • Check components/ui/ before building a new primitive. Used in 2+ places → extract it.
  • Prefer composition over deeply nested components and prop drilling.
  • Prefer explicit props over "magic" behavior and hidden side effects.

Server / Client Boundary

  • "use client" only for state, hooks, browser APIs, or event handlers — never on a page.tsx.
  • Database clients, secrets, mail transports and session signing are server-only and must never be reachable from the browser bundle.
  • Every data-backed route ships loading.tsx and error.tsx.

API & Data

  • Route handlers are thin wrappers around the standard handler, with a Zod schema for every mutating method. Controllers orchestrate. Services own all queries.
  • Use the singleton DB accessor, never new PrismaClient().
  • Every response resolves to the standard ApiResponse<T> envelope. Never swallow an error into a log line and return success.
  • Select columns explicitly when a row holds secrets. Avoid N+1; batch or include. Multi-step writes go in a transaction.

No Hardcoded Strings

  • Endpoints → constants/apiEndpoints.ts
  • Routes → constants/routes.ts
  • Query keys → constants/queryKeys.ts
  • Env vars → constants/env.ts (ENV server-side, CLIENT_ENV for NEXT_PUBLIC_*)
  • Colors, spacing, radius, fonts → design tokens (see DESIGN.md)

No secret is ever exposed behind a NEXT_PUBLIC_ prefix.

Styling & Design System

  • Theme tokens only — no hex literals, no arbitrary values for themed properties. Missing token? Add it to the theme and DESIGN.md first.
  • Headings use font-heading; body copy uses font-sans.
  • Loading, empty, error and disabled states are part of the UI, not optional extras.
  • Accessible by default: real interactive elements, labelled inputs, visible focus, keyboard paths, colour never the only signal.
  • Responsive by default; verified in both light and dark themes.

Forms & Validation

  • react-hook-form + @hookform/resolvers/zod. No complex form state in raw useState.
  • Zod schemas live in lib/validations/schemas.ts; user-facing copy in lib/validations/messages.ts.
  • The same schema validates the client form and the server payload.

Performance

  • No fetching inside loops — batch or filter.
  • Siblings needing the same data: lift the fetch to a shared hook or parent.
  • Lazy-load heavy views. Avoid unstable object/function references that force re-renders.

Working Discipline

  • Implement what was asked; do not widen scope or refactor adjacent code in the same pass.
  • Read before editing. Grep for a symbol instead of guessing. Never invent a file, export, column or migration.
  • Run the gates and report the real output. "Should work" is not a result.
  • Report what you changed and what you skipped, including risky assumptions.
  • Don't reintroduce commented-out or dead code as a "quick win" without confirming intent first — it may be deliberately superseded.
  • When a symptom is unexplained, get a direct observation of the actual computed value before trying a second speculative fix. See .ai/skills/debug-systematically and .ai/rules/common-pitfalls.mdc.
  • See .ai/rules/agent-discipline.mdc for the full version.

Rendering & Data

  • Render a component, section, or element only when the specific field it depends on is present — never on the parent object merely existing. See .ai/rules/data-presence-rendering.mdc.
  • If this app deploys to a serverless/edge runtime, background work needs the platform's execution extension API (not fire-and-forget), and nothing may assume in-memory state survives between invocations. See .ai/rules/serverless-safe-patterns.mdc.
  • A credential or role always uses the narrowest scope for what it acts on; a permission at a narrower scope is capped to the broader baseline, never additive. See .ai/rules/least-privilege-scoping.mdc.

Which Skills to Use

SituationSkill
Non-trivial feature, refactor, or architectural changetask-brief
Implementing anythingproject-development
Behavior doesn't match expectation, a bug report, prod-only failuredebug-systematically
Before declaring work donecode-review
The change touched UIdesign-audit
Branch is ready for a PRgenerate-pr-description

Definition of Done

  1. The code implements the requirement without breaking existing patterns.
  2. It has been validated against .ai/rules/project-rules.md.
  3. code-review has been run; all [BLOCKING] findings are fixed and [HUMAN REVIEW] findings surfaced. UI changes also passed design-audit. A bug fix went through debug-systematically and was verified against the original reproduction, not just against the new code.
  4. The type-check gate passes.
  5. The lint gate passes (also enforced by husky + lint-staged on commit).
  6. What changed — and anything skipped — is reported honestly.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.