Define capstone architecture and acceptance tests
Design the capstone around a real problem
Build a fictional tool library dashboard. A viewer can read and filter inventory; a manager can also adjust quantities. Stock is a whole number between 0 and 999. Each row has an ID and a revision number so stale writes can be rejected. Your goal is to demonstrate working behavior and explain the design, not to combine every React library. Start from the provided starter and compare it with the reference implementation only after attempting the acceptance criteria.
Choose one architecture
Option A: a Vite client-rendered SPA with React Router and an independent API. It is straightforward for an authenticated dashboard that does not need public search indexing. Option B: a supported SSR framework with route loaders and server-side rendering; this can help when first HTML or public pages matter, but adds deployment, cache isolation and hydration work. Choose A for the offline lab; keep B as a written alternative. In production, the API derives identity from a verified session and authorizes every operation. The fixture injects a synthetic actor; it is not an authentication implementation.
export const seed = [ {id:'drill', name:'Drill', quantity:3, version:1}, {id:'saw', name:'Saw', quantity:0, version:1}, {id:'lamp', name:'Lamp', quantity:5, version:1}];export const actors = { viewer:{id:'demo-viewer',role:'viewer'}, manager:{id:'demo-manager',role:'manager'}};export function canAdjust(actor) { return actor?.role === 'manager'; }export function filterItems(items, query) { const term = query.trim().toLowerCase(); return items.filter(item => item.name.toLowerCase().includes(term));}export function parseQuantity(raw) { if (typeof raw !== 'string' || !/^\d+$/.test(raw)) return null; const n = Number(raw); return Number.isSafeInteger(n) && n <= 999 ? n : null;}The three initial quantities are 3, 0 and 5. The zero quantity is valid. Filtering is case-insensitive, and invalid quantity text produces null rather than silently accepting a partial number.
import {seed, canAdjust, parseQuantity} from './contracts.mjs';// Offline model. Actor is supplied by a trusted server adapter in a real app.export function createInventoryApi(actor, initial=seed) { let items = initial.map(x=>({...x})); let failNext = false; return { failNextRead() { failNext = true; }, async list() { if (!actor || !['viewer','manager'].includes(actor.role)) throw new Error('Unauthorized'); if (failNext) { failNext=false; throw new Error('Read failed'); } return items.map(x=>({...x})); }, async adjust(id, raw, expectedVersion) { if (!canAdjust(actor)) return {ok:false,status:403}; const current = items.find(x=>x.id===id); if (!current) return {ok:false,status:404}; const quantity = parseQuantity(raw); if (quantity===null) return {ok:false,status:400}; if (current.version!==expectedVersion) return {ok:false,status:409}; const next = {...current,quantity,version:current.version+1}; items = items.map(x=>x.id===id?next:x); return {ok:true,item:{...next}}; } };}The API returns fresh record copies and rejects unauthorized, invalid and stale mutations with separate status codes. For example, a viewer receives 403 even if the UI accidentally exposes a save button. In a real backend, revision comparison and write must be atomic, such as a conditional database update.
Write acceptance criteria before implementation
export const acceptance = [ {id:'read',given:'viewer',when:'open inventory',then:'rows appear'}, {id:'denied',given:'viewer',when:'call adjust directly',then:'403; no change'}, {id:'invalid',given:'manager',when:'submit -1',then:'400; no change'}, {id:'conflict',given:'manager',when:'submit stale version',then:'409; reload'}, {id:'retry',given:'read fails once',when:'retry',then:'rows appear'}];export function missingEvidence(results) { return acceptance.filter(c=>results[c.id]!=='PASS').map(c=>c.id);}Write a test for every criterion, including the denied direct request and unchanged inventory after rejection. A planned test does not count as passed. Add tests for route navigation, loading, keyboard controls and save recovery in the next lesson.