Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Project

Recipe Box

Start after Part 8

Stage 2

Goal: Build a content-focused recipe site that proves the Server/Client boundary in a real app, not just in isolated snippets — recipe pages are Server Components with zero client-side JavaScript of their own, two small Client Component islands prove exactly where interactivity belongs, and a "related recipes" widget streams in behind a <Suspense> boundary without blocking the page. Time: ~8 h · Uses: Parts 1–8 only (file-based routing, layouts, metadata, Server/Client Components, streaming, rendering philosophy) — no Server Actions, no Route Handlers, no database. Those are Stage 3–4 territory.

Project brief

A small home-cooking site, Recipe Box: a list of Indian recipes, a detail page per recipe with a serving-size stepper that scales every ingredient, a "save this recipe" button, a collapsible method section, a related-recipes widget that streams in a beat after the rest of the page, and a festive-collections page that leans on loading.tsx instead.

A real run against this project's data (the full transcript is in tests_manual.md):

$ curl -s http://localhost:PORT/recipes/butter-chicken | grep -o '<ul id="related-recipes">.*</ul>'
<ul id="related-recipes"><li><a href="/recipes/chole-bhature">Chole Bhature</a> — Punjab</li><li><a href="/recipes/palak-paneer">Palak Paneer</a> — Punjab</li></ul>

$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost:PORT/recipes/rajma-chawal
404

Files

File What it is
README.md This brief and the step-by-step build guide
rendering-notes.md The capstone's required written note: which files are Server vs Client Components, and why — backed by real build output
tests_manual.md Every curl/build-output check to run yourself, with the exact captured output
examples/ Numbered snapshot copies of the reference implementation (the live code is added to the shared harness — see "Implementation location" below)

How to run

This project adds routes to the course's one shared harness (Node 22, npm 11, Next.js 16.4.6 — see ../../TOOLING.md), under harness/app/recipes/. No separate install, no separate package.json.

cd ../../harness
npm run dev          # then open http://localhost:3000/recipes

or, to see the build-time rendering decisions this project is built to demonstrate:

cd ../../harness
npm run build        # read the route table — /recipes, /recipes/[slug], /recipes/collections
npm run start         # then curl against it, same as tests_manual.md

Implementation location

This course's convention (Parts 1–8) is one shared harness/ app: every part's mini-build lives at its own route inside it, with a numbered snapshot of the same code kept in that part's own examples/ folder. This project follows the identical pattern — Recipe Box is a real, additive route tree at harness/app/recipes/, not a separate app, and this project's own examples/ folder holds the same numbered-snapshot convention (plus the stream-observer script, Part 7's technique, adapted to this project's ids).

harness/app/recipes/
├── layout.tsx                      Part 3 — shared nav, nested metadata template
├── page.tsx                        Part 5 — recipe list, Server Component, zero client JS
├── lib/
│   ├── types.ts                    Plain shared types (Ingredient, Recipe, RecipeSummary)
│   ├── delay.ts                    Part 7's wait() helper, reused for this project's own simulated delays
│   ├── recipes.ts                  Part 5 — the data layer, "server-only", async reads
│   └── collections.ts              Part 5 — a second, slower data source for the collections page
├── _components/
│   ├── ServingSizeStepper.tsx      Part 6 — Client Component, serializable props, owns its own state
│   ├── SaveRecipeButton.tsx        Part 6 — Client Component, serializable props, owns its own state
│   ├── CookingStepsPanel.tsx       Part 6 — Client Component, children-slot composition
│   ├── CookingSteps.tsx            Part 6 — Server Component, passed as children, never imported by the panel
│   └── RelatedRecipes.tsx          Part 7 — async Server Component, always rendered inside a <Suspense>
├── [slug]/
│   └── page.tsx                    Part 2 — dynamic segment, generateStaticParams, notFound()
└── collections/
    ├── page.tsx                    Part 7 — a page with nothing worth showing before its one slow read resolves
    └── loading.tsx                 Part 7 — the file-based alternative to an inline <Suspense>

Features

