Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🟢 Basics – React + Next.js Foundation  ·  Lesson 03

Next.js Project Structure

The folder tree

After create-next-app finishes (with the answers from the previous lesson) your project looks like this:

📁 my-first-app/
  📁 app/                 # all routes (pages) live here
    layout.js          # root layout: <html> and <body>, shared on every page
    page.js            # the home page  →  /
    globals.css        # CSS applied to the whole site
    favicon.ico        # browser tab icon
    📁 about/
      page.js          # →  /about
  📁 public/              # static files served as-is
    logo.png           # →  /logo.png
  📁 node_modules/        # installed packages (never edit)
  📁 .next/               # build output (auto-generated)
  next.config.mjs      # Next.js settings
  package.json         # project name, scripts, dependencies
  jsconfig.json        # the @/* import alias
  AGENTS.md            # notes for AI coding assistants
A fresh Next.js 16 project (JavaScript, App Router)

You will work almost entirely inside app/, plus folders you create such as components/ and lib/.

The app/ folder = your website's map

In the App Router, folders decide URLs. A folder becomes a URL segment, and the page.js inside it is what visitors see.

app/page.js→ /home page
app/about/page.js→ /aboutabout page
Folder path becomes the URL path
JSX – app/about/page.js
// app/about/page.js  →  http://localhost:3000/about
export default function AboutPage() {
  return <h1>About us</h1>
}

layout.js at the top of app/ is the root layout. It must contain <html> and <body>, and {children} is replaced by the current page:

JSX – app/layout.js
// app/layout.js — wraps EVERY page
import './globals.css'

export const metadata = {
  title: 'My First App',
  description: 'Learning Next.js on CodingEasily',
}

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}

Special file names

Next.js gives special meaning to certain file names inside app/. You will learn each one in later lessons:

FileWhat it does
page.jsThe UI of a route — makes the URL public
layout.jsShared wrapper (header, footer) for a folder and its children
loading.jsShown instantly while the page loads
error.jsShown when something crashes in that part of the site
not-found.jsThe 404 page
route.jsAn API endpoint (Route Handler) instead of a page
sitemap.js, robots.jsGenerate /sitemap.xml and /robots.txt
opengraph-image.jsSocial-share image for the route
💡 Any other file name (for example Button.jsx) inside app/ is not a route. It is just a module you can import.

public/ for images and files

Files in public/ are served exactly as they are, from the site root. Do not write public in the URL:

JSX
// public/logo.png is available at /logo.png
<img src="/logo.png" alt="EduSite logo" width="120" height="40" />

Config files

  • package.json — project name, dev / build / start scripts and dependency versions.
  • package-lock.json — exact installed versions, so every computer installs the same thing.
  • next.config.mjs — Next.js options: redirects, image settings, headers.
  • jsconfig.json — the @/* import alias.
  • .gitignore — keeps node_modules, .next and secret .env*.local files out of Git.
  • AGENTS.md — tells AI coding assistants to read the docs that match your Next.js version.

The @ import alias

JSON + JSX
// jsconfig.json
{
  "compilerOptions": {
    "paths": { "@/*": ["./*"] }
  }
}

// Without alias (fragile):
import Header from '../../../components/Header'
// With alias (clean, works from any folder):
import Header from '@/components/Header'

@/ always means "the project root", so imports never break when you move a file deeper.

Where to put your own code

A clean, common layout — the same one used by the EduSite project you will build:

📁 edusite/
  📁 app/
    layout.jsx  page.jsx  globals.css  not-found.jsx  sitemap.js  robots.js
    📁 courses/  page.jsx  [slug]/page.jsx
    📁 blog/     page.jsx  [slug]/page.jsx  loading.jsx
    📁 contact/  page.jsx  ContactForm.jsx  actions.js
    api/courses/route.js
  📁 components/   Header.jsx  Footer.jsx  CourseCard.jsx
  📁 lib/          courses.js  posts.js  site.js
  📁 content/posts/  *.md
  📁 public/images/  *.png
  proxy.js
EduSite project structure (final project)
  • components/ — reusable UI pieces (Header, Card).
  • lib/ — data and helper functions (database, Markdown reader).
  • content/ — Markdown blog posts.

Common mistakes

  • Creating app/about.js — this does nothing. It must be app/about/page.js.
  • Writing src="/public/logo.png" — remove /public.
  • Deleting <html> or <body> from the root layout — the app will not render.
  • Editing files inside node_modules or .next — changes are lost.

Summary

  • app/ holds routes; folder = URL, page.js = the page.
  • layout.js wraps pages; special names add loading, error, 404 and API behaviour.
  • public/ serves static files from /.
  • Use @/ imports and keep shared code in components/ and lib/.
✅ Practice

Create app/contact/page.js and app/courses/page.js with a heading each. Open /contact and /courses in the browser.

Frequently Asked Questions

What is the difference between app/ and pages/?
app/ is the App Router (modern, used in this course) with layouts and Server Components. pages/ is the older Pages Router. New projects should use app/.
Can I delete the .next folder?
Yes. .next is generated by dev and build. Deleting it is a common fix for strange cache problems; it is rebuilt next time you run npm run dev.
Should node_modules be uploaded or committed?
No. node_modules is recreated by npm install from package.json and package-lock.json, so it is listed in .gitignore.
Do I have to use the file name page.js?
Yes, a route becomes public only when its folder contains page.js (or .jsx/.tsx). Other files in the folder are not routes.
← Next.js Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicReact Basics: JSX & Components Your progress: 3 / 37 (8%) · Lesson 4 / 37 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free