Skip to content
nextjs-best-practices logo

Next.js Best Practices

nextjs-best-practices

Next.js App Router principles. Server Components, data fetching, routing patterns.

lchenrique/politron-ide0installs0stars

SKILL.md

Full skill instructions

Next.js Best Practices

Principles for Next.js App Router development.


1. Server vs Client Components

Decision Tree

Does it need...?
│
├── useState, useEffect, event handlers
│   └── Client Component ('use client')
│
├── Direct data fetching, no interactivity
│   └── Server Component (default)
│
└── Both? 
    └── Split: Server parent + Client child

By Default

TypeUse
ServerData fetching, layout, static content
ClientForms, buttons, interactive UI

2. Data Fetching Patterns

Fetch Strategy

PatternUse
DefaultStatic (cached at build)
RevalidateISR (time-based refresh)
No-storeDynamic (every request)

Data Flow

SourcePattern
DatabaseServer Component fetch
APIfetch with caching
User inputClient state + server action

3. Routing Principles

File Conventions

FilePurpose
page.tsxRoute UI
layout.tsxShared layout
loading.tsxLoading state
error.tsxError boundary
not-found.tsx404 page

Route Organization

PatternUse
Route groups (name)Organize without URL
Parallel routes @slotMultiple same-level pages
Intercepting (.)Modal overlays

4. API Routes

Route Handlers

MethodUse
GETRead data
POSTCreate data
PUT/​PATCHUpdate data
DELETERemove data

Best Practices

  • Validate input with Zod
  • Return proper status codes
  • Handle errors gracefully
  • Use Edge runtime when possible

5. Performance Principles

Image Optimization

  • Use next/​image component
  • Set priority for above-fold
  • Provide blur placeholder
  • Use responsive sizes

Bundle Optimization

  • Dynamic imports for heavy components
  • Route-based code splitting (automatic)
  • Analyze with bundle analyzer

6. Metadata

Static vs Dynamic

TypeUse
Static exportFixed metadata
generateMetadataDynamic per-route

Essential Tags

  • title (50-60 chars)
  • description (150-160 chars)
  • Open Graph images
  • Canonical URL

7. Caching Strategy

Cache Layers

LayerControl
Requestfetch options
Datarevalidate/​tags
Full routeroute config

Revalidation

MethodUse
Time-basedrevalidate: 60
On-demandrevalidatePath/​Tag
No cacheno-store

8. Server Actions

Use Cases

  • Form submissions
  • Data mutations
  • Revalidation triggers

Best Practices

  • Mark with 'use server'
  • Validate all inputs
  • Return typed responses
  • Handle errors

9. Anti-Patterns

❌ Don't✅ Do
'use client' everywhereServer by default
Fetch in client componentsFetch in server
Skip loading statesUse loading.tsx
Ignore error boundariesUse error.tsx
Large client bundlesDynamic imports

10. Project Structure

app/
├── (marketing)/     # Route group
│   └── page.tsx
├── (dashboard)/
│   ├── layout.tsx   # Dashboard layout
│   └── page.tsx
├── api/
│   └── [resource]/
│       └── route.ts
└── components/
    └── ui/

Remember: Server Components are the default for a reason. Start there, add client only when needed.

More skills from lchenrique

bash-linux logo
lchenrique/politron-ide

bash-linux

Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

0 0
View
api-patterns logo
lchenrique/politron-ide

api-patterns

API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.

0 0
View
deployment-procedures logo
lchenrique/politron-ide

deployment-procedures

Production deployment principles and decision-making. Safe deployment workflows, rollback strategies, and verification. Teaches thinking, not scripts.

0 0
View
game-design logo
lchenrique/politron-ide

game-design

Game design principles. GDD structure, balancing, player psychology, progression.

0 0
View
game-audio logo
lchenrique/politron-ide

game-audio

Game audio principles. Sound design, music integration, adaptive audio systems.

0 0
View
architecture logo
lchenrique/politron-ide

architecture

Architectural decision-making framework. Requirements analysis, trade-off evaluation, ADR documentation. Use when making architecture decisions or analyzing system design.

0 0
View
mobile-games logo
lchenrique/politron-ide

mobile-games

Mobile game development principles. Touch input, battery, performance, app stores.

0 0
View
parallel-agents logo
lchenrique/politron-ide

parallel-agents

Multi-agent orchestration patterns. Use when multiple independent tasks can run with different domain expertise or when comprehensive analysis requires multiple perspectives.

0 0
View
brainstorming logo
lchenrique/politron-ide

brainstorming

Socratic questioning protocol + user communication. MANDATORY for complex requests, new features, or unclear requirements. Includes progress reporting and error handling.

0 0
View
i18n-localization logo
lchenrique/politron-ide

i18n-localization

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

0 0
View
geo-fundamentals logo
lchenrique/politron-ide

geo-fundamentals

Generative Engine Optimization for AI search engines (ChatGPT, Claude, Perplexity).

0 0
View
multiplayer logo
lchenrique/politron-ide

multiplayer

Multiplayer game development principles. Architecture, networking, synchronization.

0 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View