Feature What it does
Recipe list (/recipes) Every recipe, Server Component, zero client-side JavaScript of its own — the project's zero-JS baseline
Recipe detail (/recipes/[slug]) A dynamic segment; six of seven recipes are prerendered at build time, the seventh works identically the first time it's requested
Serving-size stepper A Client Component that scales every ingredient's quantity client-side as you change the serving count, with no server round trip
Save recipe button A Client Component that receives only two strings as props and owns its own saved/unsaved state (persisted to localStorage, a plain browser API — no Stage 3/4 persistence involved)
Collapsible method section A Client Component (CookingStepsPanel) that toggles visibility of server-rendered content (CookingSteps) handed to it as children, never as an import
Related recipes An async Server Component with a genuine 900ms simulated delay, always inside a <Suspense> boundary, so it streams in after the rest of the page
Festive thali collections (/recipes/collections) A page with nothing worth showing before its one slow read resolves, so it uses loading.tsx instead of an inline boundary
An unlisted-but-real recipe kerala-fish-curry is deliberately left out of generateStaticParams — visiting it works anyway, dynamically, proving dynamicParams defaults to true
A truly unknown slug notFound() from inside the main (non-Suspense-wrapped, instant) lookup gives a real 404 — contrast with Part 8's PNR page, where the same call behind a slow Suspense boundary gave 200 + noindex

Which Parts each feature uses

Feature Skills Part
/recipes/[slug] as a dynamic segment, generateStaticParams, notFound() Dynamic segments, the build-time params list, programmatic 404 Part 2
harness/app/recipes/layout.tsx wrapping every route under /recipes in one nav Nested layouts, <Link> navigation Part 3
Static metadata on the list and collections pages; generateMetadata on the detail page; the layout's title.template Metadata API, title cascading across nested layouts Part 4
recipes.ts/collections.ts as async data-layer modules with import "server-only"; page.tsx/[slug]/page.tsx as async Server Components that await them directly Server Components by default, async components, server-only Part 5
ServingSizeStepper, SaveRecipeButton, CookingStepsPanel as "use client" leaf components receiving only serializable props; CookingSteps passed as children, never imported The "use client" boundary, serializable props, children-slot composition Part 6
<Suspense> around RelatedRecipes; loading.tsx on /recipes/collections Streaming, Suspense boundaries, the file-based loading.tsx shortcut Part 7
The build's own route table (○ /recipes, ◐ /recipes/[slug], ◐ /recipes/collections); the unlisted kerala-fish-curry slug; the real-404-vs-200-noindex contrast with Part 8's own PNR page Static vs dynamic as a component-level spectrum, reading ○/◐/ƒ Part 8

💡 No Server Actions, no Route Handlers, no database, no "use cache" — every one of those is a later stage. This project's whole point is proving Parts 1–8 are enough to ship something real: a page that chooses, component by component, whether to be static, streamed, or client-interactive.


Build it step by step

Build in small steps. Run npm run build (or npm run dev + a curl) after every step. Try each one yourself before opening the finished files under harness/app/recipes/.

Step 1: The data layer (Part 5)

What and why: decide the shape of a recipe before any page exists. Keep the types in their own file with no "server-only" import, so a later Client Component can still import just the type without any ambiguity about crossing the boundary.

// lib/types.ts
export type Ingredient = { name: string; quantity: number; unit: string };
export type RecipeSummary = { slug: string; name: string; region: string; prepMinutes: number; cookMinutes: number; prerendered: boolean };
export type Recipe = RecipeSummary & { baseServings: number; ingredients: Ingredient[]; steps: string[] };

lib/recipes.ts starts with import "server-only";, holds the actual recipe array, and exports getAllRecipes()/getRecipe(slug) — both async, but with no artificial delay: await Promise.resolve(); then return. Part 5, section 2's "going deeper" note found that cacheComponents: true rejects a bare timer during prerendering even if its value never changes — these two functions are read directly in page bodies with no <Suspense> around them, so they have to stay genuinely instant.

✅ Test: getRecipe("masala-dosa") resolves to a recipe named "Masala Dosa"; getRecipe("not-a-slug") resolves to null.

Step 2: The recipe list (Part 5)

What and why: the project's zero-client-JS baseline — a plain async Server Component, no <Suspense>, no Client Component anywhere in its tree.

// page.tsx
export default async function RecipesHomePage() {
  const recipes = await getAllRecipes();
  return (
    <main>
      <h1>Recipe Box</h1>
      <ul>{recipes.map((recipe) => <li key={recipe.slug}><Link href={`/recipes/${recipe.slug}`}>{recipe.name}</Link></li>)}</ul>
    </main>
  );
}

