Overview
Provides a complete, production-ready Next.js 14+ (App Router) project scaffold including recommended directory structure, TypeScript strict config, Tailwind, ESLint + Prettier, testing setup (Jest or Vitest + React Testing Library), basic CI with GitHub Actions, environment variable conventions, middleware example, image optimization config, and a Vercel deployment checklist.
When to Use This Skill
- Starting a brand new Next.js project.
- The user says "create a new Next.js app", "scaffold Next.js", or "set up a Next.js project with best practices".
- You want to avoid the default
create-next-app minimal setup and jump straight to a hardened production template.
Prerequisites
- Node.js 18.17+ or 20+.
npx create-next-app@latest or manual setup.
- Git initialized.
- Vercel account (recommended for deployment) or other hosting.
Steps
Initialize the project:
npx create-next-app@latest . --yes --tailwind --eslint --yes --app
Upgrade to latest stable and install additional deps:
typescript, @types/node, react, react-dom (already there).
- Add:
zod, clsx, tailwind-merge, @hookform/resolvers, react-hook-form (common), lucide-react or heroicons.
- Dev:
prettier, eslint-config-prettier, husky, lint-staged, @testing-library/react, jest or vitest.
Directory structure (create these folders):
app/
(marketing)/ # route groups
(dashboard)/
api/
components/
lib/ # utils, constants, db clients
hooks/
types/
middleware.ts
next.config.mjs # hardened
Configure next.config.mjs with security and performance:
- Headers for security.
- Image remote patterns.
- Experimental features if needed.
- Output: 'standalone' for Docker if relevant.
Set up environment variables:
.env.example
NEXT_PUBLIC_ for client-exposed.
- Server-only vars loaded via
process.env with Zod validation in lib/env.ts.
Add middleware for auth redirects, i18n, etc.
Linting & formatting:
.eslintrc.json extending recommended + prettier.
.prettierrc
lint-staged + husky pre-commit hook.
Testing setup:
- Jest/Vitest config.
- Example test for a component.
testing-library setup.
GitHub Actions CI (.github/workflows/ci.yml):
- Install, lint, typecheck, test, build.
Vercel / deploy checklist:
- Environment variables in dashboard.
- Preview deployments.
- Custom domain + HTTPS.
- Analytics + Speed Insights.
Examples
Full next.config.mjs, lib/env.ts Zod schema, sample app/layout.tsx with metadata, middleware example, and CI workflow are provided in the skill output.
Edge Cases & Error Handling
- Monorepo: Note adjustments for Turborepo or Nx.
- Internationalization: Recommend
next-intl or built-in.
- Authentication: Suggest adding
next-auth or Lucia in a follow-up step.
- Database: Prisma or Drizzle setup guidance.
Verification
npm run dev — app runs cleanly.
npm run build — successful production build.
npm run lint and typecheck pass.
- Run tests.
- Deploy to Vercel preview and verify.
- Success: Project starts with all modern best practices, zero config debt on day one.
References
1---2name: nextjs-app-scaffold3description: Scaffolds a production Next.js 14+ App Router project with TypeScript, Tailwind, ESLint, Prettier, testing, and CI. Use when starting a new Next.js project from scratch.4license: Apache-2.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: web-development10 tags: nextjs, app-router, typescript, tailwind, eslint, vercel, scaffold11---1213## Overview1415Provides a complete, production-ready Next.js 14+ (App Router) project scaffold including recommended directory structure, TypeScript strict config, Tailwind, ESLint + Prettier, testing setup (Jest or Vitest + React Testing Library), basic CI with GitHub Actions, environment variable conventions, middleware example, image optimization config, and a Vercel deployment checklist.1617## When to Use This Skill1819- Starting a brand new Next.js project.20- The user says "create a new Next.js app", "scaffold Next.js", or "set up a Next.js project with best practices".21- You want to avoid the default `create-next-app` minimal setup and jump straight to a hardened production template.2223## Prerequisites2425- Node.js 18.17+ or 20+.26- `npx create-next-app@latest` or manual setup.27- Git initialized.28- Vercel account (recommended for deployment) or other hosting.2930## Steps31321. **Initialize the project**:33 ```bash34 npx create-next-app@latest . --yes --tailwind --eslint --yes --app35 ```36372. **Upgrade to latest stable** and install additional deps:38 - `typescript`, `@types/node`, `react`, `react-dom` (already there).39 - Add: `zod`, `clsx`, `tailwind-merge`, `@hookform/resolvers`, `react-hook-form` (common), `lucide-react` or heroicons.40 - Dev: `prettier`, `eslint-config-prettier`, `husky`, `lint-staged`, `@testing-library/react`, `jest` or `vitest`.41423. **Directory structure** (create these folders):43 ```44 app/45 (marketing)/ # route groups46 (dashboard)/47 api/48 components/49 lib/ # utils, constants, db clients50 hooks/51 types/52 middleware.ts53 next.config.mjs # hardened54 ```55564. **Configure next.config.mjs** with security and performance:57 - Headers for security.58 - Image remote patterns.59 - Experimental features if needed.60 - Output: 'standalone' for Docker if relevant.61625. **Set up environment variables**:63 - `.env.example`64 - `NEXT_PUBLIC_` for client-exposed.65 - Server-only vars loaded via `process.env` with Zod validation in `lib/env.ts`.66676. **Add middleware** for auth redirects, i18n, etc.68697. **Linting & formatting**:70 - `.eslintrc.json` extending recommended + prettier.71 - `.prettierrc`72 - `lint-staged` + husky pre-commit hook.73748. **Testing setup**:75 - Jest/Vitest config.76 - Example test for a component.77 - `testing-library` setup.78799. **GitHub Actions CI** (`.github/workflows/ci.yml`):80 - Install, lint, typecheck, test, build.818210. **Vercel / deploy checklist**:83 - Environment variables in dashboard.84 - Preview deployments.85 - Custom domain + HTTPS.86 - Analytics + Speed Insights.8788## Examples8990Full `next.config.mjs`, `lib/env.ts` Zod schema, sample `app/layout.tsx` with metadata, middleware example, and CI workflow are provided in the skill output.9192## Edge Cases & Error Handling9394- **Monorepo**: Note adjustments for Turborepo or Nx.95- **Internationalization**: Recommend `next-intl` or built-in.96- **Authentication**: Suggest adding `next-auth` or Lucia in a follow-up step.97- **Database**: Prisma or Drizzle setup guidance.9899## Verification1001011. `npm run dev` — app runs cleanly.1022. `npm run build` — successful production build.1033. `npm run lint` and typecheck pass.1044. Run tests.1055. Deploy to Vercel preview and verify.1066. Success: Project starts with all modern best practices, zero config debt on day one.107108## References109110- [Next.js 14 App Router Docs](https://nextjs.org/docs/app)111- [Vercel Deployment](https://vercel.com/docs)112- [Next.js Security Best Practices](https://nextjs.org/docs/app/building-your-application/security)