agent-skills / accelint-nextjs-best-practices
AGENTS.md25 starsChanged 54 days agoApache-2.0View on GitHub
Note: This document is mainly for agents and LLMs to follow when maintaining, generating, or refactoring Next.js code. Humans may also find it useful, but guidance here is optimized for automation and consistency by AI-assisted workflows. Comprehensive performance optimization guide for Next.js applications, designed for AI agents and LLMs. Each rule includes one-line summaries with links to detailed examples in references/. Load reference files only when implementing a specific pattern. Focus: Next.js App Router patterns including Server Components, Server Actions,…
We split this AGENTS.md into the rules it gives an agent
14 rules. About 0 are common, 12 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 33
Not sure what's wrong? → Use Quick Diagnostic Guide below
- Distinctive: line 42
Use this guide to quickly identify which optimization applies based on symptoms:
- Distinctive: line 53
Not sure if component should be client or server → 3.2 Server vs Client Component
- Distinctive: line 69
Start independent operations immediately in API routes/Server Actions, even if you don't await them yet.
- Distinctive: line 73
Use Promise.allSettled() to run fully independent async operations concurrently.
- Distinctive: line 77
Use Suspense to show wrapper UI immediately while data loads, instead of blocking entire page.
- Distinctive: line 87
Always verify authentication and authorization inside each Server Action—treat them as public endpoints.
- Distinctive: line 95
Only pass fields the client actually uses—every prop is serialized into HTML.
- Very specific: line 117
Import directly from source files instead of barrel files (index.js re-exports) to avoid loading thousands of unused modules.
- Very specific: line 130
When writing or reviewing Next.js code, prioritize in this order:
- Distinctive: line 169
Parallelization: - Start independent operations immediately
- Distinctive: line 170
Minimization: - Only serialize what the client uses
- Distinctive: line 171
Streaming: - Use Suspense boundaries strategically
- Distinctive: line 173
Default to Server: - Only use Client Components when needed
≈ “Common” is an estimate: at least 1 in 5 of the 36,368 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.
Files
Next.js Best Practices
Note: This document is mainly for agents and LLMs to follow when maintaining, generating, or refactoring Next.js code. Humans may also find it useful, but guidance here is optimized for automation and consistency by AI-assisted workflows.
Abstract
Comprehensive performance optimization guide for Next.js applications, designed for AI agents and LLMs. Each rule includes one-line summaries with links to detailed examples in references/. Load reference files only when implementing a specific pattern.
Focus: Next.js App Router patterns including Server Components, Server Actions, RSC serialization, and server-side optimization.
- For React specific patterns, use the
accelint-react-best-practicesskill. - For JavaScript/TypeScript specific patterns, use the
accelint-ts-best-practicesskill. - For Testing patterns, use the
accelint-ts-testingskill.
How to Use This Guide
For agents/LLMs:
- Scan rule summaries below to identify relevant optimizations
- Load reference files only when implementing a specific pattern
- Each reference is self-contained with ❌/✅ examples
Quick shortcuts:
- Security issues? → 2.1 (Server Actions authentication)
- Waterfall issues? → 1.1-1.2 (Parallelization)
- Large HTML payload? → 2.2-2.3 (Serialization optimization)
- Slow page loads? → 1.3 (Suspense), 2.4 (Parallel data fetching)
- Real-world examples? → Compound Patterns
- Not sure what's wrong? → Use Quick Diagnostic Guide below
Next.js Resources:
Quick Diagnostic Guide
Use this guide to quickly identify which optimization applies based on symptoms:
Symptom → Solution:
- API route or Server Action is slow → 1.1 Prevent Waterfall Chains, 1.2 Parallelize Operations
- Entire page waits for data → 1.3 Strategic Suspense Boundaries
- Server Action can be called without login → 2.1 Authenticate Server Actions
- HTML response is huge → 2.3 Minimize Serialization, 2.2 Avoid Duplicate Serialization
- Data fetches happen sequentially → 2.4 Parallel Data Fetching with Composition
- Same query runs multiple times per request → 2.5 Per-Request Deduplication
- Logging/analytics blocks response → 2.6 Use after() for Non-Blocking Operations
- Development server is slow to start → 3.1 Avoid Barrel File Imports
- Not sure if component should be client or server → 3.2 Server vs Client Component
- Data is duplicated in RSC props → 2.2 Avoid Duplicate Serialization
- Cache not working with React.cache() → 2.5 Per-Request Deduplication (avoid inline objects)
Security Issues:
- Server Action has no auth check → 2.1 Authenticate Server Actions
- Server Action doesn't validate input → 2.1 Authenticate Server Actions (with Zod validation)
- Server Action allows unauthorized mutations → 2.1 Authenticate Server Actions (authorization check)
1. General
Core patterns for optimal server-side execution in Next.js App Router.
1.1 Prevent Waterfall Chains
Start independent operations immediately in API routes/Server Actions, even if you don't await them yet. View detailed examples
1.2 Parallelize Independent Operations
Use Promise.allSettled() to run fully independent async operations concurrently. View detailed examples
1.3 Strategic Suspense Boundaries
Use Suspense to show wrapper UI immediately while data loads, instead of blocking entire page. View detailed examples
2. Server-Side Performance
Optimizing server-side rendering and data fetching eliminates server-side waterfalls and reduces response times. These patterns are specific to Next.js App Router and RSC (React Server Components).
2.1 Authenticate Server Actions Like API Routes
Always verify authentication and authorization inside each Server Action—treat them as public endpoints. View detailed examples
2.2 Avoid Duplicate Serialization in RSC Props
RSC deduplicates by reference, not value. Do transformations (.toSorted(), .filter(), .map()) in client, not server. View detailed examples
2.3 Minimize Serialization at RSC Boundaries
Only pass fields the client actually uses—every prop is serialized into HTML. View detailed examples
2.4 Parallel Data Fetching with Component Composition
Restructure Server Component tree so siblings fetch data in parallel, not sequentially. View detailed examples
2.5 Per-Request Deduplication with React.cache()
Wrap database queries and auth checks with React.cache() to deduplicate within a request. Use primitives as arguments, not inline objects. View detailed examples
2.6 Use after() for Non-Blocking Operations
Schedule logging, analytics, and side effects to run after response is sent using Next.js's after(). View detailed examples
3. Misc
Additional optimization patterns for Next.js applications.
3.1 Avoid Barrel File Imports
Import directly from source files instead of barrel files (index.js re-exports) to avoid loading thousands of unused modules. View detailed examples
3.2 Server vs. Client Component
Decision tree: Server Components are DEFAULT. Only use 'use client' when you need hooks, events, or browser APIs. View detailed examples
Summary
Priority Checklist
When writing or reviewing Next.js code, prioritize in this order:
1. Security First (Critical)
- ✅ Authenticate all Server Actions (2.1)
- ✅ Validate all Server Action inputs with schemas
- ✅ Check authorization before mutations
2. Eliminate Waterfalls (High Impact)
- ✅ Start independent operations immediately (1.1)
- ✅ Use Promise.allSettled() for parallel operations (1.2)
- ✅ Restructure with component composition (2.4)
3. Optimize Serialization (High Impact)
- ✅ Pass only necessary fields to client (2.3)
- ✅ Avoid duplicate serialization (2.2)
- ✅ Share object references when possible
4. Strategic Suspense (Medium Impact)
- ✅ Use Suspense boundaries to prevent blocking (1.3)
- ✅ Pass promises to components with
use()hook - ✅ Show wrapper UI while data loads
5. Caching & Non-Blocking (Medium Impact)
- ✅ Use React.cache() for deduplication (2.5)
- ✅ Use after() for non-blocking operations (2.6)
- ✅ Avoid inline objects in cache keys
6. Import Optimization (Low Impact, High Frequency)
- ✅ Avoid barrel file imports (3.1)
- ✅ Import directly from source files
7. Component Decisions (As Needed)
- ✅ Use Server Components by default (3.2)
- ✅ Only add 'use client' when necessary
- ✅ Preserve Server/Client boundaries with composition
Key Principles
- Security - Server Actions are public endpoints, always authenticate
- Parallelization - Start independent operations immediately
- Minimization - Only serialize what the client uses
- Streaming - Use Suspense boundaries strategically
- Caching - Deduplicate with React.cache()
- Default to Server - Only use Client Components when needed
Related Skills
- accelint-react-best-practices - React specific patterns and optimizations
- accelint-ts-best-practices - JavaScript/TypeScript patterns and optimizations
- accelint-ts-testing - Vitest patterns and optimizations
Other versions1 project uses a version of this.
Word for word · 1
- davidanthonyn/claude-skills★ 0100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 28,693 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/accelint-design-foundation/AGENTS.mdAGENTS.md
- skills/accelint-eval-architect/AGENTS.mdAGENTS.md
- skills/accelint-prompt-manager/AGENTS.mdAGENTS.md
- skills/accelint-react-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-react-testing/AGENTS.mdAGENTS.md
- skills/accelint-readme-writer/AGENTS.mdAGENTS.md
- skills/accelint-security-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-skill-manager/AGENTS.mdAGENTS.md
- skills/accelint-skill-manager/references/agents.mdAGENTS.md
- skills/accelint-ts-best-practices/AGENTS.mdAGENTS.md
- skills/accelint-ts-documentation/AGENTS.mdAGENTS.md
- skills/accelint-ts-performance/AGENTS.mdAGENTS.md
- skills/accelint-ts-testing/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- accelint-ac-to-playwrightSkill
- accelint-architecture-docSkill
- accelint-archive-synthesisSkill
- accelint-design-foundationSkill
- accelint-english-managerSkill
- accelint-eval-architectSkill
- accelint-nextjs-best-practicesSkill
- accelint-onboard-agentsSkill
- accelint-onboard-openspecSkill
- accelint-persona-reviewSkill
- accelint-prompt-managerSkill
- accelint-qrspi-applySkill
- accelint-qrspi-archiveSkill
- accelint-qrspi-proposeSkill
- accelint-react-best-practicesSkill
- accelint-react-testingSkill
- accelint-readme-writerSkill
- accelint-security-best-practicesSkill
- referencesSkill
- accelint-skill-managerSkill
- accelint-skill-proseSkill
- accelint-tanstack-query-best-practicesSkill
- accelint-ts-audit-allSkill
- accelint-ts-best-practicesSkill
- accelint-ts-documentationSkill
- accelint-ts-performanceSkill
- accelint-ts-testingSkill
- constraints-extractorSkill
- context-driftSkill
- epistemic-mapperSkill
- generate-docsSkill
- jargon-extractorSkill
- pr-descriptionSkill
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
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.

