Next.js (Pages Router): How I set up a Next.js project structure

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


Next.js is great to give our React apps a big set of built-in features that are essential in Web applications.

It gives us just a little bit of structure for our project files.

All visible pages stay under the /pages folder. API routes stay under the /pages/api folder. Publicly visible files under /public.

That’s basically all. The rest is all on us.

What I commonly do is this.

All the React components required by pages are in a /components folder.

I usually have a /components/Common folder, and then I re-create the pages structure:

  • /components/Common
  • /components/Home
  • /components/Profile

… and so on.

Then I have a lib folder that contains all the utilities used by the React components or the API routes. It might be data fetching, a library initialization, the Prisma setup, database access, a fetcher for SWR, the easy-peasy store.. basically anything that could be reused anywhere but it’s not a component.

I also make sure that I can include them like this:

import comp from components/Common/comp
import x from lib/x

using this little setup in jsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "."
  }
}

I mentioned Prisma, which I use frequently. That’d need its own /prisma folder for the schema and the migrations, and maybe an SQLite database if needed.

If the site has content, in form of markdown for example, I’ll add a /content folder.

For middleware (sometimes it’s useful), /middleware but it’s quite rare.

This will work fine for almost all the things you’ll need.

Lessons in this unit:

0: Introduction
1: Getting started with Next.js (Pages Router), a tutorial
2: How to install Next.js
3: ▶︎ How I set up a Next.js project structure
4: Linking two pages in Next.js using Link
5: How to use the Next.js Router
6: Dynamic content in Next.js with the router
7: Prefetching content in Next.js
8: How to programmatically change a route in Next.js
9: View source to confirm SSR is working in Next.js
10: Feed data to a Next.js component using getInitialProps
11: Styling Next.js components using CSS
12: Next.js: populate the head tag with custom tags
13: How to use Next.js API Routes
14: How to get cookies server-side in a Next.js app
15: Deploying a Next.js application on Now
16: Deploying a Next.js app in production