nextjs-patterns

$npx mdskill add tranhieutt/software_development_department/nextjs-patterns

Provides comprehensive Next.js App Router development patterns and workflows.

  • Solves the complexity of building modern Next.js apps with App Router.
  • Depends on Next.js 14+, TypeScript, Tailwind CSS, and file-based routing.
  • Decides based on server vs. client component rules and route organization.
  • Delivers patterns via SKILL.md reference for direct agent use.

SKILL.md

.github/skills/nextjs-patternsView on GitHub ↗
---
name: nextjs-patterns
type: reference
description: "Comprehensive Next.js development patterns for App Router, Server Components, TypeScript, and Tailwind CSS. Covers foundational principles, data fetching, routing, performance, and an 8-phase development workflow. Also includes Server Actions and Metadata patterns."
paths: ["**/*.tsx", "**/*.jsx", "**/next.config.*", "**/app/**/*.ts", "**/tailwind.config.*"]
when_to_use: "Building or optimizing Next.js 14+ / 15+ applications with App Router, Server Components, streaming, or Server Actions."
allowed-tools: Read, Glob, Grep, Write, Edit, Bash
user-invocable: true
effort: 3
---

# 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
| Pattern | Use Case | Implementation |
|---------|----------|----------------|
| **Static** | Blog posts, marketing | Cached at build time |
| **ISR** | Products, news | `revalidate: 60` |
| **Dynamic** | User dashboards, search | `no-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.

More from tranhieutt/software_development_department

SkillDescription
agent-healthReads production/traces/agent-metrics.jsonl and displays a per-agent performance summary table for the current or a specified session. Highlights agents with high error rates or OPEN circuit breaker state.
agent-styleProvides the vendored agent-style v0.3.5 prose rule pack as a portable Claude skill. Use when installing, syncing, applying, or auditing SDD Agent-Style support in another project, or when a style-review workflow needs the bundled rules.
angular-best-practicesProvides Angular best practices for components, modules, services, and reactive patterns. Use when working with Angular TypeScript files, component templates, NgModules, RxJS observables, or when the user mentions Angular, ng, or Angular CLI.
annotateRecords unexpected API behaviors, undocumented caveats, version bugs, or non-obvious workarounds into .claude/memory/annotations.md. Use immediately when an undocumented behavior or surprising caveat is discovered during development.
aws-serverlessProvides AWS serverless architecture patterns for Lambda, API Gateway, DynamoDB, SQS, and SAM/CDK. Use when working with AWS serverless files (serverless.yml, CDK stacks) or when the user mentions Lambda, API Gateway, serverless, or AWS SAM.
backend-architectDesigns scalable backend architectures covering microservices, event-driven systems, API gateways, and data stores. Use when designing a backend system or when the user mentions backend architecture, scalability, or distributed systems.
cloud-run-puppeteerDeploys Puppeteer browser automation on Google Cloud Run with Docker. Use when running headless browser tasks on Cloud Run, or when the user mentions Cloud Run, Puppeteer, headless Chrome, or serverless browser automation.
codex-sddAdapts SDD for Codex while preserving Claude Code behavior. Use when working in Codex, setting up Codex compatibility, mapping Claude tools to Codex tools, or explaining how SDD should run outside Claude Code.
database-architectDesigns relational and NoSQL database schemas, indexing strategies, migration plans, and data modeling patterns. Use when designing a database or when the user mentions database architecture, schema design, or data modeling.
db-reviewReviews database schemas, queries, and migrations for correctness, performance, security, and best practices. Use when reviewing SQL migration files or when the user mentions database review, schema review, or query audit.