5.1 KiB
Storage Backend Default: IndexedDB
Summary
The storage system has been updated to default to IndexedDB instead of Flask backend. Flask backend is now opt-in only, requiring explicit configuration through UI settings or environment variables.
Changes Made
1. Updated Storage Initialization Logic (src/lib/unified-storage.ts)
Previous Behavior:
- Checked for Flask backend preference first
- If
codeforge-prefer-flaskwas set in localStorage, attempted Flask connection - Fell back to IndexedDB only if Flask failed
New Behavior:
- IndexedDB is now the default - initialized first unless Flask is explicitly configured
- Flask backend is only used when:
VITE_FLASK_BACKEND_URLenvironment variable is set, OR- User explicitly enables Flask backend in UI settings
- Priority order:
- Flask (only if explicitly configured)
- IndexedDB (default)
- SQLite (if preferred)
- Spark KV (fallback)
2. Environment Variable Support
The Flask backend URL can be configured via environment variable:
# .env file
VITE_FLASK_BACKEND_URL=http://localhost:5001
Or for production:
VITE_FLASK_BACKEND_URL=https://backend.example.com
3. Updated UI Components (src/components/StorageSettingsPanel.tsx)
Added Flask backend switching functionality:
- Input field for Flask backend URL
- Button to switch to Flask backend
- Clear indication that IndexedDB is the default
- Improved descriptions explaining when to use each backend
4. Updated Documentation (STORAGE.md)
- Reorganized backend priority to show IndexedDB first as default
- Added clear "Default" label for IndexedDB
- Documented Flask backend configuration methods
- Clarified that Flask requires explicit configuration
Usage
Default Behavior (No Configuration)
By default, the app will use IndexedDB automatically:
import { unifiedStorage } from '@/lib/unified-storage'
// Uses IndexedDB by default
await unifiedStorage.set('my-key', myData)
const data = await unifiedStorage.get('my-key')
Console output:
[Storage] Initializing default IndexedDB backend...
[Storage] ✓ Using IndexedDB (default)
Enabling Flask Backend
Method 1: Environment Variable (Recommended for Production)
Create a .env file:
VITE_FLASK_BACKEND_URL=http://localhost:5001
Or set in Docker/Caprover:
docker run -e VITE_FLASK_BACKEND_URL=https://backend.example.com myapp
Method 2: UI Settings (User Preference)
- Navigate to Settings → Storage
- Enter Flask backend URL in the input field
- Click "Flask Backend" button
- System will migrate all data from IndexedDB to Flask
Switching Back to IndexedDB
In UI Settings:
- Navigate to Settings → Storage
- Click "IndexedDB (Default)" button
- System will migrate all data back to IndexedDB
Benefits of IndexedDB Default
- No Setup Required - Works immediately without backend server
- Offline First - Full functionality without network connection
- Fast Performance - Local storage is faster than network requests
- Privacy - Data stays on user's device by default
- Simpler Deployment - No backend infrastructure needed for basic usage
When to Use Flask Backend
Enable Flask backend when you need:
- Cross-device synchronization - Share data across multiple devices
- Centralized data management - Admin access to all user data
- Server-side processing - Complex queries, analytics, backups
- Team collaboration - Multiple users sharing the same data
- Production deployments - Centralized data storage for SaaS applications
Migration Path
The system automatically migrates data when switching backends:
// Switch from IndexedDB to Flask
await switchToFlask('http://localhost:5001')
// Switch from Flask back to IndexedDB
await switchToIndexedDB()
All existing data is preserved during migration.
Backwards Compatibility
Existing projects with Flask backend configured will continue to use Flask backend:
- If
codeforge-prefer-flaskis set in localStorage - If
VITE_FLASK_BACKEND_URLis configured - Data will not be lost or modified
Testing
To verify the default behavior:
-
Clear localStorage (to remove any preferences):
localStorage.clear() -
Reload the app
-
Check console output:
[Storage] Initializing default IndexedDB backend... [Storage] ✓ Using IndexedDB (default) -
Open DevTools → Application → IndexedDB
- Should see
CodeForgeDBdatabase - Should see
keyvalueobject store
- Should see
Files Changed
src/lib/unified-storage.ts- Updated initialization logicsrc/components/StorageSettingsPanel.tsx- Added Flask backend UISTORAGE.md- Updated documentation.env.example- Already documented VITE_FLASK_BACKEND_URL
Related Documentation
- STORAGE.md - Complete storage system documentation
- FLASK_BACKEND_SETUP.md - Flask backend installation guide
- .env.example - Environment variable configuration