✅ Test: npm run build shows ○ /recipes in the route table — fully static, prerendered once.

Step 3: The dynamic detail route, minus interactivity (Part 2)

What and why: six of seven recipes get a build-time prerendered shell; the seventh (kerala-fish-curry) is held back on purpose.

// lib/recipes.ts
export function listedSlugs(): string[] {
  return recipes.filter((recipe) => recipe.prerendered).map((recipe) => recipe.slug);
}
// [slug]/page.tsx
export function generateStaticParams() {
  return listedSlugs().map((slug) => ({ slug }));
}

export default async function RecipePage({ params }: PageProps<"/recipes/[slug]">) {
  const { slug } = await params;
  const recipe = await getRecipe(slug);
  if (!recipe) notFound();
  return <main><h1>{recipe.name}</h1>{/* ingredients, steps, as plain text for now */}</main>;
}

✅ Test: curl http://localhost:PORT/recipes/masala-dosa shows the recipe; curl http://localhost:PORT/recipes/kerala-fish-curry also works (not in generateStaticParams, served dynamically instead); curl -o /dev/null -w "%{http_code}" http://localhost:PORT/recipes/not-a-real-slug returns 404.

Step 4: Metadata (Part 4)

What and why: a layout-level title template, a static title on the list/collections pages, and a data-dependent title on the detail page.

// layout.tsx
export const metadata: Metadata = { title: { template: "%s | Recipe Box", default: "Recipe Box" }, description: "..." };
// [slug]/page.tsx
export async function generateMetadata({ params }: PageProps<"/recipes/[slug]">): Promise<Metadata> {
  const { slug } = await params;
  const recipe = await getRecipe(slug);
  return recipe ? { title: recipe.name, description: `...` } : { title: "Recipe not found" };
}

✅ Test: curl http://localhost:PORT/recipes/masala-dosa | grep -o '<title>[^<]*</title>' → Masala Dosa | Recipe Box. See rendering-notes.md for a genuinely surprising result this step turned up on the list page itself.

Step 5: The serving-size stepper (Part 6)

What and why: the first Client Component island — owns its own useState, receives only a number and a plain array of plain objects as props.

// _components/ServingSizeStepper.tsx
"use client";
export function ServingSizeStepper({ baseServings, ingredients }: { baseServings: number; ingredients: Ingredient[] }) {
  const [servings, setServings] = useState(baseServings);
  const scale = servings / baseServings;
  return (/* stepper buttons + ingredients.map(scaled by `scale`) */);
}

✅ Test: on /recipes/masala-dosa (base servings 2), clicking + once shows 3 servings and every ingredient quantity scaled by 1.5×.

Step 6: The save button (Part 6)

What and why: a second, independent Client Component island, proving the boundary is per-leaf, not per-page.

// _components/SaveRecipeButton.tsx
"use client";
export function SaveRecipeButton({ slug, name }: { slug: string; name: string }) {
  const [saved, setSaved] = useState(false);
  // useEffect reads localStorage on mount; toggleSaved writes to it
  return <button onClick={toggleSaved} aria-pressed={saved}>{saved ? "♥ Saved" : `♡ Save ${name}`}</button>;
}

✅ Test: the server-rendered HTML always shows aria-pressed="false" and ♡ Save <name> on a fresh load — curl can confirm the starting state; the click itself is a real browser interaction curl can't exercise (same limitation Part 6 names for its own AddToCartCounter).

Step 7: The collapsible method section — children composition (Part 6)

What and why: CookingStepsPanel (Client Component) never imports CookingSteps (Server Component) — it only ever renders whatever children turns out to be.

// CookingSteps.tsx — plain Server Component
export function CookingSteps({ steps }: { steps: string[] }) {
  return <ol>{steps.map((step, i) => <li key={i}>{step}</li>)}</ol>;
}
// RecipePage
<CookingStepsPanel title="method">
  <CookingSteps steps={recipe.steps} />
</CookingStepsPanel>

