Appearance
Agent Directive: Astro Offline-First PWA Setup
Objective
Scaffold an offline-capable Astro web application designed for zero-connectivity environments. The application must operate entirely from local storage, syncing with the Cloudflare D1 API only when a connection is detected.
Execution Sequence
1. Initialise the Frontend Workspace
- Create a new directory named
appin the repository root. - Initialise a blank package configuration and install Astro:
npm install astro @vite-pwa/astro dexie -D
2. Configure the Service Worker
- Create
app/astro.config.mjsand configure the@vite-pwa/astrointegration. - Set
registerType: 'autoUpdate'. - Configure the
workboxparameter to aggressively cache the app shell:globPatterns: ['**/*.{js,css,html,ico,png,svg}'].
3. Implement the Offline Database (IndexedDB)
- Create a file at
app/src/lib/db.ts. - Initialise a new
Dexiedatabase instance namedEventRouteOptimiserDB. - Define the schema stores for
festivals,stages, andbandsto mirror the D1 data contract.
4. Scaffold the App Shell
- Create
app/src/pages/index.astro. - Inject the PWA registration script (
virtual:pwa-register). - Implement a minimal HTML structure that includes a script to verify the Dexie database loads correctly in the browser console.