Skip to main content
RapidDev - Software Development Agency
cursor-tutorial

How to structure a Next.js project for Cursor

Cursor can scaffold a complete Next.js project structure when given clear conventions about the App Router, file-based routing, and component organization. By adding Next.js-specific rules to .cursorrules and prompting Cursor to follow the official App Router patterns, you get a well-organized project that Cursor can navigate and generate code for efficiently.

What you'll learn

  • How to configure .cursorrules for Next.js App Router conventions
  • How to prompt Cursor to scaffold the correct folder structure
  • How to organize components, hooks, and utilities for Cursor discoverability
  • How to set up route groups and layouts effectively
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner7 min read10-15 minCursor Free+, Next.js 14+ with App RouterMarch 2026RapidDev Engineering Team
TL;DR

Cursor can scaffold a complete Next.js project structure when given clear conventions about the App Router, file-based routing, and component organization. By adding Next.js-specific rules to .cursorrules and prompting Cursor to follow the official App Router patterns, you get a well-organized project that Cursor can navigate and generate code for efficiently.

Structuring a Next.js project for optimal Cursor usage

Next.js App Router uses file-based routing with special files (page.tsx, layout.tsx, loading.tsx). Cursor needs to understand these conventions to generate routes, layouts, and server components correctly. This tutorial establishes a project structure that maximizes Cursor's ability to navigate and generate Next.js code.

Prerequisites

  • Cursor installed with a Next.js project (App Router)
  • Next.js 14+ with TypeScript
  • Basic understanding of the App Router file conventions
  • Familiarity with Cursor Chat (Cmd+L) and Composer (Cmd+I)

Step-by-step guide

1

Add Next.js conventions to .cursor/rules

Create rules that define your Next.js project structure and file conventions. This ensures Cursor generates code in the right locations with the correct patterns.

.cursor/rules/nextjs.mdc
1---
2description: Next.js App Router conventions
3globs: "app/**/*.tsx,app/**/*.ts"
4alwaysApply: true
5---
6
7## Next.js App Router Rules
8- Use the app/ directory for all routes (NOT pages/)
9- page.tsx = route page component (default export)
10- layout.tsx = shared layout (wraps child routes)
11- loading.tsx = loading UI (Suspense boundary)
12- error.tsx = error boundary (must be 'use client')
13- not-found.tsx = 404 page
14- route.ts = API route handler (GET, POST, etc.)
15
16## Component Rules
17- Server Components by default (NO 'use client' unless needed)
18- Add 'use client' ONLY for: useState, useEffect, event handlers, browser APIs
19- Data fetching in Server Components using async/await (not useEffect)
20- Place shared components in src/components/
21- Place page-specific components in app/[route]/_components/
22
23## File Organization
24- app/ routes and layouts
25- src/components/ shared UI components
26- src/hooks/ custom React hooks
27- src/lib/ utility functions and API clients
28- src/types/ TypeScript type definitions
29- public/ static assets

Expected result: Cursor follows Next.js App Router conventions for file placement and component types.

2

Scaffold the project structure with Composer

Use Composer Agent mode to create the initial folder structure with placeholder files. This gives Cursor a map of your project to reference in future prompts.

Cursor Composer prompt
1// Composer prompt (Cmd+I):
2// Create the following Next.js App Router project structure:
3//
4// app/
5// layout.tsx (root layout with html, body, Providers)
6// page.tsx (home page)
7// loading.tsx (global loading spinner)
8// not-found.tsx (404 page)
9// (auth)/
10// login/page.tsx
11// register/page.tsx
12// layout.tsx (auth layout, no navbar)
13// (dashboard)/
14// dashboard/page.tsx
15// settings/page.tsx
16// layout.tsx (dashboard layout with sidebar)
17// api/
18// users/route.ts
19// auth/route.ts
20//
21// src/
22// components/ui/ (Button, Input, Modal)
23// components/layout/ (Navbar, Sidebar, Footer)
24// hooks/ (useAuth, useMediaQuery)
25// lib/ (fetcher, auth, utils)
26// types/ (user, api)
27//
28// Generate minimal placeholder content for each file.

Expected result: A complete Next.js project structure with placeholder files for Cursor to reference.

3

Generate a route with proper patterns

Test the setup by asking Cursor to generate a new route. It should create the correct files in the right locations following App Router conventions.

Cursor Chat prompt
1// Cursor Chat prompt (Cmd+L):
2// @.cursor/rules/nextjs.mdc Create a new /products route with:
3// - Server Component page that fetches products from /api/products
4// - Loading state with loading.tsx
5// - Error boundary with error.tsx
6// - Product card component in app/products/_components/
7// Use Server Component data fetching (async page, not useEffect).
8
9// Expected file structure:
10// app/products/
11// page.tsx (async Server Component)
12// loading.tsx
13// error.tsx ('use client')
14// _components/ProductCard.tsx

Pro tip: Use the _components/ convention (underscore prefix) for route-specific components. The underscore prevents Next.js from treating the folder as a route segment.

Expected result: A complete route with Server Component page, loading state, error boundary, and local components.

4

Organize route groups for different layouts

Use route groups (parenthesized folders) to share layouts between routes without affecting the URL structure. Ask Cursor to set these up correctly.

