Frontend7 min read

Next.js Architect

Architects Next.js 15 applications - App Router structure, React Server Components, caching strategy, data fetching, and deployment patterns.

Next.jsApp RouterRSCSSRSSGReact Server Components

The Next.js Architect designs App Router applications for performance, maintainability, and correct data fetching. The most common architectural mistake is using Client Components for work that should be Server Components - sending to the browser code that could have stayed on the server and data that could have been rendered as HTML.

Server vs Client Component Decision

NeedComponent typeReason
Fetch data from DB / APIServerNo API route needed; credentials stay on server
Access environment secretsServerNever send secrets to the browser
Render static contentServerZero JS bundle impact; streamed HTML
useState / useEffectClientBrowser-only React APIs
Event listeners (onClick)ClientServer components cannot be interactive
Browser APIs (localStorage, window)ClientNot available server-side

Data Fetching Patterns

// app/products/page.tsx - Server Component (default)
// No 'use client' directive = Server Component

async function ProductsPage() {
  // Fetch runs on the server - DB credentials never exposed
  const products = await db.products.findMany({ where: { active: true } });

  return (
    <main>
      {products.map(p => <ProductCard key={p.id} product={p} />)}
    </main>
  );
}

// Parallel data fetching - avoid sequential await
async function Dashboard() {
  // ❌ Sequential - total time = A + B + C
  // const user = await getUser();
  // const posts = await getPosts();
  // const stats = await getStats();

  // ✅ Parallel - total time = max(A, B, C)
  const [user, posts, stats] = await Promise.all([
    getUser(),
    getPosts(),
    getStats(),
  ]);
  return <DashboardView user={user} posts={posts} stats={stats} />;
}

Caching Strategy

// Next.js 15 caching: opt-in (fetch is no longer cached by default)

// Static - cache forever, revalidate on deploy
const data = await fetch('https://api.example.com/config', {
  cache: 'force-cache',
});

// ISR - cache for N seconds, then regenerate in background
const data = await fetch('https://api.example.com/products', {
  next: { revalidate: 3600 }, // 1 hour
});

// Dynamic - no cache, always fresh
const data = await fetch('https://api.example.com/user/me', {
  cache: 'no-store',
});

// Route segment config - applies to all fetches in the route
export const revalidate = 3600;
export const dynamic = 'force-dynamic'; // Opts out of all caching

Folder Structure

app/
  (marketing)/          # Route group - shared layout, no URL segment
    page.tsx
    layout.tsx
  (dashboard)/
    layout.tsx          # Dashboard shell with sidebar
    projects/
      page.tsx
      [id]/
        page.tsx        # /projects/123
  api/
    webhooks/
      stripe/
        route.ts        # POST /api/webhooks/stripe
components/
  ui/                   # Shared, stateless UI (Server or Client)
  features/             # Feature-specific components
lib/
  db.ts                 # Prisma/Drizzle client singleton
  auth.ts               # Auth helper functions

Explore all agents

Browse the full library of specialized AI agents.