Skip to content

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 app in 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.mjs and configure the @vite-pwa/astro integration.
  • Set registerType: 'autoUpdate'.
  • Configure the workbox parameter 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 Dexie database instance named EventRouteOptimiserDB.
  • Define the schema stores for festivals, stages, and bands to 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.