nextjs-patterns
Skill3 starsChanged 7 months agoMITView on GitHub
Next.js 15+ App Router best practices. Covers server components, data fetching, caching, middleware, and deployment patterns. Use when building Next.js applications or reviewing Next.js code.
Files
Next.js Patterns
Modern Next.js 15+ App Router patterns and best practices.
Server vs Client Components
Default to Server Components
// app/users/page.tsx (Server Component by default)
export default async function UsersPage() {
const users = await db.user.findMany(); // Direct DB access
return <UserList users={users} />;
}Client Components for Interactivity
'use client';
// Only add 'use client' when you need:
// - useState, useEffect, useRef
// - Event handlers (onClick, onChange)
// - Browser APIs (window, localStorage)
// - Third-party client libraries
export function SearchBar() {
const [query, setQuery] = useState('');
return <input value={query} onChange={e => setQuery(e.target.value)} />;
}Composition Pattern
// Server Component (parent) passes data to Client Component (child)
export default async function Page() {
const data = await fetchData(); // Server-side
return <InteractiveChart data={data} />; // Client-side interactivity
}Data Fetching
Server Component Fetching
// Direct async/await in Server Components
async function UserProfile({ userId }: { userId: string }) {
const user = await db.user.findUnique({ where: { id: userId } });
if (!user) notFound();
return <div>{user.name}</div>;
}Parallel Data Fetching
export default async function Dashboard() {
// Fetch in parallel, not waterfall
const [users, stats, recent] = await Promise.all([
getUsers(),
getStats(),
getRecentActivity(),
]);
return (
<>
<UserList users={users} />
<StatsPanel stats={stats} />
<ActivityFeed items={recent} />
</>
);
}Server Actions
// app/actions.ts
'use server';
export async function createUser(formData: FormData) {
const name = formData.get('name') as string;
const email = formData.get('email') as string;
// Validate
const validated = UserSchema.parse({ name, email });
// Write to database
await db.user.create({ data: validated });
// Revalidate
revalidatePath('/users');
}Caching and Revalidation
Route Segment Config
// Static page (default)
export const dynamic = 'auto';
// Always dynamic (no cache)
export const dynamic = 'force-dynamic';
// Revalidate every 60 seconds
export const revalidate = 60;On-Demand Revalidation
import { revalidatePath, revalidateTag } from 'next/cache';
// Revalidate specific path
revalidatePath('/users');
// Revalidate by tag
revalidateTag('users');Middleware
// middleware.ts (root level)
import { NextResponse } from 'next/server';
export function middleware(request: NextRequest) {
// Authentication check
const token = request.cookies.get('session');
if (!token && request.nextUrl.pathname.startsWith('/dashboard')) {
return NextResponse.redirect(new URL('/login', request.url));
}
// Add security headers
const response = NextResponse.next();
response.headers.set('X-Frame-Options', 'DENY');
return response;
}
export const config = {
matcher: ['/dashboard/:path*', '/api/:path*'],
};File Structure
app/
├── layout.tsx # Root layout (shared UI)
├── page.tsx # Home page
├── loading.tsx # Loading UI (Suspense)
├── error.tsx # Error boundary
├── not-found.tsx # 404 page
├── (auth)/ # Route group (no URL segment)
│ ├── login/page.tsx
│ └── register/page.tsx
├── dashboard/
│ ├── layout.tsx # Dashboard layout
│ ├── page.tsx
│ └── settings/page.tsx
└── api/
└── users/route.ts # API route handlerChecklist
- Server Components by default (add 'use client' only when needed)
- Parallel data fetching with Promise.all
- Server Actions for mutations
- Proper loading.tsx and error.tsx at each route level
- Middleware for auth and security headers
- Caching configured per route
- Metadata exported for SEO
- Images use next/image with proper sizing
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- tranhieutt/software_development_department★ 71same name
- Nadav011/apex-skills★ 0same name
- theyoungastronauts/waypoint-md★ 0same name
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.
In this repository72 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- api-designerSkill
- backend-patternsSkill
- code-reviewerSkill
- debugging-assistantSkill
- golang-testingSkill
- project-guidelines-exampleSkill
- python-testingSkill
- refactoring-guideSkill
- spec-driven-developmentSkill
- tdd-workflowSkill
- verification-loopSkill
- update-docsSkill
- api-docsSkill
- changelog-writerSkill
- readme-generatorSkill
- django-patternsSkill
- django-securitySkill
- django-tddSkill
- django-verificationSkill
- fastapi-patternsSkill
- react-patternsSkill
- springboot-patternsSkill
- springboot-securitySkill
- springboot-tddSkill
- branch-strategySkill
- changelogSkill
- commit-helperSkill
- pr-creatorSkill
- prSkill
- evolveSkill
- instinct-exportSkill
- instinct-importSkill
- instinct-statusSkill
- cleanupSkill
- lint-fixSkill
- refactor-cleanSkill
- update-depsSkill
- continuous-learningSkill
- continuous-learning-v2Skill
- eval-harnessSkill
- iterative-retrievalSkill
- strategic-compactSkill
- golang-patternsSkill
- python-patternsSkill
- rust-patternsSkill
- typescript-patternsSkill
- accessibility-checkerSkill
- build-fixSkill
- code-reviewSkill
- e2eSkill
- performance-reviewerSkill
- security-auditorSkill
- security-reviewSkill
- test-coverageSkill
- checkpointSkill
- deploySkill
- evalSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

