Stage 5 track

Track: SaaS dashboard

Capstone: Ops Dashboard · Builds on: Stage 4's QuickCart, Part 15, 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, in the same style as the sibling Python and React courses' own Stage 5 track files — not a full Part-style lesson with its own examples//exercises.md/solutions/. Nothing below was built, run, or verified while writing this brief. Parts 1–18's lessons (including Parts 17/18, linked throughout) were all built and verified for real against this course's harness; the Ops Dashboard capstone itself was not. See "What this brief does not claim" at the bottom. Naming note: this harness already has an unrelated app/ops/ directory from Parts 9/10 (a loading.tsx streaming demo) — the Ops Dashboard capstone is a separate project built from this brief, not an extension of that lesson folder.

Who this track is for

You finished Stage 4's QuickCart and Parts 17–18, and the part of QuickCart you found most interesting wasn't the storefront — it was the admin screen (/quickcart/admin), the single requireUser() check gating it, and the caching strategy behind data that needs to look "live" without hammering the database on every request. You want to build the kind of internal tool a SaaS company's own support/ops team uses all day: role-gated views, data scoped per account, and a revalidation strategy that's actually been thought through rather than "cache nothing and hope."

Job roles this maps to: Frontend/Full-stack Engineer on an internal-tools or platform team — the role that owns admin dashboards, support consoles, and the access-control rules around them, rather than the customer-facing product itself.

You already have, from earlier stages:

  • The Server/Client boundary and Server Components reading data directly (Stage 2)
  • "use cache", cacheTag/cacheLife, revalidateTag vs. updateTag (Stage 3, Parts 10–11)
  • iron-session, the DAL pattern (getCurrentUser/requireUser), "use cache: private", and the central finding that a layout's own check doesn't protect the page it wraps (Part 15, in full)
  • proxy.ts's optimistic-check pattern layered on top of an authoritative DAL check (Part 15 section 5)
  • better-sqlite3 with a hand-written DAL, and a real db.transaction(...) (Part 16)
  • A real Vitest + Testing Library setup, and what's genuinely hard to unit-test in Server Components land (Part 17)
  • output: "standalone", environment variables and secrets in production, and instrumentation.ts's register()/onRequestError() hooks (Part 18)

What you'll learn, step by step

Step 1 — Roles, not just "logged in or not"