✅ Test: curl http://localhost:PORT/recipes/masala-dosa | grep -c "Show" → 1 (aria-expanded="false" by default); see tests_manual.md for proof that the method's real text is already in the initial payload, before any click, the same way Part 6 proved it for ProductSpecs.

Step 8: Related recipes, streamed (Part 7)

What and why: the one genuinely slow read on this page (900ms simulated), always wrapped in its own <Suspense>.

// lib/recipes.ts
export async function getRelatedRecipes(slug: string): Promise<RecipeSummary[]> {
  await wait(900);
  // recipes sharing the same region, excluding this one
}
<Suspense fallback={<p id="related-fallback">Finding more {recipe.region} recipes…</p>}>
  <RelatedRecipes slug={recipe.slug} />
</Suspense>

✅ Test: run examples/08-stream-observer.mjs against /recipes/butter-chicken — the fallback ships in the first chunk, id="related-recipes" lands roughly 900ms later, in a separate chunk. Real output in tests_manual.md.

Step 9: Festive collections, with loading.tsx instead (Part 7)

What and why: this page has nothing worth showing before its one read resolves, so the file-based shortcut fits better than an inline boundary around nothing.

// lib/collections.ts
export async function getFestiveCollections(): Promise<FestiveCollection[]> {
  await wait(1100);
  return collections;
}

collections/loading.tsx — no import, no JSX reference anywhere — is the entire fix.

✅ Test: npm run build shows ◐ /recipes/collections; curl -D - http://localhost:PORT/recipes/collections shows Transfer-Encoding: chunked and takes roughly 1.1s to fully arrive.

Step 10: Read the build output (Part 8)

What and why: this project's whole point, made visible in one table.

$ npm run build
...
├ ○ /recipes
├   /recipes/[slug]
│ ├ ◐ /recipes/[slug]
│ ├ ◐ /recipes/masala-dosa
│ ├ ◐ /recipes/chole-bhature
│ └ ◐ [+4 more paths]
├ ◐ /recipes/collections

✅ Test: can you say, for each line, why it's ○ vs ◐? See rendering-notes.md for the full answer, written out.


Stretch goals

  • 🟢 Add a "Quick to make" badge (recipe takes 30 minutes or less total) computed on the server from prepMinutes + cookMinutes.
  • 🟢 Link each dish name in /recipes/collections to its matching recipe slug, when one exists (several dish names already match a recipe's name exactly).
  • 🟡 Add "use cache" to getRelatedRecipes with a short cacheLife, rebuild, and confirm the detail route's ◐ lines don't change shape but the data itself no longer re-runs every request (Part 8, section 5's exact proof-and-revert pattern — Stage 3 territory, try it only after finishing Stage 3).
  • 🟡 Add an error.tsx under [slug]/ and make getRelatedRecipes throw for one slug on purpose, reproducing Part 7, section 7's "the rest of the page survives, the status stays 200" finding against this project's own route.
  • 🔴 A category route, /recipes/region/[region], as a second dynamic segment reusing the same data layer — practice choosing between a second top-level dynamic folder and a search param.
  • 🔴 Persist "saved" recipes across devices — this needs a real backend (Server Actions or a database), which is explicitly Stage 3–4 territory; note why it can't be done with what Parts 1–8 teach, as the exercise.

Checklist

  • Recipe list and recipe detail pages are Server Components and ship no client-side JavaScript for their content — confirmed by diffing their chunk lists against a known pure-server page (Part 5/6's technique; real output in tests_manual.md).
  • At least one small Client Component island (ServingSizeStepper) is interactive without making the whole page a Client Component.
  • A "save this recipe" button is a Client Component that receives server-fetched data as props.
  • A "related recipes" section streams in behind a <Suspense> boundary with a visible fallback, without blocking the rest of the page — proven with a real byte-stream reader, not just curl.
  • A short written note (rendering-notes.md) correctly labels which files in this project are Server vs Client Components, and why.
  • I can explain, from the real build output, why /recipes is ○, /recipes/[slug] is ◐ for every listed slug, and /recipes/collections is also ◐ despite having no inline <Suspense> of its own.
  • I reproduced the real 404 for an unknown slug and can explain why it differs from Part 8's PNR page returning 200 + noindex for its own unknown case.

Next

🎉 Stage 2 done! Go back to the roadmap and start Stage 3: Data, Caching and Mutations.

Search the guide