ai-first-nextjs-boilerplate

skill
Security Audit
Pass
Health Pass
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Community trust — 121 GitHub stars
Code Pass
  • Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Pass
  • Permissions — No dangerous permissions requested

No AI report is available for this listing yet.

SUMMARY

The most opinionated, production-ready Next.js 16 boilerplate with first-class AI tooling. Claude Code, Cursor, Gemini CLI, Kiro, Windsurf — all produce consistent, reviewable code from day one.

README.md
AI-First Next.js Boilerplate

AI-First Next.js Boilerplate

Stop prompting. Start shipping.

The only Next.js boilerplate where Claude Code, Cursor, Gemini CLI, Kiro, Copilot, and Windsurf all produce identical, production-grade code — without custom prompting.

GitHub stars
GitHub forks
Next.js
TypeScript
License: MIT

Get Started · Why This Exists · Features · Star History


The Problem

You open Cursor, type "create a user profile page," and get:

  • A file in the wrong folder
  • useState for form fields instead of react-hook-form
  • Raw fetch() instead of your HTTP client
  • console.log everywhere
  • No Zod validation, no error boundaries, no types

You spend more time fixing AI output than writing code yourself.

This boilerplate solves that. Every AI tool reads the same rules, follows the same architecture, and produces code that passes your linting, type-checking, and code review — on the first try.


Why Developers Are Switching

create-next-app t3-app AI-First Boilerplate
AI understands your architecture - - 6 AI configs, synced
Vertical slice architecture - Partial Strict, ESLint-enforced
Pre-commit AI code review - - Code Review Graph MCP
Type-safe server actions - - next-safe-action v8
Headless, accessible UI - - Ark UI v5 (WAI-ARIA)
Canonical AI examples - - src/__examples__/
Docker (dev/staging/prod) - - Three-tier setup
Security headers (CSP/HSTS) - - OWASP-ready

What You Get

AI-First Development — The Core Differentiator

One rule file. Six AI tools. Zero drift.

Every AI coding assistant in your team reads the same architecture rules from a single source (.ai/rules.md), auto-synced to each tool's config format:

AI Tool Config Status
Claude Code CLAUDE.md + .claude/steering/ Fully configured
Cursor .cursorrules Fully configured
Windsurf .windsurfrules Fully configured
GitHub Copilot .github/copilot-instructions.md Fully configured
Gemini CLI .gemini/GEMINI.md + hooks Fully configured
Kiro .kiro/steering/ Fully configured

What this means in practice: Two developers — one using Cursor, one using Claude Code — generate code that looks like it was written by the same person. No "fix the AI output" phase. No style wars. No architectural drift.

Pre-commit AI Code Review (Code Review Graph MCP)

Every commit triggers a semantic impact analysis powered by a Tree-sitter knowledge graph:

  • Detects which functions, components, and modules are affected
  • Scores risk level of changes
  • Flags architectural violations before they reach PR review
  • Provides blast radius visualization

This isn't linting — it's structural understanding of your codebase.


Production-Grade Architecture

src/
  app/              Routes ONLY — pages, layouts, route handlers
  features/         Vertical slices — one folder per business domain
    [name]/
      _components/  Private UI (never imported outside feature)
      _hooks/       Private hooks
      adapters/     HTTP layer (calls shared/lib/xhr)
      schemas/      Zod schemas + derived types
      services/     Business logic
      actions/      next-safe-action server actions
      index.ts      PUBLIC barrel — the ONLY export surface
  shared/           Cross-cutting utilities
  server/           Server-only code (iron-session, etc.)

Hard rules enforced by ESLint:

  • app/ imports ONLY from features/[name]/index.ts — never deep paths
  • Features NEVER import from other features
  • shared/ NEVER imports from features/ or app/
  • Adapters use shared/lib/xhr.ts — never raw fetch()

Full-Stack Tech Stack

FrameworkNext.js 16 (App Router + Turbopack)
LanguageTypeScript 6 (strict mode)
StylingPanda CSS + Ark UI v5 (headless, WAI-ARIA)
Server StateTanStack Query v5
Client StateZustand v5 + nuqs (URL state)
Formsreact-hook-form + Zod v4
Server Actionsnext-safe-action v8 (end-to-end typed)
TablesTanStack Table v8
HTTPofetch v1 (browser + Edge + SSR)
Authiron-session v8 (encrypted cookies)
AnimationsMotion (Framer Motion v12)
TestingVitest v4 + Testing Library + Playwright
LintingBiome v2 + ESLint (architectural rules)
MonitoringSentry (error tracking + performance)
CI/CDGitHub Actions (lint → type-check → test → build)
ContainersDocker (dev / staging / prod)

