nextjs-app-router
Next.js 15 App Router patterns for this project. Use when creating routes, API endpoints, server components, or client components.
When & Why to Use This Skill
This Claude skill provides standardized Next.js 15 App Router patterns and architectural blueprints. It helps developers implement best practices for directory structure, server/client component separation, API route handling, and advanced caching strategies to build scalable, high-performance web applications using the latest Next.js features.
Use Cases
- Architecting a new Next.js 15 project using a modular directory structure (app, client, server, shared) to ensure code maintainability and scalability.
- Developing high-performance Server Components for direct database access and data fetching while minimizing client-side JavaScript bundles.
- Creating robust API Route Handlers with standardized request validation and JSON response patterns for backend integration.
- Implementing sophisticated data fetching and caching strategies using revalidation intervals and dynamic rendering configurations to optimize SEO and performance.
- Setting up consistent error handling and loading UI patterns across the application using Next.js 15's built-in error.tsx and loading.tsx conventions.
| name | nextjs-app-router |
|---|---|
| description | Next.js 15 App Router patterns for this project. Use when creating routes, API endpoints, server components, or client components. |
Next.js 15 App Router
Directory Structure
app/- Routes and API handlersclient/- Client components and utilitiesserver/- Server-side servicesshared/- Shared types and utilities
Route Handlers (API)
// app/api/example/route.ts
import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) {
const body = await request.json();
// Validate with zod schema from shared/validation/
return NextResponse.json({ data });
}
Server Components (Default)
// No 'use client' directive
export default async function Page() {
const data = await fetchData(); // Direct DB/API calls
return <div>{data}</div>;
}
Client Components
'use client';
// Required for: hooks, browser APIs, event handlers, state
import { useState } from 'react';
Data Fetching
- Server Components: Direct async/await
- Client Components: Use
client/utils/api-client.ts
Caching
// Revalidate every hour
export const revalidate = 3600;
// Or disable caching
export const dynamic = 'force-dynamic';
Error Handling
error.tsx- Error boundary per routenot-found.tsx- 404 handlingloading.tsx- Suspense fallback
Metadata
export const metadata = {
title: 'Page Title',
description: 'Page description',
};