Skip to main content
⚡ OpenDevDocs
Next.js
frontendnextjsGuideBeginner

Next.js App Router Project Structure

Understanding Next.js folder organization: special file conventions (page, layout, loading, error, not-found, route), public assets, and components.

Verified: 2026-09-30
Tested on:nextjs 16.x
Platforms:
web
#nextjs#project-structure#conventions#special-files

Next.js App Router Project Structure

Next.js uses a file-system based router where folders define URL paths and special reserved files define UI behaviors and routing logic.


1. Complete Architecture Overview

my-next-app/
├── app/                      # App Router root
│   ├── layout.tsx            # Root layout (required: <html> and <body>)
│   ├── page.tsx              # Homepage UI (Route: /)
│   ├── loading.tsx           # Global loading skeleton (React Suspense)
│   ├── error.tsx             # Global client error boundary
│   ├── not-found.tsx         # 404 UI
│   ├── global.css            # Tailwind & CSS design system
│   ├── api/                  # Backend Route Handlers
│   │   └── search/
│   │       └── route.ts      # API endpoint (GET /api/search)
│   └── docs/                 # Nested route (/docs)
│       ├── layout.tsx        # Docs sidebar layout
│       └── [slug]/
│           └── page.tsx      # Dynamic route (/docs/javascript)
├── components/               # Reusable UI components
├── lib/                      # Database clients (prisma.ts) and utilities
├── public/                   # Static uncompiled assets (favicon, images)
├── next.config.ts            # Next.js framework configuration
└── tsconfig.json             # TypeScript configuration with @/* alias

2. Special Reserved File Conventions

File NamePurposeRender Context
page.tsxUnique UI for the route segmentServer Component (default)
layout.tsxShared UI wrapper for a segment and its childrenServer Component (default)
loading.tsxInstant loading UI wrapped in React SuspenseServer Component
error.tsxError UI boundary for a segmentMust be Client Component ("use client")
not-found.tsx404 Not Found UIServer Component
route.tsBackend HTTP API endpoint (GET, POST, etc.)Server only (no JSX)
middleware.tsEdge request interceptor at project rootEdge / Node.js runtime

On this page