Project Structure (Next.js)
This defines how your project files and folders are organized
Top-Level Folders
Used to organize code and assets:
app/→ App Routerpages/→ Pages Routerpublic/→ Static files (images, fonts)src/→ Optional source folder
Top-Level Files
Important config files:
package.json→ dependencies & scriptsnext.config.js→ Next.js config.env→ environment variablestsconfig.json→ TypeScript config.gitignore→ ignored files
🧭 Routing Files
Special files for routing:
FilePurposepage.tsxPage UIlayout.tsxShared layoutloading.tsxLoading UIerror.tsxError UIroute.tsAPI route
🔗 Nested Routes
Folder = URL path
app/
├── page.tsx → /
├── blog/
│ └── page.tsx → /blog✔ Folders create routes automatically
🔄 Dynamic Routes
👉 Use [ ] for dynamic URLs:
app/blog/[slug]/page.tsx👉 Example:
/blog/my-post📦 Route Types
TypeExampleDynamic[slug]Catch-all[...slug]Optional[[...slug]]
🧩 Route Groups
👉 Organize folders without changing URL:
app/(marketing)/page.tsx → /✔ (folder) is NOT in URL
🔒 Private Folders
👉 Prefix _ to make non-routable:
app/blog/_components/✔ Used for:
Components
Utils
Internal logic
⚡ Special Routing Features
🔹 Parallel Routes
👉 Use @folder for multiple UI sections
🔹 Intercepted Routes
👉 Show one route inside another (like modal)
Component Hierarchy
👉 Rendering order:
layout → template → error → loading → page📁 Public Folder
👉 Static files:
public/image.png → /image.png📊 Metadata Files
SEO & icons:
favicon.icositemap.xmlrobots.txtopengraph-image.png
🧩 Project Organization Strategies
You can organize in 3 ways:
1. Outside app/
Keep logic in root folders
2. Inside app/
Keep everything in app folder
3. Feature-based
Split by feature or route
🎯 Key Concepts
Folder = Route
page.tsx= public route_folder= private(folder)= group (no URL change)