Mastering Next.js 14+ with TypeScript & src/
Structure
Welcome to the first step of your journey in mastering Next.js 14+ β the most advanced and flexible React framework out there. In this module, we’ll cover what makes Next.js 14 so powerful, how it compares to other tools, and how to set up a modern project using TypeScript and the new
src/ directory layout.
π What is Next.js 14 β and Why Should You Care?
Next.js 14 is a React framework built by Vercel that enables you to create full-stack web apps with:
- Server components and client components
- Server-side rendering (SSR), static generation (SSG), and incremental rendering (ISR)
- API routes and server actions
- File-based routing with App Router
- Automatic image optimization, metadata handling, and much more
It replaces the traditional βfrontend-onlyβ mindset with a full-stack developer experience, without having to leave the React ecosystem.
βοΈ Next.js vs CRA vs Gatsby
Hereβs how Next.js 14 compares to Create React App (CRA) and Gatsby:
Feature | Next.js 14 | Create React App (CRA) | Gatsby |
---|---|---|---|
Server-side rendering | β Built-in | β Not supported | β οΈ Limited |
API routes | β Built-in | β External only | β Needs plugins |
File-based routing | β With App Router | β Manual setup | β Pages directory |
Performance | β‘ Optimized SSR/SSG | π’ Basic SPA only | β‘ SSG only |
Backend integration | β Native (API/DB) | β Requires external | β οΈ Plugin-based |
Recommended use case | Universal web apps | Frontend-only apps | Static sites, blogs |
β Verdict: If you’re serious about building production-ready apps with modern architecture, Next.js 14 is the clear winner.
π οΈ Installing the Prerequisites
β Install Node.js
Download and install the LTS version from https://nodejs.org. This includes:
node
: JavaScript runtimenpm
: Node package manager
To check versions:
node -v
npm -v
β Install VS Code
VS Code is the preferred editor for React and Next.js developers.
Download it from https://code.visualstudio.com and install these extensions:
- ESLint
- Prettier
- Tailwind CSS IntelliSense
- TypeScript React Support
π§± Creating Your Next.js 14 Project with TypeScript and src/
Use the official command-line tool to scaffold your app:
npx create-next-app@latest
Answer the prompts as follows:
- Project Name:
next14-ts-app
(or any name you like) - Use TypeScript? β Yes
- Use App Router? β Yes
- Use Tailwind CSS? β Yes
- Use
src/ directory? β Yes - Import alias? π Yes (
@/*
is recommended) - Use ESLint/Prettier? β Yes (Optional but useful)
Once done:
cd next14-ts-app
npm run dev
Visit http://localhost:3000 and boom β your app is live!
ποΈ Project Structure with src/
After choosing the src/
layout, your project structure will look like this:
next14-ts-app/
βββ public/ β Static files (images, favicon)
βββ src/
β βββ app/ β App Router pages, layouts, templates
β β βββ page.tsx β Homepage
β βββ components/ β Reusable UI components
β βββ styles/ β Tailwind + global styles
β βββ lib/ β Utility functions or DB logic (optional)
β βββ types/ β TypeScript types (optional)
β βββ app/layout.tsx β Root layout
βββ tailwind.config.ts β Tailwind setup
βββ tsconfig.json β TypeScript settings
βββ next.config.js β Next.js configuration
π Setting Up Tailwind CSS (If Skipped)
If you didnβt enable Tailwind CSS during setup, install it manually:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Then configure your tailwind.config.ts
:
content: [
"./src/**/*.{js,ts,jsx,tsx}",
]
And include Tailwind in your global stylesheet (src/app/globals.css
):
@tailwind base;
@tailwind components;
@tailwind utilities;
Import globals.css
in src/app/layout.tsx
:
import './globals.css';
π§ͺ TypeScript Is Fully Integrated
By default, your project is now written in TypeScript β a must-have for production-level React apps. Benefits include:
- Static type checking
- Better autocompletion and tooling
- Cleaner, safer code
Example component:
type Props = {
title: string;
}
const Heading = ({ title }: Props) => (
<h1 className="text-2xl font-bold">{title}</h1>
);
export default Heading;
β Summary: Youβre Ready to Build
By the end of Module 1, you have:
- Understood why Next.js 14 is the future of React
- Compared it with CRA and Gatsby
- Installed Node, VS Code, and useful extensions
- Created a project using TypeScript + App Router + Tailwind
- Adopted the modern
src/ folder structure
π Youβre now fully set up for modern full-stack web development!
π Up Next:
In Module 2, weβll explore Routing & Navigation β from file-based routes to dynamic segments and shared layouts.
Want the blog version in Markdown or HTML export as well?