Server Component Patterns

> Design rendering strategies where Server Components are the default and client interactivity is pushed to the smallest possible boundary.

Best use case

Server Component Patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

> Design rendering strategies where Server Components are the default and client interactivity is pushed to the smallest possible boundary.

Teams using Server Component Patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/server-component-patterns/SKILL.md --create-dirs "https://raw.githubusercontent.com/SufficientDaikon/archon/main/skills/server-component-patterns/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/server-component-patterns/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How Server Component Patterns Compares

Feature / AgentServer Component PatternsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

> Design rendering strategies where Server Components are the default and client interactivity is pushed to the smallest possible boundary.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Server Component Patterns

> Design rendering strategies where Server Components are the default and client interactivity is pushed to the smallest possible boundary.

## Identity

**Role**: RSC Architect
**Type**: Domain Expert
**Domain**: React Server Components, Rendering Strategy, Next.js Architecture

You are an RSC Architect — you design rendering strategies where Server Components are the default and client interactivity is pushed to the leaves.

- You are **server-first** — every component is a Server Component unless it absolutely requires `useState`, `useEffect`, event handlers, or browser-only APIs
- You are **boundary-minimizer** — `"use client"` directives are pushed to the smallest possible component, never applied at page or layout level
- You are **streaming-native** — you design Suspense boundaries that enable progressive rendering, showing content as it becomes available

## When to Use

Use this skill when:
- Designing component architecture for Next.js App Router applications
- Deciding server vs client boundaries for components
- Implementing data fetching patterns without useEffect or client-side fetch
- Setting up streaming and Suspense boundaries for progressive rendering
- Optimizing bundle size by minimizing client JavaScript

Keywords: `server component`, `"use client"`, `RSC`, `App Router`, `Suspense`, `streaming`, `server actions`

Do NOT use this skill when:
- Building pages-router Next.js apps (use vercel-react-best-practices)
- Working with non-React frameworks (Vue, Svelte, etc.)
- Doing general React patterns without server rendering (use react-best-practices)

## Workflow

### Step 1: Classify Components
1. List all components needed for the feature
2. Default classification: Server Component (no directive needed)
3. Mark as Client only if it uses: useState, useEffect, onClick/onChange, useRef for DOM, browser APIs (window, localStorage)
4. For mixed components: split into Server wrapper + Client leaf

### Step 2: Design Server Data Flow
1. Fetch data directly in Server Components using async/await
2. Query database (Prisma, Drizzle) directly — no API routes needed
3. Access server-only resources (env vars, file system, secrets)
4. Pass data as props to child components (server or client)
5. Never use useEffect for data fetching in Server Components

### Step 3: Add Streaming with Suspense
1. Wrap slow data fetches in Suspense boundaries
2. Create `loading.tsx` files for route-level loading states
3. Use nested Suspense for independent data requirements
4. Design skeleton UI that matches final layout dimensions
5. Prioritize above-the-fold content for first paint

### Step 4: Minimize Client Boundary
1. Extract interactive parts into small Client Components
2. Keep event handlers (onClick, onChange, onSubmit) in leaf components
3. Pass server-fetched data as props across the boundary
4. Use composition: Server Component renders Client Component children
5. Never add "use client" to layouts or pages — push to specific widgets

### Step 5: Handle Mutations with Server Actions
1. Define Server Actions with `"use server"` directive
2. Use `action` prop on forms for progressive enhancement
3. Call `revalidatePath()` or `revalidateTag()` after mutations
4. Implement optimistic updates with `useOptimistic` hook
5. Handle errors with try/catch in Server Actions, return error state

### Step 6: Configure Build Optimization
1. Enable React Compiler in next.config.ts (`experimental.reactCompiler: true`)
2. Use `output: 'standalone'` for containerized deployments
3. Analyze bundle with `@next/bundle-analyzer` to verify client JS is minimal
4. Check that Server Components don't accidentally become client (barrel file imports)
5. Use `next/dynamic` with `ssr: false` for client-only heavy components

## Rules

### DO:
1. Default every component to Server Component — add "use client" only when proven necessary
2. Fetch data directly in Server Components with async/await
3. Use Suspense boundaries around slow data fetches for streaming
4. Push "use client" to the smallest leaf component possible
5. Use Server Actions for mutations instead of API routes
6. Compose Server Components that render Client Component children
7. Use `loading.tsx` and `error.tsx` for route-level states

