name: nextjs-project-manager
description: Expert guide for Next.js 14+ App Router projects. Use when building features, routing, server/client components, forms, layouts, or debugging Next.js-specific issues.
slug: nextjs-project-manager
category: operations
complexity: complex
version: "1.0.0"
author: "id8Labs"
triggers:
- "nextjs-project-manager"
- "nextjs project manager"
tags:
- development
- tool-factory-retrofitted---
Next.js Project Manager Skill
Core Workflows
Workflow 1: Primary Action
- Analyze the input and context
- Validate prerequisites are met
- Execute the core operation
- Verify the output meets expectations
- Report results
Overview
This skill helps you build production-ready Next.js 14+ applications using the App Router. Use this when working on routing, components, server actions, data fetching, or any Next.js-specific patterns.
Core Principles
1. App Router First
- All routes in
src/app/ directory
- Use
page.tsx for routes, layout.tsx for shared layouts
- Server Components by default, Client Components when needed
- Route groups with
(group) for organization
2. Server vs Client Components
Server Components (Default):
- No "use client" directive needed
- Can use async/await directly
- Access database/backend directly
- Better performance (less JS sent to client)
- Cannot use hooks or browser APIs
Client Components ("use client"):
- Use when you need:
- State (useState, useReducer)
- Effects (useEffect)
- Event handlers (onClick, onChange)
- Browser APIs (localStorage, window)
- Third-party libraries that use hooks
3. Data Fetching Patterns
Server Components:
export default async function Page() {
const data = await fetch('https://api.example.com/data')
const json = await data.json()
return <div>{json.title}</div>
}
Client Components:
'use client'
import { useEffect, useState } from 'react'
export default function Page() {
const [data, setData] = useState(null)
useEffect(() => {
fetch('/api/data')
.then(res => res.json())
.then(setData)
}, [])
return <div>{data?.title}</div>
}
4. Server Actions
Use Server Actions for form submissions and mutations:
'use server'
export async function createItem(formData: FormData) {
const title = formData.get('title')
await db.insert({ title })
revalidatePath('/items')
redirect('/items')
}
'use client'
import { createItem } from './actions'
export function Form() {
return (
<form action={createItem}>
<input name="title" />
<button type="submit">Create</button>
</form>
)
}
Common Patterns
Route Structure
src/app/
├── (auth)/
│ ├── login/
│ │ └── page.tsx
│ └── signup/
│ └── page.tsx
├── (dashboard)/
│ ├── layout.tsx # Shared dashboard layout
│ ├── page.tsx # Dashboard home
│ └── settings/
│ └── page.tsx
├── api/
│ └── endpoint/
│ └── route.ts # API routes
├── layout.tsx # Root layout
└── page.tsx # Home page
Layouts
import { Sidebar } from '@/components/sidebar'
export default function DashboardLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<div className="flex">
<Sidebar />
<main className="flex-1">{children}</main>
</div>
)
}
Loading States
export default function Loading() {
return <div>Loading...</div>
}
Error Handling
'use client'
export default function Error({
error,
reset,
}: {
error: Error
reset: () => void
}) {
return (
<div>
<h2>Something went wrong!</h2>
<button onClick={reset}>Try again</button>
</div>
)
}
Metadata
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: 'Page Title',
description: 'Page description',
}
export default function Page() {
return <div>Content</div>
}
API Routes
import { NextRequest, NextResponse } from 'next/server'
export async function GET(request: NextRequest) {
const items = await db.getItems()
return NextResponse.json({ items })
}
export async function POST(request: NextRequest) {
const body = await request.json()
const item = await db.createItem(body)
return NextResponse.json({ item }, { status: 201 })
}
Dynamic Routes
export default function Post({ params }: { params: { id: string } }) {
return <div>Post {params.id}</div>
}
export async function generateStaticParams() {
const posts = await getPosts()
return posts.map((post) => ({ id: post.id }))
}
Middleware
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
return NextResponse.next()
}
export const config = {
matcher: '/dashboard/:path*',
}
Environment Variables
const apiKey = process.env.API_KEY
const publicKey = process.env.NEXT_PUBLIC_API_KEY
Best Practices Checklist
Debugging Tips
- Hydration Errors: Check for server/client mismatches
- "use client" Errors: Missing directive on component using hooks
- Cannot Access Browser APIs: Move to client component
- Data Not Updating: Use revalidatePath() or revalidateTag()
- Build Errors: Check for async components without proper typing
Performance Optimization
- Use React Suspense for loading states
- Implement streaming with loading.tsx
- Use dynamic imports for code splitting
- Optimize images with next/image
- Use Font optimization with next/font
- Implement ISR (Incremental Static Regeneration)
- Use caching with fetch options
When to Use This Skill
Invoke this skill when:
- Creating new routes or pages
- Setting up layouts
- Implementing forms with Server Actions
- Debugging Next.js-specific errors
- Optimizing performance
- Setting up middleware
- Creating API routes
- Working with metadata