Getting Started: Project Structure | Next.js (2024)

This page provides an overview of the project structure of a Next.js application. It covers top-level files and folders, configuration files, and routing conventions within the app and pages directories.

Click the file and folder names to learn more about each convention.

Top-level folders

Top-level folders are used to organize your application's code and static assets.

Getting Started: Project Structure | Next.js (1)Getting Started: Project Structure | Next.js (2)
appApp Router
pagesPages Router
publicStatic assets to be served
srcOptional application source folder

Top-level files

Top-level files are used to configure your application, manage dependencies, run middleware, integrate monitoring tools, and define environment variables.

Next.js
next.config.jsConfiguration file for Next.js
package.jsonProject dependencies and scripts
instrumentation.tsOpenTelemetry and Instrumentation file
middleware.tsNext.js request middleware
.envEnvironment variables
.env.localLocal environment variables
.env.productionProduction environment variables
.env.developmentDevelopment environment variables
.eslintrc.jsonConfiguration file for ESLint
.gitignoreGit files and folders to ignore
next-env.d.tsTypeScript declaration file for Next.js
tsconfig.jsonConfiguration file for TypeScript
jsconfig.jsonConfiguration file for JavaScript

app Routing Conventions

The following file conventions are used to define routes and handle metadata in the app router.

Routing Files

layout.js .jsx .tsxLayout
page.js .jsx .tsxPage
loading.js .jsx .tsxLoading UI
not-found.js .jsx .tsxNot found UI
error.js .jsx .tsxError UI
global-error.js .jsx .tsxGlobal error UI
route.js .tsAPI endpoint
template.js .jsx .tsxRe-rendered layout
default.js .jsx .tsxParallel route fallback page

Nested Routes

folderRoute segment
folder/folderNested route segment

Dynamic Routes

[folder]Dynamic route segment
[...folder]Catch-all route segment
[[...folder]]Optional catch-all route segment

Route Groups and Private Folders

(folder)Group routes without affecting routing
_folderOpt folder and all child segments out of routing

Parallel and Intercepted Routes

@folderNamed slot
(.)folderIntercept same level
(..)folderIntercept one level above
(..)(..)folderIntercept two levels above
(...)folderIntercept from root

Metadata File Conventions

App Icons

favicon.icoFavicon file
icon.ico .jpg .jpeg .png .svgApp Icon file
icon.js .ts .tsxGenerated App Icon
apple-icon.jpg .jpeg, .pngApple App Icon file
apple-icon.js .ts .tsxGenerated Apple App Icon

Open Graph and Twitter Images

opengraph-image.jpg .jpeg .png .gifOpen Graph image file
opengraph-image.js .ts .tsxGenerated Open Graph image
twitter-image.jpg .jpeg .png .gifTwitter image file
twitter-image.js .ts .tsxGenerated Twitter image

SEO

sitemap.xmlSitemap file
sitemap.js .tsGenerated Sitemap
robots.txtRobots file
robots.js .tsGenerated Robots file

pages Routing Conventions

The following file conventions are used to define routes in the pages router.

Special Files

_app.js .jsx .tsxCustom App
_document.js .jsx .tsxCustom Document
_error.js .jsx .tsxCustom Error Page
404.js .jsx .tsx404 Error Page
500.js .jsx .tsx500 Error Page

Routes

Folder convention
index.js .jsx .tsxHome page
folder/index.js .jsx .tsxNested page
File convention
index.js .jsx .tsxHome page
file.js .jsx .tsxNested page

Dynamic Routes

Folder convention
[folder]/index.js .jsx .tsxDynamic route segment
[...folder]/index.js .jsx .tsxCatch-all route segment
[[...folder]]/index.js .jsx .tsxOptional catch-all route segment
File convention
[file].js .jsx .tsxDynamic route segment
[...file].js .jsx .tsxCatch-all route segment
[[...file]].js .jsx .tsxOptional catch-all route segment
Getting Started: Project Structure | Next.js (2024)
Top Articles
Latest World & National News & Headlines
Auto Approve: Reviews, Loan Details & Services (2024)
Northern Counties Soccer Association Nj
No Hard Feelings Showtimes Near Metropolitan Fiesta 5 Theatre
Minooka Channahon Patch
Urist Mcenforcer
Cottonwood Vet Ottawa Ks
Tyson Employee Paperless
Fort Carson Cif Phone Number
Byrn Funeral Home Mayfield Kentucky Obituaries
Recent Obituaries Patriot Ledger
Cosentyx® 75 mg Injektionslösung in einer Fertigspritze - PatientenInfo-Service
Rochester Ny Missed Connections
Deshret's Spirit
MADRID BALANZA, MªJ., y VIZCAÍNO SÁNCHEZ, J., 2008, "Collares de época bizantina procedentes de la necrópolis oriental de Carthago Spartaria", Verdolay, nº10, p.173-196.
Does Pappadeaux Pay Weekly
What is a basic financial statement?
Miami Valley Hospital Central Scheduling
Pro Groom Prices – The Pet Centre
ocala cars & trucks - by owner - craigslist
The fabulous trio of the Miller sisters
5 high school volleyball stars of the week: Sept. 17 edition
Boston Gang Map
Drago Funeral Home & Cremation Services Obituaries
Wsop Hunters Club
Universal Stone Llc - Slab Warehouse & Fabrication
12 Top-Rated Things to Do in Muskegon, MI
The Old Way Showtimes Near Regency Theatres Granada Hills
Free Personals Like Craigslist Nh
Riversweeps Admin Login
Obituaries Milwaukee Journal Sentinel
Deshuesadero El Pulpo
Sienna
Black Panther 2 Showtimes Near Epic Theatres Of Palm Coast
Datingscout Wantmatures
Purdue Timeforge
J&R Cycle Villa Park
Springfield.craigslist
Los Amigos Taquería Kalona Menu
Rocketpult Infinite Fuel
Tyler Sis 360 Boonville Mo
Western Gold Gateway
Heavenly Delusion Gif
Blasphemous Painting Puzzle
Andrew Lee Torres
20 Mr. Miyagi Inspirational Quotes For Wisdom
Ewwwww Gif
Peugeot-dealer Hedin Automotive: alles onder één dak | Hedin
Cheryl Mchenry Retirement
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5589

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.