AgentSkillsCN

nextjs-turborepo

全栈 Web 框架——Next.js 15(App Router、Server Components、RSC、PPR、SSR/SSG/ISR)、Turborepo(单体仓库、任务流水线、远程缓存)。适用于 React 应用开发、服务器端渲染、单体仓库管理、构建优化,以及全栈 TypeScript 项目。

SKILL.md
--- frontmatter
name: nextjs-turborepo
description: Full-stack web frameworks — Next.js 15 (App Router, Server Components, RSC, PPR, SSR/SSG/ISR), Turborepo (monorepo, task pipelines, remote caching). Use for building React applications, server-side rendering, monorepo management, build optimization, and full-stack TypeScript projects.
license: MIT

Web Frameworks Mastery

Build modern full-stack applications with Next.js App Router and Turborepo monorepo.

Framework Selection

NeedChoose
Single full-stack appNext.js standalone
Multiple apps sharing codeNext.js + Turborepo monorepo
Static marketing siteNext.js with SSG
SaaS with dashboardNext.js App Router + RSC
API-only backendUse Rust-backend-advance (Axum) instead

Quick Start

bash
# Single app
npx create-next-app@latest my-app
cd my-app && npm run dev

# Monorepo
npx create-turbo@latest my-monorepo
cd my-monorepo && npm run dev

Reference Navigation

Next.js

  • App Router Architecture — Routing, layouts, pages, loading/error states, parallel routes
  • Server Components — RSC patterns, client vs server, streaming, use client/server
  • Data Fetching — fetch, caching, revalidation, server actions, loading.tsx
  • Optimization — Images, fonts, scripts, bundle analysis, PPR, metadata/SEO

Turborepo

Key Patterns

App Router Structure

code
app/
├── layout.tsx          # Root layout (wraps all pages)
├── page.tsx            # Home page (/)
├── loading.tsx         # Loading UI
├── error.tsx           # Error boundary
├── not-found.tsx       # 404 page
├── dashboard/
│   ├── layout.tsx      # Dashboard layout
│   ├── page.tsx        # /dashboard
│   └── settings/
│       └── page.tsx    # /dashboard/settings
└── api/
    └── users/
        └── route.ts    # API route handler

Server Component (default)

tsx
// app/users/page.tsx — Server Component (no "use client")
export default async function UsersPage() {
  const users = await fetch('https://api.example.com/users', {
    next: { revalidate: 3600 }  // ISR: refresh every hour
  }).then(r => r.json())

  return (
    <main>
      <h1>Users</h1>
      {users.map(u => <UserCard key={u.id} user={u} />)}
    </main>
  )
}

Client Component

tsx
"use client"
import { useState } from 'react'

export function Counter() {
  const [count, setCount] = useState(0)
  return <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
}

Monorepo Structure

code
my-monorepo/
├── apps/
│   ├── web/          # Customer-facing Next.js
│   ├── admin/        # Admin dashboard Next.js
│   └── docs/         # Documentation
├── packages/
│   ├── ui/           # Shared components
│   ├── config/       # ESLint, TypeScript configs
│   └── types/        # Shared types
├── turbo.json
└── package.json

Best Practices

Next.js: Default to Server Components, use "use client" only when needed. Implement proper loading/error states. Use Image component for optimization. Set metadata for SEO.

Turborepo: Clear separation (apps/ + packages/). Define task dependencies correctly. Enable remote caching. Use --filter for targeted builds.

Related Skills

SkillWhen to Use
ui-stylingTailwind CSS, shadcn/ui components
frontend-designDesign tokens, typography, color systems
authenticationNext.js authentication setup
testingE2E testing with Playwright
devopsDeployment, Vercel, Docker