This repository contains a minimal offline-first PWA storefront (React client) and a tiny Express API (demo in-memory). The demo showcases:
- Installable web app (manifest + icons)
- Service worker that precaches the app shell and runtime-caches product responses and images
- Offline cart persisted in IndexedDB and queued checkout actions
- Background Sync support (where available) and client-side replay on
onlineevents - Idempotent order endpoint on the API to avoid duplicate orders
- Run the demo using the provided PowerShell helper (Windows):
.\start-demo.ps1This opens two PowerShell windows and runs the API and the client dev server (it runs npm install on first run).
-
Open the client in Chrome at:
-
Verify service worker registered (open DevTools -> Console; you should see a "Service worker registered:" log).
-
Add products to cart and then simulate offline:
- DevTools -> Network -> Offline (or disconnect your machine)
- Click "Checkout" — the UI will enqueue the order and clear the cart. It displays a message indicating the order was queued.
-
Reconnect network:
- If the page is open, the client will replay queued orders automatically via
onlineevent. - If you used a Chromium browser with Background Sync support, the Service Worker will also attempt to replay queued orders while the page is closed.
- If the page is open, the client will replay queued orders automatically via
-
Check the API window to see order requests arriving and the API's responses.
npm run install-all— installs dependencies for bothapiandclient.npm run dev— starts API and client concurrently (requiresnpm installin the repo root to installconcurrently).
Or use the PowerShell script above for a Windows-friendly flow.
- The demo API is in-memory and will reset on restart. If you want persistent data, I can wire MongoDB and update
docker-compose.yml. - For full Lighthouse PWA checks you can run a production build (
npm run buildinclient) and serve it over HTTPS orlocalhost— the manifest and SW are included underclient/public.
If you'd like, I can now (pick one):
- Wire the API to MongoDB, add seed data, and update
docker-compose.ymlso the full stack runs in Docker (recommended for reproducible demos). - Improve the Service Worker (Workbox) and add a Lighthouse audit script to iterate until core PWA checks pass.
- Create a short demo script and slide/checklist you can use while presenting (step-by-step actions and expected outcomes).
Tell me which option you'd like; I can implement it and verify the demo works end-to-end.
If you prefer a reproducible demo using Docker for the API and MongoDB, you can run:
docker-compose up --build -dThis will start the API on http://localhost:4000 backed by a MongoDB instance. Then run the client locally:
cd client
npm install
npm run devOpen http://localhost:5174 and follow the demo steps above. The API will be persistent across container restarts thanks to the mongo-data volume.
- Client
cd client
npm install
npm run dev