Next.js Development Setup (nextjs-dev-setup)
A structured, end-to-end orchestration runbook for discovering, configuring, and verifying the Next.js App Router development environment, reverse proxy routing (Traefik / Nginx), and single source of truth at docs/project.json.
Pre-Conditions & Discovery
- Zero-Interruption Scan: Scan existing repository files (
package.json, lockfiles, stylesheets,docs/adr/*.md,docs/plan.md,CONTEXT.md) before asking questions. - Consult project-json-schema.md for metadata structure and automated deduction rules.
Phase 0: Multi-Round Setup Interview (Grilling) & Plan Generation
Conduct the interactive interview in progressive, adaptive rounds (waiting for user response after each round) to tailor the setup:
- Round 1 (Scope & Tooling): Probe target testing suites (Jest, Playwright, Storybook), MCP servers, and
@shadcn/lintenforcement. - Round 2 (Reverse Proxy & Production Hosting): Probe domain name, port, and reverse proxy strategy:
- Traefik via Docker Compose: Automated container discovery using Compose labels reading from environment variables (
${DOMAIN_NAME},${TRAEFIK_ENTRYPOINT},${TRAEFIK_CERTRESOLVER}) with anti-buffering. - Nginx via Host System: Standalone configuration in
/etc/nginx/sites-available/<domain>using Certbot SSL certificates.
- Traefik via Docker Compose: Automated container discovery using Compose labels reading from environment variables (
- Round 3 (CI/CD, Git Hooks & Registry): Probe Husky pre-push test suites, Commitlint, and GitHub Actions Release Please / GHCR workflows.
- Consult setup-interview-rounds.md for complete question sets and branching logic.
- Plan & Execution: Generate and present an
implementation_plan.mdartifact detailing all planned file creations, configurations, and packages before applying changes, and proceed directly with execution without waiting for manual confirmation.
Step-by-Step Execution Flow
Stage 1: Project Metadata & Developer Tooling (docs/project.json)
- Initialize
docs/project.jsonusing project.template.json based on user interview choices. - Configure
.vscode/launch.jsonusing vscode-launch.json.template. - Scaffold
app/providers.tsxwith<ProgressBarProvider>using providers.tsx.template and composite<Link>using Link.tsx.template. - Scaffold
.env.exampleusing env.example.template for production and.env.localusing env.local.template for local development. - App Icons, Apple Icon & PWA Manifest: Deploy manifest.ts.template to
app/manifest.ts. Configure the user-provided favicon across rootapp/favicon.ico,app/icon.png, andapp/apple-icon.png(or dynamicImageResponseicon). Consult app-icons-and-pwa-guide.md.
Stage 2: Testing Suites (Jest, Playwright & Instant Navigation)
[!IMPORTANT] No Dummy Test Files (Rule 3): Do not create placeholder/sample test files in the workspace. Configure framework files and scripts only. Sample patterns are available in sample-component.test.tsx, sample-navigation.spec.ts, and sample-component.stories.tsx.
- Jest Unit Testing: Configure jest.config.ts.template and jest.setup.ts.template.
- Playwright E2E & Instant Navigation: Install
@playwright/testand@next/playwright(pnpm add -D @playwright/test @next/playwright), configure playwright.config.ts.template, and install browsers. - Next.js Instant Config: Configure
cacheComponents: true,partialPrefetching: true, and instant insights innext.config.ts. - Storybook Workshop: Configure .storybook/main.ts and .storybook/preview.tsx.
- Review architectures in testing-guide.md and storybook-guide.md.
Stage 3: Dual MCP Server Configuration
[!IMPORTANT] Antigravity Global MCP Loading Rule: AG only loads MCP servers configured globally on the host system (
~/.gemini/antigravity/mcp_config.jsonand~/.gemini/config/mcp_config.json). Workspacemcp.jsonis maintained for portability. Both must be configured.
- Configure
next-devtools,playwright,storybook, andcodebase-memory-mcp. - Stutter Prevention: Set
auto_watch = falseviacodebase-memory-mcp config set auto_watch falseand deploy root .cbmignore. - Review full specs in mcp-configuration-guide.md.
Stage 4: Agent-First Design System Linting (@shadcn/lint)
- Install
@shadcn/lintand configure ESLint flat config using eslint.config.mjs.template. - Review mechanics in styling-and-linting-guide.md.
Stage 5: Standalone Production Docker & Reverse Proxy (Traefik / Nginx)
- In
next.config.ts: resolve Git commit hash (getGitCommitHash()with CI fallbacks) and package version, injectNEXT_PUBLIC_APP_VERSIONandNEXT_PUBLIC_GIT_COMMIT_HASHunderenv, enableoutput: "standalone", setdeploymentIdfor version skew protection (${pkg.version}-${gitHash}), configureheaderswithX-Accel-Buffering: no, and setexperimental.serverActions.allowedOrigins. - Document
NEXT_SERVER_ACTIONS_ENCRYPTION_KEYin.env.exampleand pass it to runtime environments. - Deploy Dockerfile.template (with
STOPSIGNAL SIGTERM) and docker-compose.yml.template (withstop_grace_period: 30s). - Reverse Proxy Configuration:
- Traefik: Deploy docker-compose.prod.yml.template with dynamic environment variable labels (
${DOMAIN_NAME},${TRAEFIK_ENTRYPOINT},${TRAEFIK_CERTRESOLVER}) and anti-buffering middleware. - Nginx: Deploy or output nginx-site.conf.template for
/etc/nginx/sites-available/<domain>with Certbot SSL certificates.
- Traefik: Deploy docker-compose.prod.yml.template with dynamic environment variable labels (
- Review architecture and multi-container cache drift callout in docker-containerization-guide.md.
Stage 6: Git Hooks & Credit-Optimized CI/CD
- Install
husky,@commitlint/cli,@commitlint/config-conventional. - Configure commitlint.config.mjs.template,
.husky/commit-msg, and.husky/pre-push(pnpm run test:all). - Deploy .github/workflows/release-please.yml with
.next/cachebuild caching and multi-arch matrix publishing. - Review caching in cicd-and-release-automation-guide.md.
Stage 7: Final Execution Report & Verification
- Execute the configuration verification script and ensure all checks pass.
- Stage all created/modified files in git (
git add .) per Rule 36. - Mandatory Final Output: Render the complete, structured Next.js Dev Setup Execution Report markdown table summarizing all implemented files, verification check results, and next development steps.
Verification & Sanity Check
- Execute configuration verification script:
- Windows (PowerShell):
powershell -ExecutionPolicy Bypass -File .agents/skills/nextjs-dev-setup/scripts/verify-project-config.ps1 - Linux / macOS (Bash):
bash .agents/skills/nextjs-dev-setup/scripts/verify-project-config.sh
- Windows (PowerShell):
- Fix any reported errors and re-verify until all checks pass.
Edge Cases & Known AI Pitfalls
- Chained Commands: Never chain commands with
&∨on a single line in terminal execution. - MCP Disabling: In AG global configs,
agy.exeignores"disabled": trueinsidemcpServers. Move disabled servers outsidemcpServers. - Docker Image Names: Docker OCI naming strictly requires lowercase repository names (
IMAGE_NAME=$(echo ... | tr '[:upper:]' '[:lower:]')). - Storybook Intl Context: Always wrap Storybook stories rendering
LinkoruseTranslationswithNextIntlClientProvider.
Mandatory Final Output: Execution Report Template
Always output this report upon completing the skill workflow:
## 🛠️ Next.js Dev Setup Execution Report
| Step / Component | Target File(s) / Resource | Status | Notes / Details |
| :----------------------------------- | :----------------------------------------------------------------------------------------------------- | :------------------------------ | :------------------------------------------------------------------------------- |
| **1. Project Metadata** | `docs/project.json` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured package manager, directories, animation & i18n metadata. |
| **2. App Icons & PWA Manifest** | `app/manifest.ts`, `app/favicon.ico`, `app/apple-icon.png`, `app/icon.png` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured root favicon, Apple touch icon, and Web App Manifest using user favicon. |
| **3. Core Dependencies** | `package.json`, Lockfile | `[IMPLEMENTED]` / `[UNTOUCHED]` | Verified React, Next.js, styling, and motion libraries. |
| **4. Next.js Dev Server MCP** | `~/.gemini/antigravity/mcp_config.json`, `mcp.json`, `.agents/plugins/workspace-tools/mcp_config.json` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured Next.js Dev Server (`next-devtools`) globally for AG & in workspace. |
| **5. Playwright & Instant Testing** | `playwright.config.ts`, `@next/playwright`, `mcp.json`, `~/.gemini/antigravity/mcp_config.json` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Verified runner, browsers, Playwright MCP & `@next/playwright` instant navigation helper. |
| **6. Codebase Memory & Stutter Fix** | `.cbmignore`, `mcp.json`, `~/.gemini/antigravity/mcp_config.json`, `auto_watch=false` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Registered MCP, configured .cbmignore exclusions, and disabled session watcher. |
| **7. Jest Unit Testing** | `jest.config.ts`, `jest.setup.ts` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured Next.js Jest transformer, jsdom environment & test-dom. |
| **8. Storybook & Storybook MCP** | `.storybook/main.ts`, `.storybook/preview.tsx`, `mcp.json`, `~/.gemini/antigravity/mcp_config.json` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured Storybook Vite, a11y, themes & Storybook AI MCP globally & workspace. |
| **9. Agent-First Tailwind Linter** | `eslint.config.mjs`, `package.json` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured `@shadcn/lint` for agent verification of design tokens and contracts. |
| **10. Docker & Reverse Proxy** | `Dockerfile`, `docker-compose.prod.yml`, `nginx-site.conf`, `.dockerignore` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Standalone container, Traefik labels / Nginx HTTPS with Certbot SSL. |
| **11. Husky Git Hooks** | `.husky/commit-msg`, `.husky/pre-push` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Enforces dual pre-push test suite (Jest + Playwright) & commitlint. |
| **12. Commitlint Config** | `commitlint.config.mjs` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Configured `@commitlint/config-conventional`. |
| **13. Release & CI Build Caching** | `.github/workflows/release-please.yml` | `[IMPLEMENTED]` / `[UNTOUCHED]` | Next.js build cache (.next/cache), SemVer release PRs & GHCR multi-arch pkg. |
| **14. Environment Verification** | `scripts/verify-project-config.ps1` / `.sh` | `[PASSED]` | Sanity check passed with zero errors. |
#### Status Definitions:
- **`[IMPLEMENTED]`**: Freshly created, installed, or modified during this setup run.
- **`[UNTOUCHED]`**: Already properly configured prior to running the skill; preserved as-is.
- **`[SKIPPED]`**: Intentionally omitted based on user preference.