Week 3 — Next.js Getting Started
Build App Router foundations while keeping Nest as the owner of the product API — then ship a Next blog/dashboard mini-project.
- 1. Install and run Next.jsOpen
Start by running the web application that already exists in this workspace instead of creating a second app.
- 2. Understand project structureOpen
A predictable tree lets you trace an Course screen from its URL to its route component and supporting code.
- 3. Use layouts and pagesOpen
Choose the file that owns UI so navigation, providers, and page-specific data do not become tangled.
- 4. Link and navigateOpen
Navigation should preserve the app experience while retaining normal browser behavior for external destinations.
- 5. Choose Server and Client ComponentsOpen
The boundary controls bundle size, available APIs, and whether code can safely access server-only values.
- 6. Fetch data in Next.jsOpen
Fetching strategy follows rendering and ownership requirements, not a desire to replace the product API.
- 7. Mutate data safelyOpen
Interactive product writes use Nest endpoints and TanStack Query mutations in this monorepo.
- 8. Understand cachingOpen
Next server caches and TanStack Query’s browser cache solve different problems and must not be confused.
- 9. Revalidate stale dataOpen
The correct revalidation mechanism depends on which cache contains the stale representation.
- 10. Handle loading and errorsOpen
Route boundaries complement, rather than replace, request states inside interactive client components.
- 11. Style Next.js applicationsOpen
Style ownership should be as deliberate as component ownership so visual changes remain predictable and accessible.
- 12. Optimize imagesOpen
Image optimization improves loading experience, but it does not make untrusted remote hosts or misleading alt text safe.
- 13. Optimize fontsOpen
Typography affects readability and performance because late font swaps can move content after users begin reading.
- 14. Add metadata and Open Graph imagesOpen
Good metadata represents the current route accurately rather than repeating generic application copy.
- 15. Use Route Handlers without replacing NestOpen
Keeping ownership clear prevents ticket rules, authentication, and validation from drifting across two servers.
- 16. Use Next proxying carefullyOpen
Proxying can simplify a browser path, but it must preserve cookie, CORS, and error behavior intentionally.
- 17. Deploy Next.jsOpen
The deployed web app must communicate safely with the separately deployed Nest API without exposing secrets.
- 18. Upgrade Next.jsOpen
Next upgrades can affect rendering, routing, caching, and dependencies, so they need a focused and evidence-based change.
End-of-week mini-project · practice only
Next blog / dashboard shell
Host a small blog or dashboard in the Next App Router: layouts, Link nav, Server/Client boundaries, Nest-backed data with revalidation, image/font/metadata optimization.
Definition
A Next App Router app that applies the full Week 3 surface — layouts and pages, navigation, Server vs Client Components, data fetching and caching/revalidation, loading/error boundaries, and image/font/metadata optimization — while Nest stays the product API owner.
In simpler words
Build routes and layouts in Next. Interactive lists/forms stay in Client Components. Data still comes from Nest, and writes go back to Nest — Next just renders and revalidates.
Concepts covered this week
- Install and run Next.js
- Scaffold with create-next-app (App Router) and run the dev server.
- Understand project structure
- Organize routes under app/ with colocated components and route groups.
- Layouts and pages
- A root layout plus a nested section layout wrap the blog/dashboard pages.
- Link and navigate
- next/link nav with active styling and no full page reloads.
- Server vs Client Components
- Server components render the shell; a Client Component owns the interactive list/form.
- Fetch data in Next.js
- A Server Component fetches the feed from the Nest API.
- Mutate data safely
- A Server Action (or client mutation) forwards writes to Nest, which stays the API owner.
- Understand caching
- Choose force-cache vs no-store for the feed and justify the choice.
- Revalidate stale data
- revalidatePath/revalidateTag (or time-based) refreshes the list after a write.
- Handle loading and errors
- loading.tsx and error.tsx provide route-level boundaries.
- Style Next.js applications
- CSS Modules for components plus a small global stylesheet.
- Optimize images
- next/image renders cover images with sizing and lazy loading.
- Optimize fonts
- next/font loads a self-hosted font without layout shift.
- Metadata & Open Graph
- generateMetadata sets titles and an OG image on detail pages.
- Route Handlers without replacing Nest
- A thin route handler serves health/OG only; product CRUD stays on Nest.
- Proxy carefully
- Any proxy keeps auth cookies and avoids duplicating business logic.
- Deploy & upgrade Next.js
- A production build with deploy notes and the Next upgrade/codemod path.
Deliverables
- App Router routes: /blog + /blog/[slug] (or /dashboard + a detail route) with a root and nested layout
- A Server Component shell composing a Client Component list/form; providers only on the client subtree
- Nest-backed data via a server fetch; a Server Action (or client mutation) for writes with revalidation
- loading.tsx + error.tsx boundaries; next/image, next/font, and per-page metadata + OG
- At most a thin Route Handler for health/OG — no product CRUD in Next
Build guide
- Scaffold + structurecreate-next-app, then lay out app/ routes with a root layout and a nested section layout.
- Build navigationAdd next/link nav with active states between the list and detail routes.
- Draw the boundaryKeep the page a Server Component and push interactivity into a Client Component leaf; place providers there.
- Fetch from NestLoad the feed in the Server Component from the Nest API and pick a caching mode deliberately.
- Mutate + revalidateSend writes to Nest via a Server Action or client mutation, then revalidate the list.
- Add boundaries + metadataAdd loading.tsx/error.tsx and generateMetadata with an OG image on detail pages.
- Optimize + shipSwap in next/image and next/font, run a production build, and note the deploy/upgrade steps.
Acceptance checklist
- [ ] use client only on interactive leaves + the providers module
- [ ] Data fetched in a Server Component; the write path revalidates the list
- [ ] Internal nav uses next/link; at least one dynamic segment
- [ ] loading.tsx + error.tsx boundaries present
- [ ] next/image + next/font + per-page metadata/OG in place
- [ ] Nest remains API owner (no product CRUD in Route Handlers)Stretch goals
- Add tag/category filtering with searchParams-driven server fetching.
- Stream the slow part of the dashboard with Suspense.
- Generate dynamic OG images per post.
Tips
- Reuse Week 2 Query patterns inside Client Components — do not invent a second data layer.
- The official Learn Next.js path under /resources complements this brief.
- Keep secrets and JWT handling on Nest; the browser only sends cookies.