Stage 5 track

Track: E-commerce at scale

Capstone: QuickCart Pro · Builds on: Stage 4's QuickCart, Part 17, Part 18 · Time: ~15–20 h (one milestone every 2–3 days, ~2 hours a day)

🚧 Brief, not a built capstone. This is a short, focused plan — the same kind of brief the sibling Python and React courses write for their own Stage 5 tracks — not a full Part 1–18-style lesson with its own examples//exercises.md/solutions/. Nothing below was built, run, or verified while writing this brief. Parts 1–18's own lessons (including Parts 17/18, which this document links to constantly) were all built and verified for real against this course's harness; QuickCart Pro itself was not. See "What this brief does not claim" at the bottom before treating anything here as tested.

Who this track is for

You finished Stage 4's QuickCart and Parts 17–18, and you want to go deep on the specific problems a real storefront has that QuickCart's teaching-sized capstone deliberately left out: searching a catalog instead of browsing all of it, paginating instead of loading everything at once, a checkout flow that models payment without actually integrating a payment provider (no account, no API key — this course's "works fully offline" rule, same as every dependency choice DESIGN-NOTES.md/TOOLING.md already made), and letting a signed-in shopper see their own order history.

Job roles this maps to: Frontend/Full-stack Engineer on a commerce or marketplace team, the kind of role where "add server-side search with pagination to a product catalog" or "add an order-history page gated behind auth" is a normal sprint ticket, not a special project.

You already have, from earlier stages:

  • Server Components, Client Components, and the Server/Client boundary (Stage 2)
  • "use cache", cacheTag/cacheLife, revalidateTag/updateTag (Stage 3, Parts 10–11)
  • Server Actions and forms, including the "every Server Action is a public POST endpoint" rule (Part 12)
  • Route Handlers, proxy.ts, the iron-session auth pattern (requireUser/getCurrentUser), and better-sqlite3 with a hand-written data-access layer (Stage 4, Parts 13–16)
  • QuickCart itself: products, cart, checkout gated behind auth, an order placed via a real db.transaction(...) (Stage 4 capstone)
  • A real Vitest + Testing Library setup, including what's and isn't testable in Server Components land (Part 17)
  • output: "standalone", environment variables in production, and instrumentation.ts (Part 18)

What you'll learn, step by step

Step 1 — Search and filtering

Builds on: Part 9 (Server Components reading data), Part 16 (the better-sqlite3 data-access layer).

  • Add a search box that filters QuickCart Pro's product catalog by name/description, implemented as a SQL WHERE ... LIKE (or SQLite's FTS5 full-text search extension, if you want to go further) inside the existing products DAL — not a client-side .filter() over every product, which stops working the moment the catalog is larger than one page.
  • Read the search term from the URL (searchParams, a Server Component prop) so a search result is a real, shareable, bookmarkable link — not client-only state that resets on refresh.
  • Add at least one real filter (price range, in-stock only) alongside free-text search, composed in the same WHERE clause.

Step 2 — Pagination

Builds on: Step 1's search/filter query, Part 11 (on-demand revalidation).

  • Paginate the (now filtered) product list with LIMIT/OFFSET in the same DAL function, not by fetching everything and slicing it in JavaScript.
  • Carry the current page number in the URL (another searchParams read) so pagination composes correctly with search/filtering — paging to page 2 of a search result must still be a real, shareable link.
  • Decide, and be able to explain, whether the product-list query should use "use cache" at all once it depends on searchParams — Part 15's "cookies()/headers()/searchParams need use cache: private, not plain use cache" rule applies here too, not just to an authenticated session read.

Step 3 — A mocked payment-gateway pattern

Builds on: Part 12 (Server Actions), the real placeOrder transaction in QuickCart's lib/orders.ts.

  • Add a lib/payments.ts module with a function shaped like a real payment provider's API (createPaymentIntent(amountCents) → returns a fake client secret / confirmation id; confirmPayment(id) → returns "succeeded" or "failed", with a configurable failure rate so the failure path is actually exercisable) — but backed by nothing except this module's own logic. No account, no API key, no network call to any real payment provider, matching this course's existing dependency-selection rule.
  • Wire it into the checkout Server Action so a failed "payment" leaves the cart untouched and shows a real error, and a successful one proceeds into the exact same db.transaction(...) order-placement path QuickCart's capstone already built — the mocked gateway should feel like a seam you could swap a real provider's SDK into later, not a parallel checkout path.

Step 4 — Order history

Builds on: Part 15 (requireUser), the existing orders/order_items tables from Stage 4.

  • Add a /orders page, gated behind auth the same way checkout already is (both the DAL-level requireUser() call inside the page and the optimistic proxy.ts check — Part 15 section 4's central finding about why the DAL check is the one that actually matters, not just the proxy's).
  • List only the signed-in user's own orders (WHERE user_id = ?, not every order in the table) — the same "scope every query to the authenticated user, inside the DAL, every time" discipline the SaaS dashboard track's role-gating depends on too.
  • Link each order to an order-detail view reusing QuickCart's existing orders/[id] page/Route Handler.

Step 5 — Testing and deployment pass

Builds on: Part 17, Part 18, in full.

  • Extend Part 17's real Vitest setup to cover the new search/pagination DAL function and the mocked payment module directly (both are plain, dependency-light functions — Part 17 section 4's easiest case).
  • Re-run Part 18's local verification pass (output: "standalone", the .env.local/SESSION_PASSWORD check, instrumentation.ts) against QuickCart Pro specifically, not just the original capstone — confirm the SQLite build-time-snapshot finding (Part 18 section 4) still applies to whatever new tables this track added.