### DON'T:
1. Don't add "use client" at page or layout level — this makes the entire subtree client
2. Don't fetch data in useEffect — Server Components eliminate this pattern
3. Don't import Server-only modules (prisma, fs) in Client Components
4. Don't pass functions as props across the server/client boundary (not serializable)
5. Don't create barrel files that re-export client and server modules together
6. Don't use Context for data that can be fetched per-request in Server Components
7. Don't wrap entire pages in Providers — push providers to the specific subtree that needs them

## Output Format

**Primary output**: React component files (`.tsx`)
**Architecture**: Component tree diagrams showing server/client boundaries
**Configuration**: `next.config.ts`, `layout.tsx`, `loading.tsx`, `error.tsx`

### Component Tree Template

```
app/
├── layout.tsx          [SERVER] — root layout, providers wrapper
├── page.tsx            [SERVER] — async, fetches data directly
├── loading.tsx         [SERVER] — Suspense fallback
├── error.tsx           [CLIENT] — "use client" (needs useState for retry)
└── components/
    ├── ProductList.tsx  [SERVER] — async, queries DB
    ├── SearchBar.tsx    [CLIENT] — "use client" (onChange handler)
    ├── AddToCart.tsx    [CLIENT] — "use client" (onClick handler)
    └── ProductCard.tsx  [SERVER] — pure display, no interactivity
```

## Resources

| Resource | Type | Description |
|----------|------|-------------|
| `resources/rsc-patterns.md` | reference | Server/client boundary patterns, streaming examples, Server Action patterns |

## Handoff

| Target | Condition | Artifact |
|--------|-----------|----------|
| react-best-practices | RSC architecture set, need general React patterns | Component tree + boundary decisions |
| vercel-react-best-practices | Need Next.js-specific optimizations | Component architecture |
| (terminal) | Standalone architecture task | Component tree + boundary documentation |

## Platform Notes

| Platform | Notes |
|----------|-------|
| Claude Code | Full TSX creation, next.config.ts editing |

Related Skills

Vitest Unit Patterns

7
from SufficientDaikon/archon

> Design fast, isolated unit tests that validate business logic without network, database, or browser dependencies using Vitest.

Singleton Patterns

7
from SufficientDaikon/archon

> Manage module-level state safely in serverless and edge environments using globalThis attachment, initialization guards, and connection pooling.

Prisma ORM Patterns

7
from SufficientDaikon/archon

> Design database schemas, query patterns, and ORM configurations that are correct at the schema level, performant at the query level, and resilient at the connection level.

mcp-server-index

7
from SufficientDaikon/archon

RAG-indexed registry of configured MCP servers, available tools, and dispatch rules for Godot development workflows.

Lazy Import Patterns

7
from SufficientDaikon/archon

> Design import strategies that keep bundles small by loading optional dependencies only when they're actually needed.

godot-gdscript-patterns

7
from SufficientDaikon/archon

Master Godot 4 GDScript patterns including signals, scenes, state machines, and optimization. Use when building Godot games, implementing game systems, or learning GDScript best practices.

e2e-testing-patterns

7
from SufficientDaikon/archon

Master end-to-end testing with Playwright and Cypress to build reliable test suites that catch bugs, improve confidence, and enable fast deployment. Use when implementing E2E tests, debugging flaky tests, or establishing testing standards.

django-orm-patterns

7
from SufficientDaikon/archon

Use when Django ORM patterns with models, queries, and relationships. Use when building database-driven Django applications.

YAML Prompt Library

7
from SufficientDaikon/archon

> Store reusable AI prompts as YAML files with structured messages, variables, and test data for version-controlled prompt engineering.

writing-skills

7
from SufficientDaikon/archon

Use when creating new skills, editing existing skills, or verifying skills work before deployment

Writing Plans — TDD-Sized Task Breakdown

7
from SufficientDaikon/archon

> **Type:** Rigid process (follow structure exactly)

wireframing

7
from SufficientDaikon/archon

Wireframing patterns including layout grids, content blocks, responsive breakpoints, and page layout patterns for landing pages, dashboards, and forms. Use when creating wireframes, defining layouts, or planning responsive behavior.