Offline-First Architecture
WEFA's core loop works entirely without network. This is a hard requirement, not a nice-to-have.
What Works Offline
- Login (session restoration from localStorage)
- Full onboarding (seed pack fallback for creature generation)
- Add plant + daily care
- Creature nurture and evolution
- Pass-and-play games (Device mode)
- View deck, collection, stats
- PWA shell rendering
What Requires Network
- Creature generation via Claude API + Meshy (falls back to seed pack)
- Local/World multiplayer (Yjs sync)
- EAS attestation creation (queued for later)
- AT Protocol publishing (queued for later)
- Plant identification via Plant.ID
Persistence Strategy
| Data | Storage | Sync |
|---|---|---|
| Player profile | Dexie (IndexedDB) | None (local-only in V1) |
| Plants + care events | Dexie | Job queue -> EAS when online |
| Creatures + assets | Dexie + blob cache | None |
| Game sessions/results | Dexie | Job queue -> EAS when online |
| Auth session | localStorage | None |
| Yjs game docs | y-indexeddb | Resume interrupted sessions |
| Attestations | Dexie | Optional onchain timestamp |
Service Worker
Configured via vite-plugin-pwa with Workbox:
- Precache: App shell, seed pack sprites, icons
- Runtime cache:
CacheFirstfor creature templatesStaleWhileRevalidatefor generated creature assetsNetworkFirstfor API calls
PWA Configuration
display: standalone(installable)- Theme color: earth green
- Manifest icons: 192px and 512px
- Service worker registration in
src/main.tsx - Update prompt when new version available
iOS Safari Considerations
- IndexedDB quota: ~50MB per origin
- Monitor usage with cache management in
src/modules/creature-generator/cache.ts - Evict old creature assets when approaching limit
- Font minimum 16px on inputs (prevents zoom)
- Safe area insets:
env(safe-area-inset-*)
Background Sync
When the device comes back online, the Background Sync API triggers a flush of the job queue, processing any pending attestation or reporting jobs.
Key Files
vite.config.ts- PWA and Workbox configurationsrc/main.tsx- Service worker registrationsrc/modules/creature-generator/cache.ts- Asset cache with quota managementsrc/modules/job-queue/- Background job queuepublic/manifest.json- PWA manifest