Security — Not an Afterthought

  • CSP, HSTS, X-Frame-Options, X-Content-Type-Options configured out of the box
  • import 'server-only' guard on server modules
  • Zod validation at every API boundary
  • Middleware-based route protection
  • public/.well-known/security.txt for responsible disclosure
  • No eval(), no dangerouslySetInnerHTML without DOMPurify

Testing — Mock Adapters, Never Services

npm run test          # Vitest with interactive UI
npm run test:check    # CI mode (exits with code)
npm run test:coverage # Coverage report (v8)
npx playwright test   # E2E tests
  • Mock at the HTTP layer (adapters), never at the service layer
  • @testing-library/react for behavior-driven component tests
  • MSW v2 for network-level API mocking
  • Convention: describe('[ServiceName]') > it('should [behavior] when [condition]')

Quality Gates — Every Commit

Husky runs automatically on every commit:

  1. Biome — format + lint (sub-second)
  2. ESLint — architectural rules (no console.log, no any, no cross-feature imports)
  3. TypeScripttsc --noEmit, zero errors
  4. commitlint — enforces type(scope): description format
  5. Code Review Graph — semantic impact analysis

If it doesn't pass the gates, it doesn't get committed. Period.


Quick Start

# Clone
git clone https://github.com/NoahDuongMaster/ai-first-nextjs-boilerplate.git
cd ai-first-nextjs-boilerplate

# Install
npm install

# Start dev server (Turbopack)
npm run dev

Open http://localhost:3000.

Sync AI configs after editing rules

All AI tool configs are generated from a single source (.ai/rules.md):

./scripts/gen-ai-config.sh

This updates CLAUDE.md, .cursorrules, .windsurfrules, .github/copilot-instructions.md, .gemini/GEMINI.md, and .kiro/steering/ — keeping every AI tool in sync.

Docker environments
# Development (hot-reload, source maps)
npm run build:development && npm run start:development  # → :3001

# Staging (production build, staging env)
npm run build:staging && npm run start:staging          # → :3002

# Production (standalone, minimal image)
npm run build:production && npm run start:production    # → :80
Environment variables

Declared in src/shared/config/env.configuration.ts with Zod validation. Never use process.env directly.

Variable Required Description
NEXT_PUBLIC_APP_URL Yes Public base URL
SESSION_SECRET Yes iron-session secret (32+ chars)
NEXT_PUBLIC_API_URL Yes External API base URL

All Scripts

Command What it does
npm run dev Dev server with Turbopack
npm run build Production build
npm run start Start production server
npm run type-check TypeScript check (zero errors)
npm run lint ESLint + architectural rules
npm run lint:biome Biome check + auto-fix
npm run format Biome format all files
npm run test Vitest with UI
npm run test:check Vitest CI mode
npm run test:coverage Coverage report
npm run build:development Docker build (dev)
npm run build:staging Docker build (staging)
npm run build:production Docker build (prod)

Project Structure

.
├── .ai/rules.md                  Single source of truth for all AI rules
├── .claude/steering/             Claude Code steering rules
├── .cursorrules                  Cursor rules (auto-synced)
├── .windsurfrules                Windsurf rules (auto-synced)
├── .github/copilot-instructions  Copilot rules (auto-synced)
├── .gemini/                      Gemini CLI config + hooks
├── .kiro/steering/               Kiro steering rules
├── docker/                       Three-tier Docker setup
├── scripts/                      AI config sync + setup scripts
├── src/
│   ├── app/                      Next.js routes (zero business logic)
│   ├── features/                 Vertical slices by domain
│   ├── shared/                   Cross-cutting utilities
│   ├── server/                   Server-only code
│   └── __examples__/             Canonical patterns for AI reference
└── tests/                        Playwright E2E tests

Contributing

  1. Fork the repo
  2. Create a branch: feat(scope)/issue-123-description
  3. Follow patterns in src/__examples__/
  4. Pass all gates: npm run type-check && npm run lint && npm run test:check
  5. Open a PR

Star History

Star History Chart

If this saved you time, star the repo — it helps others find it.

Built by Noah Duong · MIT License


Reviews (0)

No results found