Setup and Project Structure
Level: Beginner to Intermediate
- Creating a Next.js project with create-next-app
- App directory structure and conventions
- Config files: next.config.js, tsconfig.json, package.json
- public folder for static assets
- Environment variables setup
- npm scripts: dev, build, start
- TypeScript in Next.js projects
- SMS project folder organization
Why This Matters
Setup and Project Structure is part of building production React applications with Next.js. You will use it when creating student dashboards, SEO-friendly pages, API-connected forms, route handlers, layouts, and deployments for .NET-backed systems.
Next.js projects are usually created with create-next-app.
The Problem
Beginners often treat Next.js like plain React and miss routing, rendering, server/client boundaries, environment variables, and deployment behavior. This lesson shows how Setup and Project Structure works in a real School Management System frontend that talks to ASP.NET Core APIs.
Prerequisites
Install Node.js LTS. Then check:
node --version
npm --version
Create a Project
npx create-next-app@latest school-ui
For beginner learning, choose:
TypeScript? No or Yes
ESLint? Yes
Tailwind CSS? Optional
src directory? Optional
App Router? Yes
Turbopack? Yes
Import alias? Yes
If you are learning React with JavaScript first, choose JavaScript. For production teams, TypeScript is usually better.
Run the App
cd school-ui
npm run dev
Open:
http://localhost:3000
Important Files
school-ui/
app/
layout.jsx
page.jsx
globals.css
public/
package.json
next.config.js
| File/folder | Purpose |
|---|---|
app/page.jsx | Home page |
app/layout.jsx | Shared root layout |
app/globals.css | Global styles |
public/ | Static files like images |
package.json | Scripts and dependencies |
next.config.js | Next.js configuration |
package.json Scripts
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
}
}
Use:
npm run devduring developmentnpm run buildbefore deploymentnpm run startto run the production build locally
Always run npm run build before publishing. Development mode can hide performance and routing issues.
First Page
export default function HomePage() {
return (
<main>
<h1>School Management System</h1>
<p>Welcome to the Next.js frontend.</p>
</main>
);
}
Interview Questions
The app folder contains routes, layouts, pages, loading UI, error UI, and route handlers for the App Router.
npm run dev starts a development server. npm run build creates an optimized production build and catches many deployment issues.
Quick Definitions
- Setup and Project Structure - The main Next.js concept explained in this lesson.
- App Router - The modern Next.js routing system based on the
appfolder. - Server/Client boundary - The decision of whether code runs on the server or in the browser.
- ASP.NET Core integration - Calling or proxying backend APIs from a Next.js frontend.
Common Mistakes
- Treating every component as a Client Component without a reason
- Forgetting environment variables differ between local and production
- Calling ASP.NET Core APIs from the browser without handling CORS
- Putting secrets in
NEXT_PUBLIC_variables - Skipping
npm run buildbefore deployment
Practice Task
Create a small Next.js example using Setup and Project Structure. Keep it connected to a School Management System scenario.
Suggested practice:
- Create or update a route, layout, form, or data-fetching example.
- Use realistic student, teacher, attendance, or marks data.
- Connect the example to an ASP.NET Core-style API URL or route handler.
- Add one loading, empty, or error state where relevant.
- Explain what runs on the server and what runs in the browser.
Quick Revision
| Question | Answer |
|---|---|
| What is the main idea? | Use Setup and Project Structure correctly in a Next.js App Router project. |
| Where is it used? | Pages, layouts, route handlers, forms, APIs, authentication, and deployment. |
| What should beginners watch carefully? | Server/client boundaries, environment variables, CORS, and production builds. |
| What is the best debugging habit? | Check terminal build output, browser console, network tab, and server logs. |
Use ChatGPT, Claude, or Copilot to go deeper on Setup and Project Structure. Try these prompts:
"Explain Setup and Project Structure with a Next.js and ASP.NET Core example""Give me 5 practice tasks for Setup and Project Structure in a School Management app""Show common Next.js mistakes in Setup and Project Structure and how to fix them""Quiz me on Setup and Project Structure with interview-style questions"
💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.