Next.js & React

Next.js App Router: Patterns I Reach for on Every Project

Server Components, route groups, streaming and server actions — the handful of patterns that keep my Next.js codebases fast and easy to reason about.

Habib Ur RehmanBy Senior Full Stack Engineer & MVP Partner
  • Published
  • Updated
  • 8 min read
A code editor with dark theme showing JavaScript test code on a monitor

Key takeaways

  • Default to Server Components and add 'use client' only where state, effects or browser APIs are needed.
  • Wrap slow data in Suspense so the page shell renders immediately and widgets stream in.
  • Use Server Actions for mutations, validate input on the server and revalidate affected paths.
  • Keep all data access in one layer so caching, auth and testing stay simple.

The App Router changed how I structure React apps. After shipping several production projects with it, a few patterns have proven themselves again and again.

Two developers working side by side at monitors full of code in a bright office
Most components can stay on the server; reach for the client only when needed.

Default to Server Components

Every component is a Server Component until it needs state, effects or browser APIs. Pushing 'use client' as far down the tree as possible keeps JavaScript bundles small and lets you fetch data right where it's used.

TSX
// app/dashboard/page.tsx  (Server Component)
import { getStats } from "@/lib/stats"
import { Chart } from "./chart" // 'use client' lives here only

export default async function Dashboard() {
const stats = await getStats()
return <Chart data={stats} />
}
A stack of four layers: client components on top, then Suspense boundaries, Server Components and a shared data layer.
Where each kind of code lives in an App Router application.

Stream slow parts with Suspense

Wrap slow data in Suspense boundaries so the shell renders instantly. Users see a useful page in milliseconds while the heavy widgets fill in.

A tablet showing web performance analytics charts and histograms
Measure real-user performance so you know which pages deserve streaming.

Server Actions for mutations

For forms and simple mutations, Server Actions remove an entire layer of API boilerplate. Validate on the server, return typed results, and revalidate the paths that changed.

  • Validate every input on the server, even if the client validates too.
  • Return a result object instead of throwing for expected errors.
  • Call revalidatePath or revalidateTag after a successful write.

Keep data access in one place

I put all queries in a small data layer (lib/ or server/) so components never talk to the database directly. It makes caching, auth checks and testing dramatically simpler. For the backend side of the same idea, see building scalable SaaS applications with Next.js and NestJS.

FAQs

Practical answers to the questions that come up most when teams adopt the App Router.

Use a Client Component only when the component needs state, effects, event handlers or browser-only APIs. Everything else should stay a Server Component to keep the JavaScript bundle small.

References

  1. Server and Client Components — Next.js documentation
  2. React Server Components — React documentation
  3. Server Actions and mutations — Next.js documentation
  • #Next.js
  • #React
  • #Performance
  • Architecture diagram of a SaaS application: Next.js frontend, NestJS API, PostgreSQL database, Redis queue and background workers

    SaaS & MVP

    Building Scalable SaaS Applications with Next.js and NestJS

    A practical architecture guide to building a multi-tenant SaaS with Next.js and NestJS: how the two fit together, how to handle auth, databases, tenancy and background jobs, and what to avoid.

    • Published
    • 11 min read
    Read article
  • A large data centre hall with server cabinets and blue network cables overhead

    Cloud & DevOps

    Scaling a Node.js API on GCP Without Over-Engineering

    From a single Cloud Run service to a resilient, observable backend — what to add at each stage of growth, and what to skip until you need it.

    • Published
    • Updated
    • 8 min read
    Read article
  • A product team placing colourful sticky notes on a glass wall while planning an MVP

    SaaS & MVP

    How I Ship a Production-Ready MVP in Six Weeks

    A practical playbook for founders: what to cut, what to keep, and how to sequence the work so you launch fast without building a house of cards.

    • Published
    • Updated
    • 7 min read
    Read article