Project: plan and setup
Before writing any code for a full-stack app, you plan it: requirements, MVP scope, routes, folder structure and the data model. This module starts CourseHub (a course app built across three videos) and ends with the home page reading courses from Postgres via Prisma.
71.1 Why is it used?
- Coding without a plan: halfway you remember login and an enrollment table, so the schema and pages change again.
- Without a plan the project gets rewritten again and again.
- Real developers spend about 20 minutes planning first, then write code.
- A plan fixes what to build (and what not to build) before any file exists.
- Step 1
1.Direct coding: no plan
- Step 2
2.New feature halfway: login, enrollment
- Step 3
3.Rewrite: schema + pages again
- Step 4
4.Fix: a 20 minute plan first
71.2 Requirements and MVP scope
Requirements = what a user can do in the app. The MVP (minimum viable product) is the smallest product that works completely.
| In scope (MVP) | Out of scope |
|---|---|
| Home: course list | Payment gateway |
| Course detail page | Video player |
| Sign up and log in | Admin panel |
| Enroll button | Adding courses from UI (courses come from a seed script) |
| Dashboard: my courses | - |
- A small working app is always better than a big incomplete one.
71.3 Routes: the user journey
- Step 1
1./ : home, course list
- Step 2
2./courses/[slug] : detail + Enroll
- Step 3
3./login, /signup : Better Auth
- Step 4
4./dashboard : protected, my courses
Today: home page. Next video: the rest
71.4 Tech stack
| Need | Tool |
|---|---|
| Framework + language | Next.js 16 + TypeScript |
| Styling | Tailwind CSS v4 |
| Database + ORM | PostgreSQL + Prisma |
| Authentication | Better Auth |
| Validation | Zod |
| Deployment | Vercel |
- Only tools already learned in the course: no new tool just for the project.
71.5 Project setup
npx create-next-app@latest coursehub --yescd coursehubnpm i @prisma/client @prisma/adapter-pgnpm i -D prisma tsx dotenvnpx prisma init$ npx create-next-app@latest coursehub --yesCreating a new Next.js app in ~/coursehub.Using npm.Initializing project with template: app-twSuccess! Created coursehub at ~/coursehub- --yes picks the defaults: TypeScript, Tailwind and the App Router.
- Lines 3-4 install the Prisma packages (client + pg adapter, CLI as dev dependency).
- prisma init creates the schema file and the .env file.
71.6 Folder structure
coursehub/├─ app/│ ├─ page.tsx│ ├─ courses/[slug]/page.tsx│ ├─ login/page.tsx│ ├─ signup/page.tsx│ ├─ dashboard/page.tsx│ └─ api/auth/[...all]/route.ts├─ components/CourseCard.tsx├─ lib/│ ├─ db.ts│ ├─ courses.ts│ └─ auth.ts├─ prisma/schema.prisma└─ .env- app/: every route has its own page.tsx; courses/[slug] is a dynamic route.
- components/: UI pieces like CourseCard.
- lib/: all database and auth logic, so pages stay simple.
- prisma/: the schema. The structure is fixed from day one.
71.7 Data model with Prisma
model Course { id Int @id @default(autoincrement()) slug String @unique title String description String level String price Int lessons Int enrollments Enrollment[]}model Enrollment { id Int @id @default(autoincrement()) userId String courseId Int course Course @relation(fields: [courseId], references: [id]) createdAt DateTime @default(now()) @@unique([userId, courseId])}- slug is @unique because it goes into the URL (e.g. react-19).
- price is an Int in whole rupees; format it only at display time.
- One course has many enrollments (Enrollment[]).
- userId is a String because Better Auth creates users (next video).
- @@unique([userId, courseId]): one user can enroll in a course only once, enforced by the database.
71.8 Local database, migrate and seed
npx prisma dev --detachnpx prisma migrate dev --name initnpx prisma generatenpx prisma db seed$ npx prisma dev --detachpostgres://postgres:postgres@localhost:51221/template1?sslmode=disable$ npx prisma migrate dev --name initApplying migration `20261106100331_init`Your database is now in sync with your schema.$ npx prisma generate✔ Generated Prisma Client (7.10.1) to .\app\generated\prisma in 76ms$ npx prisma db seedSeeded 3 courses- Step 1
1.prisma dev: local Postgres starts, prints a URL
- Step 2
2.Paste the URL into .env as DATABASE_URL
- Step 3
3.migrate dev --name init: creates the tables
- Step 4
4.prisma generate: type-safe Prisma client
- Step 5
5.db seed: adds 3 courses
71.9 getCourses with use cache
import { cacheLife, cacheTag } from "next/cache";import { db } from "./db"; export async function getCourses() { "use cache"; cacheLife("hours"); cacheTag("courses"); return db.course.findMany({ orderBy: { price: "asc" }, select: { slug: true, title: true, level: true, price: true, lessons: true, }, });}- lib/db.ts is the same Prisma singleton from the database video.
- The template turns on cache components, so an uncached query fails the build: "use cache" is required.
- cacheLife("hours") sets how long it stays fresh; cacheTag("courses") lets you revalidate it later.
- select brings only the fields the card needs.
71.10 Home page (server component)
import { getCourses } from "@/lib/courses";import { CourseCard } from "@/components/CourseCard";export default async function HomePage() { const courses = await getCourses(); return ( <main className="mx-auto max-w-3xl p-6"> <h1 className="text-2xl font-bold">CourseHub</h1> <div className="mt-6 grid gap-4 sm:grid-cols-2"> {courses.map((c) => ( <CourseCard key={c.slug} {...c} /> ))} </div> </main> );}# CourseHubJavaScript BasicsBeginner · 24 lessons₹499React 19 CompleteIntermediate · 40 lessons₹999Next.js 16 Full-StackAdvanced · 36 lessons₹1,499- Async server component: awaits getCourses directly, no useEffect or API route.
- Courses appear sorted by price; clicking a card gives a 404 for now (detail page comes next video).
71.11 Checkpoint: double click on Enroll
import { db } from "@/lib/db"; const data = { userId: "u1", courseId: 2 }; await db.enrollment.create({ data });try { await db.enrollment.create({ data });} catch (e: any) { console.log(e.code);}console.log(await db.enrollment.count());> P2002> 1- Only one row exists because (userId, courseId) is unique.
- The second create fails with Prisma error code P2002 (unique constraint violation).
- Next video turns P2002 into an "Already enrolled" message.
71.12 Common mistakes
model Course { id Int @id @default(autoincrement()) title String price String // "₹1,499"}const inr = new Intl.NumberFormat("en-IN", { style: "currency", currency: "INR", maximumFractionDigits: 0,}); export function formatPrice(rupees: number) { return inr.format(rupees);}- Wrong: price as a String with the rupee sign. Strings sort character by character, so the order becomes ₹1,499, ₹499, ₹999.
- Right: price as an Int (1499) and formatPrice only at display time -> ₹1,499.
- Misconception: a full-stack app needs a separate Express backend. Reads run in server components, writes in server actions; route handlers are enough even for a mobile app.
71.13 Best practices
- Finish the MVP first, add extras later.
- Keep all DB code in lib/ so pages stay simple and testing is easy.
- Secrets only in .env, and .env is in .gitignore.
- Make a git commit after every working feature.
71.14 Interview tips
- "How would you plan a new full-stack project?": requirements first, then fix the MVP scope and what is out of scope.
- Turn the user journey into routes and the entities into a data model.
- Put constraints like unique at the database level, not only in app code (it survives races like double clicks).
- Fix the folder structure and stack, then build each feature end to end (DB -> lib -> UI).