Cursor Chat prompt
1// Cursor Chat prompt (Cmd+L):
2// @app/layout.tsx Create route groups:
3// (marketing) — public pages with marketing navbar
4// /pricing, /about, /blog
5// (app) — authenticated pages with app sidebar
6// /dashboard, /settings, /profile
7// (auth) — auth pages with minimal layout
8// /login, /register
9// Each group should have its own layout.tsx.
10// The root layout has only Providers and html/body.

Expected result: Three route groups with distinct layouts sharing the same root layout.

5

Configure .cursorignore for Next.js

Exclude Next.js build artifacts and cache from Cursor's indexing to improve performance and avoid stale suggestions.

.cursorignore
1# .cursorignore
2.next/
3node_modules/
4out/
5.vercel/
6coverage/
7*.tsbuildinfo

Expected result: Cursor indexing skips build artifacts, improving performance and suggestion quality.

Complete working example

.cursor/rules/nextjs.mdc
1---
2description: Next.js App Router project conventions
3globs: "app/**/*.{ts,tsx},src/**/*.{ts,tsx}"
4alwaysApply: true
5---
6
7## Route Files (app/ directory)
8- `page.tsx` page component (default export, async for server data)
9- `layout.tsx` shared layout wrapping child routes
10- `loading.tsx` loading UI (automatic Suspense boundary)
11- `error.tsx` error boundary (MUST have 'use client')
12- `not-found.tsx` 404 not found page
13- `route.ts` API route handler (named exports: GET, POST, PUT, DELETE)
14- `_components/` page-specific components (underscore = not a route)
15
16## Component Types
17- Default: Server Component (no 'use client')
18- Add 'use client' ONLY when component uses:
19 - useState, useEffect, useRef, or other hooks
20 - Event handlers (onClick, onChange, etc.)
21 - Browser APIs (window, document, localStorage)
22 - Third-party client libraries
23
24## Data Fetching
25- Server Components: use async/await directly in the component
26- Client Components: use SWR hooks from src/hooks/
27- API Routes: export async functions named GET, POST, etc.
28- NEVER use getServerSideProps or getStaticProps (Pages Router)
29
30## File Organization
31```
32app/ # Routes (file-based routing)
33 (marketing)/ # Route group: public pages
34 (app)/ # Route group: authenticated pages
35 (auth)/ # Route group: auth pages
36 api/ # API routes
37src/
38 components/
39 ui/ # Reusable UI (Button, Input, Modal)
40 layout/ # Layout parts (Navbar, Sidebar)
41 hooks/ # Custom React hooks
42 lib/ # Utilities, API clients, auth
43 types/ # TypeScript definitions
44public/ # Static assets
45```

Common mistakes when structuring a Next.js project for Cursor

Why it's a problem: Cursor generating pages/ directory files instead of app/

How to avoid: Add 'Use the app/ directory for all routes, NOT pages/' to .cursorrules. Explicitly mention App Router in prompts.

Why it's a problem: Adding 'use client' to every component

How to avoid: Add 'Server Components by default, add use client ONLY for hooks and event handlers' to your rules.

Why it's a problem: Using useEffect for data fetching in Server Components

How to avoid: Add 'Data fetching in Server Components using async/await, not useEffect' to your Next.js rules.

Best practices

  • Use App Router conventions (app/) not Pages Router (pages/)
  • Default to Server Components and only add 'use client' when necessary
  • Use route groups (parentheses) for layout organization without URL impact
  • Place page-specific components in _components/ subdirectories
  • Fetch data directly in async Server Components, not with useEffect
  • Configure .cursorignore to exclude .next/ and node_modules/
  • Reference @.cursor/rules/nextjs.mdc when asking Cursor to generate routes

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

Create a Next.js 14 App Router project structure with: route groups for marketing (public), app (authenticated), and auth (login/register). Include proper layouts, loading states, error boundaries, and API routes. Show the complete folder tree with file purposes. Use TypeScript and Server Components by default.

Cursor Prompt

In Cursor Composer (Cmd+I): @.cursor/rules/nextjs.mdc Scaffold a new /products route with: async Server Component page fetching from /api/products, loading.tsx, error.tsx ('use client'), _components/ProductCard.tsx (Server Component), and api/products/route.ts with GET handler.

Frequently asked questions

Should I use src/ or put everything in app/?

Use src/ for shared code (components, hooks, lib, types) and app/ for routes only. This keeps routes clean and makes shared code easy to reference with @src/.

Can Cursor handle Next.js Server Actions?

Yes. Ask Cursor to generate Server Actions with 'use server' directive. Reference your form component and specify the action should be in the same file or a separate actions.ts file.

How do I handle route params in Cursor prompts?

Specify the dynamic route: 'Create app/products/[id]/page.tsx that receives params.id as a prop.' Cursor understands Next.js dynamic route conventions.

Does Cursor know about Next.js middleware?

Yes. Ask Cursor to generate middleware.ts at the project root for auth redirects, rate limiting, or request rewriting. Specify the matcher pattern in your prompt.

How do I handle Cursor generating Pages Router code?

Add a strict rule: 'This project uses App Router. NEVER use getServerSideProps, getStaticProps, or the pages/ directory.' Reference this rule in every prompt about routing.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.