LocalDB patterns, IndexedDB usage, and offline fallback strategies
The Construct must work fully offline. Every feature must:
localDB (localforage/IndexedDB)The app uses localforage (IndexedDB wrapper). See src/services/localDB.ts.
import localforage from 'localforage';
// Configure
localforage.config({
name: 'the-construct',
storeName: 'game_data',
});
// Basic operations
await localforage.setItem('user', userData);
const user = await localforage.getItem<User>('user');
await localforage.removeItem('user');
Every Zustand store should persist to localforage:
// In the store
const useMyStore = create<MyStore>((set, get) => ({
data: [],
save: async () => {
await localforage.setItem('my_data', get().data);
},
load: async () => {
const data = await localforage.getItem<MyData[]>('my_data');
if (data) set({ data });
},
}));
| Mode | VITE_SUPABASE_URL | VITE_API_ENDPOINT | Behavior |
|---|---|---|---|
| Offline | empty | empty | localDB + fallback content |
| Supabase | set | empty | Postgres + fallback content |
| Full | set | set | Postgres + AI narrative |
VITE_SUPABASE_URL in .envnpm run devThe app supports exporting all local data as JSON and importing it back:
// Export
const data = await localDB.exportSave();
// Returns JSON string of all stored data
// Import
await localDB.importSave(jsonString);
// Overwrites all local data