TL;DR: Next.js is a React framework by Vercel that adds page routing, server-side rendering, API routes, and optimized deployment on top of React. It's the default choice for most AI code generators when you ask for a web app. Understanding Next.js means understanding why your AI-generated project has an app/ folder, server and client components, and why npm run dev starts a local server on port 3000.

Why AI Coders Need to Know This

Here's what happens to most vibe coders: you ask your AI to build something — a dashboard, a blog, a SaaS landing page. The AI generates a project. You look at the files and see app/, layout.tsx, page.tsx, next.config.js, and you have no idea what any of it means.

That's Next.js. And if you don't understand the basic structure, you can't debug it when something breaks. You can't tell your AI what's wrong. You'll be stuck copying error messages and hoping for the best.

You don't need to master Next.js. You need to understand what it does so you can work with your AI effectively when it generates Next.js code.

React vs. Next.js: What's the Difference?

Think of it like this: React gives you the materials to build a house — bricks, wood, nails. Next.js gives you the materials plus a blueprint, plumbing, and electrical already wired up.

React (alone)

  • UI components (buttons, forms, lists)
  • State management (tracking data changes)
  • No built-in routing
  • No built-in backend
  • No built-in SEO
  • You configure everything yourself

Next.js (React + extras)

  • Everything React does
  • Page routing (folders = pages)
  • Server-side rendering (SEO)
  • API routes (backend logic)
  • Image optimization
  • One-click deployment to Vercel

The Next.js File Structure Your AI Generates

When your AI creates a Next.js project, you'll see something like this:

my-app/
├── app/
│   ├── layout.tsx      ← wraps every page (header, footer, global styles)
│   ├── page.tsx        ← the homepage (what shows at /)
│   ├── about/
│   │   └── page.tsx    ← the about page (what shows at /about)
│   ├── blog/
│   │   ├── page.tsx    ← blog listing (what shows at /blog)
│   │   └── [slug]/
│   │       └── page.tsx ← individual blog posts (/blog/my-post)
│   └── api/
│       └── users/
│           └── route.ts ← API endpoint (backend logic at /api/users)
├── public/             ← static files (images, fonts)
├── next.config.js      ← Next.js settings
├── package.json        ← dependencies and scripts
└── tsconfig.json       ← TypeScript settings

The magic: folders become URLs. Create a folder called app/pricing/ with a page.tsx inside it, and your site now has a /pricing page. No router configuration. No import statements. The folder structure is the routing.

Server Components vs. Client Components

This is the single most confusing thing about modern Next.js — and the #1 reason AI-generated Next.js code breaks.

The Rule That Breaks Everything

In Next.js, components are server components by default. They run on the server, not in the browser. This means they can't use useState, useEffect, onClick, or any browser-specific code. If you need interactivity, you have to add 'use client' at the top of the file.

Here's what this looks like in practice:

// ❌ This BREAKS — server component trying to use browser features
export default function Counter() {
  const [count, setCount] = useState(0)  // ERROR!
  return <button onClick={() => setCount(count + 1)}>{count}</button>
}

// ✅ This WORKS — marked as client component
'use client'
export default function Counter() {
  const [count, setCount] = useState(0)
  return <button onClick={() => setCount(count + 1)}>{count}</button>
}

Why your AI gets this wrong: AI models were trained on older React code where everything ran in the browser. They'll sometimes generate components with useState or onClick without adding 'use client'. When you see the error "useState is not a function" or "Event handlers cannot be passed to Server Component" — this is why.

What to Tell Your AI When This Breaks

"This component uses useState/onClick but doesn't have 'use client' at the top. It's a server component by default in Next.js App Router. Add 'use client' to make it a client component, or refactor to separate server and client parts."

API Routes: Your Backend in a Folder

One of Next.js's most powerful features for vibe coders: you can write backend code right inside your project. No separate server. No Express.js setup. Just create a file in app/api/.

// app/api/users/route.ts
import { NextResponse } from 'next/server'

export async function GET() {
  // This runs on the server, not in the browser
  const users = await db.query('SELECT * FROM users')
  return NextResponse.json(users)
}

export async function POST(request: Request) {
  const body = await request.json()
  const newUser = await db.insert('users', body)
  return NextResponse.json(newUser, { status: 201 })
}

Your frontend calls /api/users and gets data back. Your REST API lives right next to your UI code. When you ask your AI to "add a backend," this is usually what it creates.

What AI Gets Wrong About Next.js

  • Missing 'use client': The #1 bug. AI generates interactive components without the directive. Fix: add 'use client' at the top.
  • Mixing App Router and Pages Router: Next.js has two routing systems. The old one uses pages/, the new one uses app/. AI sometimes generates code for the wrong one. If you see getServerSideProps — that's the old system.
  • Import confusion: AI imports next/router (old) instead of next/navigation (new). If routing isn't working, check imports.
  • Over-engineering: AI might generate Next.js for a simple calculator or single-page tool. You can ask it to use plain React + Vite instead.

Deploying Next.js (It's Ridiculously Easy)

Next.js was built by Vercel, and deploying to Vercel is effectively one click:

  1. Push your code to GitHub
  2. Connect the repo to Vercel
  3. Vercel detects Next.js automatically and deploys it

You can also deploy to other platforms — Netlify, Railway, a VPS — but Vercel is the path of least resistance because they literally built the framework.

When to Use Next.js (and When Not To)

Use Next.js When

  • Multi-page website or app
  • SEO matters (blog, landing page, marketing site)
  • You need API routes / backend logic
  • Deploying to Vercel
  • Your AI already generated it

Skip Next.js When

  • Single-page app (calculator, dashboard)
  • Learning React basics
  • Static site with no backend
  • Prototype / throwaway project
  • You want maximum simplicity

What to Learn Next

Next Step

Ask your AI to "build a simple blog with Next.js App Router" and study the folder structure it generates. Pay attention to the app/ directory, the layout.tsx, and which components have 'use client' at the top. That understanding will save you hours of debugging later.

FAQ

Next.js is a React framework made by Vercel. It adds routing, server-side rendering, API routes, and deployment optimization on top of React. When you ask an AI to build a web app with React, there's a good chance it generates a Next.js project because Next.js handles the things React alone doesn't — like page navigation, SEO, and talking to a backend.

React is a library for building user interfaces. Next.js is a framework built on top of React that adds routing between pages, server-side rendering for SEO, API routes for backend logic, and optimized deployment. React gives you components. Next.js gives you a complete application structure.

If you're vibe coding with AI, Next.js is one of the easiest frameworks to use because AI models have been trained on massive amounts of Next.js code. The learning curve is understanding what your AI generated — especially server vs. client components.

The App Router is Next.js's current routing system. Instead of configuring routes in a file, you create folders inside app/. A folder called app/about/ automatically becomes the /about page. Your AI will generate this structure automatically.

No. For simple single-page apps, a plain React + Vite setup is lighter and faster. Next.js is best when you need multiple pages, SEO, server-side logic, or you plan to deploy on Vercel. If your AI suggests Next.js and you only need a calculator, ask it to use plain React instead.