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.05---67## Overview89Provides 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.1011## When to Use This Skill1213- Starting a brand new Next.js project.14- The user says "create a new Next.js app", "scaffold Next.js", or "set up a Next.js project with best practices".15- You want to avoid the default `create-next-app` minimal setup and jump straight to a hardened production template.1617## Prerequisites1819- Node.js 18.17+ or 20+.20- `npx create-next-app@latest` or manual setup.21- Git initialized.22- Vercel account (recommended for deployment) or other hosting.2324## Steps25261. **Initialize the project**:27 ```bash28 npx create-next-app@latest . --yes --tailwind --eslint --yes --app29 ```30312. **Upgrade to latest stable** and install additional deps:32 - `typescript`, `@types/node`, `react`, `react-dom` (already there).33 - Add: `zod`, `clsx`, `tailwind-merge`, `@hookform/resolvers`, `react-hook-form` (common), `lucide-react` or heroicons.34 - Dev: `prettier`, `eslint-config-prettier`, `husky`, `lint-staged`, `@testing-library/react`, `jest` or `vitest`.35363. **Directory structure** (create these folders):37 ```38 app/39 (marketing)/ # route groups40 (dashboard)/41 api/42 components/43 lib/ # utils, constants, db clients44 hooks/45 types/46 middleware.ts47 next.config.mjs # hardened48 ```49504. **Configure next.config.mjs** with security and performance:51 - Headers for security.52 - Image remote patterns.53 - Experimental features if needed.54 - Output: 'standalone' for Docker if relevant.55565. **Set up environment variables**:57 - `.env.example`58 - `NEXT_PUBLIC_` for client-exposed.59 - Server-only vars loaded via `process.env` with Zod validation in `lib/env.ts`.60616. **Add middleware** for auth redirects, i18n, etc.62637. **Linting & formatting**:64 - `.eslintrc.json` extending recommended + prettier.65 - `.prettierrc`66 - `lint-staged` + husky pre-commit hook.67688. **Testing setup**:69 - Jest/Vitest config.70 - Example test for a component.71 - `testing-library` setup.72739. **GitHub Actions CI** (`.github/workflows/ci.yml`):74 - Install, lint, typecheck, test, build.757610. **Vercel / deploy checklist**:77 - Environment variables in dashboard.78 - Preview deployments.79 - Custom domain + HTTPS.80 - Analytics + Speed Insights.8182## Examples8384Full `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.8586## Edge Cases & Error Handling8788- **Monorepo**: Note adjustments for Turborepo or Nx.89- **Internationalization**: Recommend `next-intl` or built-in.90- **Authentication**: Suggest adding `next-auth` or Lucia in a follow-up step.91- **Database**: Prisma or Drizzle setup guidance.9293## Verification94951. `npm run dev` — app runs cleanly.962. `npm run build` — successful production build.973. `npm run lint` and typecheck pass.984. Run tests.995. Deploy to Vercel preview and verify.1006. Success: Project starts with all modern best practices, zero config debt on day one.101102## References103104- [Next.js 14 App Router Docs](https://nextjs.org/docs/app)105- [Vercel Deployment](https://vercel.com/docs)106- [Next.js Security Best Practices](https://nextjs.org/docs/app/building-your-application/security)