Step 6 — Polish (buffer)

Finish any rough edges in the search/pagination UI, write the project's own README (goal, routes, how to run it), and attempt a stretch goal.

Setup pointers (official docs only)

Topic Official docs
SQLite full-text search (optional, Step 1) https://www.sqlite.org/fts5.html
searchParams in Server Components https://nextjs.org/docs/app/api-reference/file-conventions/page (searchParams prop)
"use cache: private" the installed use-cache-private.md reference this course already cited in Part 15

Don't hard-code a package version from memory — if you add anything beyond this harness's existing dependencies, check its current latest dist-tag and whether it's genuinely stable the same way DESIGN-NOTES.md/TOOLING.md already checked better-sqlite3, iron-session, and Vitest for this course.

Capstone brief: QuickCart Pro

User stories

  • As a shopper, I can search the catalog by name and get a real, bookmarkable results URL.
  • As a shopper, I can page through a large result set instead of loading everything at once.
  • As a shopper, a failed "payment" at checkout leaves my cart intact and shows a clear error, not a crash or a silently-placed order.
  • As a signed-in shopper, I can see a list of my own past orders, and open any one of them — and never anyone else's.
  • As a developer, the new search/filter/pagination query and the mocked payment module both have real, passing Vitest tests.

Architecture sketch

  GET /quickcart?q=mango&page=2
        │
        ▼
┌─────────────────────────────┐
│ app/quickcart/page.tsx      │  reads searchParams (q, page), Server Component
└──────────────┬───────────────┘
               │ calls
               ▼
┌─────────────────────────────┐
│ lib/products.ts             │  searchProducts(query, page) — one WHERE/LIMIT/OFFSET
│                              │  query, Stage 4's existing DAL convention extended
└──────────────┬───────────────┘
               ▼
          products.sqlite (Stage 4's existing database, unchanged schema otherwise)

  POST /quickcart/checkout (Server Action)
        │
        ▼
┌─────────────────────────────┐      ┌─────────────────────────────┐
│ lib/payments.ts (new, mock) │─────▶│ lib/orders.ts (existing      │
│ createPaymentIntent/confirm │      │ db.transaction(...) path)    │
└─────────────────────────────┘      └─────────────────────────────┘

This keeps Stage 4's existing layering intact (routes/actions → DAL → database) and adds exactly one new DAL-shaped module (payments.ts) rather than threading payment logic through the Server Action directly — the same "the database layer is the only place that touches the database" discipline Stage 4's own capstone and the Python course's web-backend track both already use.

Milestones

  1. Search — searchProducts(query) replaces the plain listProducts() call on the main catalog page; a real search term produces a real, narrowed, bookmarkable URL.
  2. Pagination — the same query gains LIMIT/OFFSET, driven by a page URL param, composing correctly with an active search term.
  3. Mocked payments — lib/payments.ts exists, checkout calls it, and both the success and failure paths are reachable and show correct UI.
  4. Order history — /orders lists only the signed-in user's own orders, gated the same way checkout is.
  5. Tests — Vitest tests cover searchProducts (at least: a real match, no match, and pagination past the last page) and lib/payments.ts's mocked failure path.
  6. Deployment pass — Part 18's local-only verification steps re-run against this extended app, with any new finding documented the same honest way Part 18 itself does.

Acceptance checklist

  • A search for a real product name returns only matching products, via a server-side query, not a client-side filter
  • Paging past the last page returns an empty (not crashing) result, and page 1 of a search still composes correctly with the search term
  • A mocked payment failure leaves the cart unchanged and shows a real error message
  • A mocked payment success places a real order through the existing db.transaction(...) path
  • /orders never shows another user's orders, verified by checking the DAL query's WHERE clause and by testing with two different signed-in users
  • npm run lint && npm run typecheck && npm run test && npm run build all exit 0 against the extended app

Stretch goals

  • 🟡 Sort order list and product search results (price, newest first).
  • 🟡 A "recently viewed" strip, backed by a real cookie or a signed-in user's own history table — not localStorage alone.
  • 🔴 SQLite FTS5 full-text search instead of LIKE, with a real ranking comparison between the two on a larger seeded catalog.
  • 🔴 A second, independent mocked-gateway failure mode (e.g. a timeout, not just a declined payment) and a retry affordance in the UI.

How you'll know you're done

  • Every item in the acceptance checklist above is ticked
  • You can explain, out loud, why the search/pagination query lives in the DAL and not in a Server Component's own JavaScript
  • You can explain why the mocked payment module is a believable stand-in for a real provider's API shape, and what specifically you'd have to change to swap a real one in
  • You re-ran Part 17's and Part 18's own verification steps against this extended app and can point at real, current output for each

What this brief does not claim

No code for QuickCart Pro — no search query, no pagination, no mocked payment module, no order-history page — was written, run, or tested while writing this brief, unlike Parts 1–18 (including Parts 17 and 18, linked throughout this document), where every snippet was built and verified for real against this course's harness and every claim traces to captured output. Treat every detail above as a design-time plan, not a tested lesson, until a learner (or a future content wave) actually builds it and replaces this section with real, run results — the same honesty rule TOOLING.md states for this entire repo.

Search the guide