agentleFS
tranhieutttranhieutt/software_development_department/.claude/skills/nextjs-patterns/SKILL.md

nextjs-patterns

Skill71 starsChanged 7 months agoMITView on GitHub

Comprehensive patterns and best practices for Next.js 14+ / 15+ App Router architecture, Server Components, and modern full-stack React development. Guidance: If you need deeper walkthroughs, refer to the resources/ folder within this skill.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 4 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Server (Default): Use for data fetching, layouts, and static content.

    line 21
  2. Distinctive:

    Client ('use client'): Use for interactivity (useState, useEffect), event handlers, and browser-only APIs.

    line 22
  3. Very specific:

    App Router: Use the app/ directory for file-based routing.

    line 26
  4. Very specific:

    Streaming: Use Suspense and loading.tsx to stream UI to the client.

    line 44
  5. Distinctive:

    Use React Hook Form and Zod for robust, type-safe data entry.

    line 67
  6. Very specific:

    Write unit/integration tests with Vitest and E2E flows with @playwright-skill.

    line 70
  7. Very specific:

    Images: Always use next/image. Set priority for LCP elements.

    line 79
  8. Distinctive:

    Dynamic Imports: Use for heavy client-side libraries.

    line 80
  9. Very specific:

    Metadata API: Use generateMetadata for dynamic SEO tags per route.

    line 81

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “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
SKILL.md

Next.js Development Patterns

Comprehensive patterns and best practices for Next.js 14+ / 15+ App Router architecture, Server Components, and modern full-stack React development.


1. Foundational Principles

Server vs Client Components

  • Server (Default): Use for data fetching, layouts, and static content.
  • Client ('use client'): Use for interactivity (useState, useEffect), event handlers, and browser-only APIs.
  • Decision Rule: Stay on the server as long as possible. Split components so the interactive "leaf nodes" are client-side while the data-heavy "branch nodes" remain on the server.

Routing & Organization

  • App Router: Use the app/ directory for file-based routing.
  • Route Groups: (group-name) for organization without affecting URL structure.
  • Special Files: page.tsx, layout.tsx, loading.tsx, error.tsx, not-found.tsx.
  • Advanced Routing: Parallel routes (@slot) and Intercepting routes ((.)).

2. Data Fetching & Caching

Strategy Matrix

PatternUse CaseImplementation
StaticBlog posts, marketingCached at build time
ISRProducts, newsrevalidate: 60
DynamicUser dashboards, searchno-store or force-dynamic

Patterns

  • Server Fetching: Fetch data directly in Server Components using async/await.
  • Streaming: Use Suspense and loading.tsx to stream UI to the client.
  • Server Actions: Perform mutations with use server functions. Validate with Zod.

3. 8-Phase Development Workflow

Phase 1: Project Setup

Scaffold with @app-builder, configure TypeScript, and set up ESLint/Prettier.

Phase 2: Component Architecture

Design hierarchy and implement base layout components using @frontend-developer and @react-patterns.

Phase 3: Styling & Design

Configure Tailwind CSS v4 and design tokens using @tailwind-patterns and @frontend-design.

Phase 4: Data Fetching

Implement Server Component data fetching and set up React Query/SWR if client-side fetching is needed.

Phase 5: Routing & Navigation

Set up file-based routing, dynamic routes, and handle redirects/guards.

Phase 6: Forms & Validation

Use React Hook Form and Zod for robust, type-safe data entry.

Phase 7: Testing

Write unit/integration tests with Vitest and E2E flows with @playwright-skill.

Phase 8: Optimization & Deploy

Analyze bundle size, optimize images with next/image, and deploy to Vercel/similar.


4. Performance & Metadata

  • Images: Always use next/image. Set priority for LCP elements.
  • Dynamic Imports: Use for heavy client-side libraries.
  • Metadata API: Use generateMetadata for dynamic SEO tags per route.

Resources & Anti-Patterns

  • implementation-playbook.md: Detailed code examples for every pattern.
  • Anti-Pattern: Using 'use client' at the top level of every file.
  • Anti-Pattern: Fetching data inside useEffect for information available on first load.

Guidance: If you need deeper walkthroughs, refer to the resources/ folder within this skill.

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.