Builds on: Part 15's requireUser()/DAL pattern.

  • QuickCart's auth only ever asked "is someone signed in?" Add a role column ("admin" | "staff", or similar) to the users table and a requireRole(role) DAL function alongside the existing requireUser() — same shape, same "call it inside every page/action that needs it, not just a parent layout" rule Part 15 section 4 already proved with a real reproduced gap.
  • Build at least one view only an "admin" role can reach, and one both roles can reach, and verify (by hand, the way Part 15's own exercises did) that a "staff" user hitting the admin-only URL directly gets a real block, not just a hidden nav link.

Step 2 — Multi-tenant-style data scoping

Builds on: Step 1, QuickCart's existing orders/order_items tables.

  • Add an account_id (or org_id) column to the data this dashboard reports on, and make every DAL query that reads it take the current user's account id as a parameter — scoped at the SQL WHERE clause, inside the DAL, the same discipline the e-commerce track's order-history page uses for user_id.
  • Prove the scoping actually holds: seed two accounts with their own data, sign in as a user from account A, and confirm account B's rows never appear anywhere in the dashboard — not just on the main list view, but on any detail page reachable by guessing an id in the URL.

Step 3 — A deliberate revalidation strategy

Builds on: Part 10/11 (cacheLife, cacheTag, revalidateTag/updateTag), Part 16 section 6's synchronous-driver-under-Cache-Components gotcha.

  • Pick at least two dashboard views with genuinely different freshness needs (e.g. an "orders today" count that can tolerate being a minute stale vs. a "currently signed-in staff" list that should feel closer to live) and give each its own explicit cacheLife profile, not a single blanket caching choice copy-pasted everywhere.
  • Wire at least one on-demand invalidation (an admin action that should make a view "catch up" immediately — Part 11/12's updateTag read-your-own-writes pattern) and verify it with a real, timed before/after check, not just by eyeballing that it "feels" fresh.
  • Explicitly decide, and document in your own project's README, which views use "use cache" vs. "use cache: private" vs. no caching at all, and why — Part 15's rule about cookies()/headers()/searchParams needing the private variant applies to any dashboard view that's scoped to "the current logged-in user's own account," not just to an auth check specifically.

Step 4 — Charts

Builds on: Step 3's cached data.

  • Pick one real, lightweight charting approach (a small library, or hand-rolled SVG bars/sparklines if you'd rather not add a new dependency — check any library's latest npm dist-tag for genuine stability first, the same evidence standard DESIGN-NOTES.md already used) and render at least one real chart from this dashboard's own cached data, not placeholder numbers.
  • Make sure the chart's data-fetching respects Step 3's caching decisions — a chart that silently bypasses the page's own revalidation strategy (e.g. by client-fetching a Route Handler on an interval instead of reading the same cached Server Component data) is a trap worth noticing and avoiding deliberately, not by accident.

Step 5 — Testing and deployment pass

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

  • Extend Part 17's real Vitest setup to cover requireRole (both the allowed and denied paths) and the multi-tenant scoping DAL functions directly — both are the "easiest case" shape Part 17 section 4 already demonstrated (plain, dependency-light functions once server-only/env gotchas are handled the way vitest.config.mts already does).
  • Re-run Part 18's local verification pass against this dashboard specifically — in particular, re-check section 5's finding (a missing env var inside proxy.ts's import graph breaks every route, not just matched ones) against whatever new session/role data this track's proxy.ts changes now depend on.

Step 6 — Polish (buffer)

Finish the role-gating and scoping edges, write the project's own README, and attempt a stretch goal.

Setup pointers (official docs only)

Topic Official docs
cacheLife profiles the installed cacheLife reference this course already used in Parts 10/16
Charting (pick one, check its current stability first) whichever library you choose — read its own official docs, don't assume an API from memory

Capstone brief: Ops Dashboard

User stories

  • As staff, I can see today's order volume and a couple of other at-a-glance metrics, scoped to my own account.
  • As an admin, I can see an admin-only view staff cannot reach, even by guessing the URL.
  • As staff from account A, I never see account B's data anywhere, on any view, including a detail page reached by guessing an id.
  • As an admin, I can trigger an action that makes a specific view "catch up" immediately, instead of waiting out its normal cache lifetime.
  • As a developer, I can point at real passing tests for the role check and the account-scoping query.

Architecture sketch

  GET /dashboard/orders-today
        │
        ▼
┌─────────────────────────────┐
│ app/dashboard/.../page.tsx  │  requireUser() + requireRole() — both called
│                              │  HERE, not just in a parent layout (Part 15 §4)
└──────────────┬───────────────┘
               │ calls, with accountId from the current session
               ▼
┌─────────────────────────────┐
│ lib/metrics.ts (new)        │  "use cache" + cacheTag/cacheLife, scoped
│                              │  WHERE account_id = ? on every query
└──────────────┬───────────────┘
               ▼
          ops-dashboard.sqlite (new database, same better-sqlite3 + hand-written
          DAL convention as QuickCart's lib/products.ts etc.)

Milestones

  1. Roles — requireRole() exists; one admin-only view and one shared view both work and are both actually gated inside the page, not just a layout.
  2. Scoping — every dashboard query takes an account id and is proven, with two seeded accounts, to never leak cross-account.
  3. Revalidation strategy — at least two views with distinct cacheLife profiles, plus one working on-demand invalidation, documented in the project's own README.
  4. Charts — at least one real chart rendering this dashboard's own cached data.
  5. Tests — Vitest tests cover requireRole's allow/deny paths and the account-scoping query's isolation.
  6. Deployment pass — Part 18's local-only checks re-run against this app, any new finding documented honestly.

Acceptance checklist

  • A "staff" user hitting an admin-only URL directly is blocked by the page/DAL itself, not just a hidden nav link
  • Two seeded accounts' data never cross-leak on any view, including a guessed-id detail page
  • At least two views have explicit, different cacheLife profiles, documented with a stated reason for each
  • One on-demand invalidation is wired and verified with a real timed before/after check
  • At least one chart renders real cached data, not placeholder numbers
  • npm run lint && npm run typecheck && npm run test && npm run build all exit 0

Stretch goals

  • 🟡 A "viewer" role that can see dashboards but trigger no actions at all (three roles, not two).
  • 🟡 A simple audit log of who triggered which on-demand invalidation and when.
  • 🔴 A custom cache handler (per the installed self-hosting.md guide Part 18 section 7 already names) so this dashboard's cache would actually coordinate across more than one process — build it, but don't claim it's verified multi-instance unless you genuinely run more than one process and check, the same honesty standard Part 18 itself holds to.
  • 🔴 Server-sent updates (polling a Route Handler, or a real streaming approach) for the "closer to live" metric from Step 3, measured against the plain cached version for actual staleness difference.

How you'll know you're done

  • Every item in the acceptance checklist above is ticked
  • You can explain, out loud, why requireRole() has to be called inside every gated page/action itself, citing Part 15 section 4's reproduced finding
  • You can explain your cacheLife choices per view and defend why each one is the right trade-off, not a default you didn't think about
  • You re-ran Part 17's and Part 18's own verification steps against this app and can point at real, current output for each

What this brief does not claim

No code for the Ops Dashboard — no requireRole, no account-scoped queries, no chart, no cache-handler — 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. Treat every detail above as a design-time plan until a learner (or a future content wave) actually builds it and replaces this section with real, run results.

Search the guide