The folder structure in a Next.js project depends on whether you use the App Router (introduced in Next.js 13) or the Pages Router (legacy approach). Below is the standard folder structure for both:
1๏ธโฃ App Router (Next.js 13+) – Recommended
Next.js introduced the app directory to enable React Server Components, Server Actions, and Streaming. The structure looks like this:
my-next-app/
โโโ public/ # Static assets (images, icons, etc.)
โโโ src/ # Source folder (optional)
โ โโโ app/ # App Router (Replaces pages/)
โ โ โโโ layout.tsx # Root layout (applies to all pages)
โ โ โโโ page.tsx # Default homepage
โ โ โโโ about/ # Route: /about
โ โ โ โโโ page.tsx
โ โ โโโ dashboard/ # Nested routes: /dashboard
โ โ โ โโโ page.tsx
โ โ โ โโโ settings/
โ โ โ โ โโโ page.tsx
โ โ โโโ api/ # API routes (e.g., /api/hello)
โ โ โ โโโ hello/
โ โ โ โ โโโ route.ts
โ โโโ components/ # Reusable UI components
โ โโโ styles/ # Global CSS or Tailwind config
โ โโโ lib/ # Utility functions, API calls
โ โโโ hooks/ # Custom hooks
โ โโโ context/ # Context providers (optional)
โโโ .next/ # Build output (auto-generated)
โโโ node_modules/ # Installed dependencies
โโโ next.config.js # Next.js config file
โโโ tailwind.config.js # Tailwind CSS config (if using Tailwind)
โโโ package.json # Project dependencies & scripts
โโโ tsconfig.json # TypeScript config (if using TypeScript)
โโโ .gitignore # Ignore unnecessary files
๐ฅ Key Features in App Router
- Uses React Server Components (RSC).
- Supports Layouts (
layout.tsx). - New API routes (
app/api/route.ts). - Improved data fetching (Server Actions, Streaming).
2๏ธโฃ Pages Router (Legacy Approach)
Before Next.js 13, all pages were inside the pages/ directory.
my-next-app/
โโโ public/ # Static assets (images, icons, etc.)
โโโ pages/ # Page-based routing
โ โโโ index.tsx # Homepage (/)
โ โโโ about.tsx # About page (/about)
โ โโโ dashboard/ # Nested pages
โ โ โโโ index.tsx # Dashboard main page
โ โ โโโ settings.tsx # Dashboard settings (/dashboard/settings)
โ โโโ api/ # API routes (e.g., /api/hello)
โ โ โโโ hello.ts
โโโ components/ # Reusable UI components
โโโ styles/ # CSS or Tailwind styles
โโโ utils/ # Helper functions
โโโ .next/ # Build output (auto-generated)
โโโ node_modules/ # Installed dependencies
โโโ next.config.js # Next.js config
โโโ package.json # Dependencies & scripts
โโโ tsconfig.json # TypeScript config (if using TypeScript)
โโโ .gitignore # Ignore unnecessary files
๐ Key Differences Between App Router & Pages Router
| Feature | App Router (app/) | Pages Router (pages/) |
|---|---|---|
| Server Components | โ Yes (default) | โ No |
| API Routes | โ
app/api/route.ts | โ
pages/api/hello.ts |
| Layouts | โ
Built-in (layout.tsx) | โ Manual _app.tsx |
| Streaming & Suspense | โ Yes | โ No |
| File-based Routing | โ Yes | โ Yes |
| Client-side Rendering | โ
Yes (with "use client") | โ Yes |
Which One Should You Use?
- โ
Use
app/(App Router) for new projects (recommended). - ๐ Use
pages/(Pages Router) if migrating an old project.
Read other awesome articles inย Medium.com or in akcoding’s posts.
OR
Join us on YouTube Channel
OR Scan the QR Code to Directly open the Channel ๐

