Slide 1
-----------
Part 1: In this lecture, we'll look at some NextJS foundations, such as creating a project from scratch and exploring the files and folders of a simple application.
Slide 2
-----------
Part 1: While we have a project to work on, let's see how easy it is to start a new Next.js project from scratch. It's a simple command, and you'll be guided through the setup process.
Part 2: This single command is all it takes to kick off a new Next.js project. It's interactive, so you can customize your project as you go.
Part 3: The command-line tool will then ask you a series of questions to configure your new project. This makes it easy to tailor the project to your specific needs.
Part 4: First, you'll be asked to name your project. This determines the name of the directory where your project will reside. For instance, if you enter "my-blog," a folder named "my-blog" will be created.
Part 5: Next, you can choose whether or not to use TypeScript. TypeScript adds static typing, which helps catch errors early. It's highly recommended for larger projects. Choosing "Yes" will generate a tsconfig.json file.
Part 6: ESLint is a linting tool that helps maintain consistent coding style and catches potential errors. It's a great practice to include it from the start. Choosing "Yes" creates an eslintrc json file.
Part 7: Tailwind CSS is a utility-first CSS framework that speeds up UI styling. If you choose "Yes", it will be installed and configured. If you choose "No", the initial project will use CSS modules.
Part 8: This option lets you choose whether to keep your code inside a src directory. It's a good way to keep your project organised. Choosing "Yes" will create a src folder with app, components, and styles sub-folders.
Part 9: The App Router is the latest and recommended routing strategy in Next.js. It uses React Server Components and unlocks powerful features. Choosing "Yes" uses the app directory. Choosing "No" will use the legacy Pages Router and the pages directory. It is recommended to use app router.
Part 10: Turbopack is a Rust-based bundler that offers faster development. Choosing "Yes" uses Turbopack, and "No" uses Webpack. Turbopack is generally recommended for faster development, but it's still under development so some less common features might not work as expected.
Part 11: Import aliases make your imports cleaner. Choosing "Yes" lets you customise the alias
Part 12: If you chose to customize the alias, you'll specify the value here. This sets up the alias in your tsconfig.json or jsconfig.json file.
Part 13: Once you answer all the questions, your new project will be created in the specified directory, and all the dependencies will be installed. You are ready to go!
Part 14: If you have visual studio code installed, you can run the following commands to quickly open the project in the visual studio code!
Slide 3
-----------
Part 1: Once the project is generated and open in Visual Studio Code, you can see the following structure of files and folders.
Part 2: The app directory is the heart of the App Router. It contains your pages, layouts, and API routes. This is where you'll spend most of your time.
Part 3: The layout tsx file defines the root layout of your application. It persists across all pages, making it ideal for headers, footers, and other shared components. This is a Server Component.
Part 4: The page tsx file in the app directory represents the main home page, also known as root. This is also a Server Component.
Part 5: Nested directories within app create routes. For example, app/dashboard/page tsx creates the /dashboard route. This is also a Server Component.
Part 6: Even deeper nesting is possible. app/dashboard/settings/page tsx would create the /dashboard/settings route. This is also a Server Component.
Part 7: The api directory is for API routes. route.ts files define the handlers for your API endpoints. These are server functions, not components.
Part 8: The public folder contains all the files your users need to access, such as images or external javascript files.
Part 9: next config json contains the configuration of the NextJS application. Please see the documentation for all the possibilities.
Part 10: package json contains the list of installed packages of a NodeJS package or application.
Part 11: tsconfig json contains the configuration parameters for typescript, such as the aliases or target javascript version.
Slide 4
-----------
Part 1: To start the development server, navigate to your project directory in the terminal and run pnpm run. This will start the server. The project will usually run on port 3000. If that port is in use, Next.js will automatically use the next available port, like 3001, 3002, and so on. Pay attention to the URL in the terminal so you know where to access your application.
Part 2: To build a production version of your application you use the pnpm build command. wewer
Part 3: After you build your application, you can start it with the pnpm start command. Note that pnpm start will not work if the application is not built.
Slide 5
-----------
Part 1: For this course, we'll be using a monorepo structure, similar to what you set up in your second assignment. This keeps things organized as our project grows.
Part 2: It's highly recommended to create a new branch called "Lecture" for working on the exercises in this course. This keeps your main branch clean and allows you to experiment freely.
Part 3: Make sure you've set up the project according to the instructions provided. This will ensure everyone is working with the same codebase.
Part 4: While we cover a significant portion of what NextJS can do, it is always good to get accustomed to their docs for further information.
Part 5: Let the coding begin!
NEXT.JS FOUNDATIONS 🚀
In this module of our Full-Stack Development Course, we dive into Next.js, a
powerful React framework that makes building fast, scalable, and SEO-friendly
web applications easier than ever. Next.js goes beyond traditional React by
offering server-side rendering (SSR), static site generation (SSG), and API
routes, making it perfect for modern full-stack applications. Throughout this
course, we’ll progressively build a feature-rich blogging and content management
system (CMS), learning how to fetch and mutate data, optimize performance, and
secure our app with authentication. By the end, you’ll have the essential skills
to develop and deploy production-ready full-stack applications with Next.js! 🚀
While we will use a project with some boilerplate, let's first take a look at
how can you quickly start a new project with Next.js!
🎬 STARTING FROM SCRATCH
If you want to create a clean new Next.js project, you can use the the following
command, which will take you through series of questions to set up your project:
pnpx create-next-app@latest
This is what you can observe in the console:
[https://skillpies.s3.ap-southeast-2.amazonaws.com/courses/full-stack-development-comp3036-2025/sections/next-js-introduction-in-next-js-backend/Screenshot%202025-02-13%20at%2013.33.23.png]
LET'S BREAK IT DOWN!
1. WHAT IS YOUR PROJECT NAMED?
Example: my-test-project
This defines the name of your project folder. Whatever you enter here will be
used as the directory name where your Next.js project is initialized.
📌 Effect: Creates a folder with this name and sets up a Next.js project inside
it.
--------------------------------------------------------------------------------
2. WOULD YOU LIKE TO USE TYPESCRIPT? (NO / YES)
TypeScript is a superset of JavaScript that adds static typing, which helps
catch errors at compile time rather than runtime.
• Yes → The project will be set up with TypeScript, and .ts/.tsx files will be
used instead of .js/.jsx.
• No → The project will use plain JavaScript.
📌 Effect: If enabled, Next.js generates a tsconfig.json file and ensures
TypeScript is properly configured.
--------------------------------------------------------------------------------
3. Would you like to use ESLint? (No / Yes)
ESLint is a tool that helps enforce consistent coding style and catch common
errors in JavaScript/TypeScript.
• Yes → A .eslintrc.json file is created with Next.js-specific linting rules.
• No → No linting setup is included.
📌 Effect: Helps maintain clean, readable, and bug-free code.
--------------------------------------------------------------------------------
4. Would you like to use Tailwind CSS? (No / Yes)
Tailwind CSS [https://tailwindcss.com/] is a utility-first CSS framework that
allows for rapid UI styling using predefined classes.
• Yes → Tailwind CSS is installed and configured in tailwind.config.js.
• No → No CSS framework is included (you can add your own later). The initial
project will use CSS modules
📌 Effect: If enabled, Next.js will automatically configure Tailwind CSS and
PostCSS for styling.
--------------------------------------------------------------------------------
5. Would you like your code inside a src/ directory? (No / Yes)
By default, Next.js places its files (pages/, components/, etc.) in the root
directory. Enabling this option moves everything inside a src/ folder, making
the root cleaner.
• Yes → The project structure will look like:
/my-test-project
├── /src
│ ├── /app (or /pages if using Pages Router)
│ ├── /components
│ ├── /styles
• No → All project files remain at the root level.
📌 Effect: Organizes the code into a src/ folder for better project structure.
--------------------------------------------------------------------------------
6. Would you like to use App Router? (recommended) (No / Yes)
Next.js has two routing strategies:
• Pages Router (Legacy) → Uses pages/ directory and file-based routing (e.g.,
pages/index.js).
• App Router (Recommended) → Uses app/ directory and introduces React Server
Components for improved performance.
• Yes → The project is set up with App Router (app/ directory), supporting
modern features like Server Actions and Streaming.
• No → Uses the older Pages Router (pages/ directory).
📌 Effect: Choosing App Router enables the latest Next.js features and
optimizations.
--------------------------------------------------------------------------------
7. Would you like to use Turbopack for next dev? (No / Yes)
Turbopack [https://turbo.build/pack] is Next.js’ new Rust-based bundler that
replaces Webpack for local development.
• Yes → Uses Turbopack, which provides faster startup and hot reloading times.
• No → Uses Webpack instead, which is more stable but slower.
📌 Effect: Choosing Turbopack makes development faster but is still in progress
for some features.
--------------------------------------------------------------------------------
8. Would you like to customize the import alias (@/* by default)? (No / Yes)
Next.js allows you to use import aliases to make importing files easier. By
default, it uses:
import Button from '@/components/Button';
Instead of:
import Button from '../../components/Button';
• Yes → You can define a custom alias (e.g., ~/ instead of @/).
• No → Uses the default alias @/.
📌 Effect: Helps with cleaner imports, especially in large projects.
--------------------------------------------------------------------------------
9. What import alias would you like configured? (Default: @/*)
If you chose “Yes” in the previous question, you can customize the alias.
• Example: Entering ~/ would let you do:
import Button from '~/components/Button';
📌 Effect: Creates a tsconfig.json or jsconfig.json file with a custom alias
setting.
--------------------------------------------------------------------------------
Final Thoughts
These options let you tailor your Next.js project based on your preferences and
needs. If you’re new to Next.js, using the recommended defaults (TypeScript,
ESLint, Tailwind, App Router) is a great way to get started with modern best
practices. 🚀
FOLDER STRUCTURE
Next.js follows a convention-based folder structure that helps organize your
project efficiently. Depending on whether you use the App Router (app/
directory) or Pages Router (pages/ directory), the structure will differ
slightly. We will focus on app router only
Introduced in Next.js 13, the App Router uses React Server Components by default
and enables powerful features like layouts, streaming, and server actions.
/my-next-app
├── /app
│ ├── /layout.tsx
│ ├── /page.tsx
│ ├── /dashboard
│ │ ├── /page.tsx
│ │ ├── /settings
│ │ │ ├── /page.tsx
│ ├── /api
│ │ ├── /route.ts
├── /components
├── /lib
├── /public
├── /styles
├── /utils
├── /node_modules
├── .gitignore
├── next.config.js
├── package.json
├── tsconfig.json
Key Folders & Files in app/ Directory
• app/ → The main folder where pages, layouts, and API routes live.
• app/layout.tsx → Defines the root layout for the application (persists
across all pages).
• app/page.tsx → The default home page (/).
• app/dashboard/page.tsx → A route for /dashboard.
• app/dashboard/settings/page.tsx → A nested route for
/dashboard/settings.
• app/api/route.ts → Defines API endpoints (e.g., /api).
📌 APP ROUTER BENEFITS:
✅ USES REACT SERVER COMPONENTS FOR BETTER PERFORMANCE.
✅ SUPPORTS NESTED LAYOUTS AND LOADING STATES.
✅ ENABLES STREAMING AND SERVER-SIDE RENDERING (SSR) BY DEFAULT.
RUNNING THE PROJECT
To run the Next.js project, please run the following command in the web project
directory
pnpm run
This starts the development server at http://localhost:3000
[http://localhost:3000]. If you are running multiple applications, the port may
change and you may see the following message:
$ pnpm dev
> my-test-project@0.1.0 dev /Users/30031005/Github/WSU/FSD/my-test-project
> next dev --turbopack
⚠ Port 3000 is in use, trying 3001 instead.
▲ Next.js 15.1.7 (Turbopack)
- Local: http://localhost:3001
- Network: http://192.168.1.184:3001
In this case I would open the project at the following URL:
http://localhost:3001 [http://localhost:3000]. When you open the browser at that
URL, you should see the following:
[https://skillpies.s3.ap-southeast-2.amazonaws.com/courses/full-stack-development-comp3036-2025/sections/next-js-introduction-in-next-js-backend/Screenshot%202025-02-13%20at%2014.48.10.png]
OUR (MONOREPO) PROJECT
In this chapter we will be working in the same code base from your second
assignment. To learn how to set it up, please follow instructions here
[/course/full-stack-development-comp3036-2025/assignment-2-1-blog-client-in-advanced-react]:.
We recommend you to create a new “Lecture” branch to play with exercises in the
lecture.
Maggie is a generative AI that can help you understand the course content better. You can ask her questions about the lecture, and she will try to answer them. You can also see the questions asked by other students and her responses.
Join the discussion to ask questions, share your thoughts, and discuss with other learners