Capstone — commerce and mutation workflows
Build a storefront whose product data, inventory, pricing, cart mutations, promo rules, and checkout validation make the server-authority vs immediate-UI problem explicit.
Core authority model
Do not let optimistic state become a second permanent source of truth.
State categories
Document a hybrid cart deliberately if you use one.
Server and Client Component split
Only serializable data needed by the client should cross the boundary. Database connections, privileged SDKs, and normal functions stay server-side unless represented through supported Server Function transport.
Add-to-cart mutation
The server validates product/variant existence, quantity, current stock, authenticated cart relationship, and server-owned pricing.
Model Action state explicitly
type CartActionState =
| { status: 'idle' }
| { status: 'error'; message: string }
| { status: 'success'; cartVersion: string };
Prefer mutually exclusive states over unrelated loading/error/success booleans that permit contradictions.
Optimistic quantity updates
Simulate inventory changing between render and mutation to prove that client state and TypeScript do not enforce real stock truth.
Concurrent mutation challenge
Test rapid updates such as 1 → 2 → 3 → 4.
Promo code workflow
The client submits a code; the server decides existence, expiry, eligibility, combinability, and actual discount.
Checkout form architecture
Build shipping/contact/delivery/notes with visible labels, runtime server validation, field errors, an error summary, pending state, and deliberate focus movement after failure.
If the framework supports progressive enhancement, test behavior before hydration and identify which optimistic enhancements require client JavaScript.
Suspense and failure architecture
Classify product-not-found routing errors, optional recommendation failure, mutation feedback, unexpected render errors, and whole-app initialization failures separately.
Cache layers are not interchangeable
Mutation invalidation and revalidation belong to the data/framework architecture, not optimistic UI alone.
Security review
Threat-model client-submitted prices/IDs, authorization, promo abuse, duplicate checkout, cross-user cart access, CSRF/framework transport, XSS in product content, unsafe redirects, logging, and third-party payment/provider boundaries.
Testing portfolio
A strong commerce capstone shows that immediate UX, server authority, accessibility, caching, and failure recovery can coexist without duplicating truth.