5.8 KiB
Packages Folder Removal - Final Implementation
Summary
The packages folder and all its references have been removed from the project. The application now uses IndexedDB by default for all data persistence, with an optional Flask API backend that automatically falls back to IndexedDB if it fails.
Changes Made
1. Dockerfile Updated
- Changed from
node:lts-alpinetonode:lts-slim(fixes ARM64 build issues with Alpine) - Removed all references to
packages/sparkandpackages/spark-tools - Added
VITE_FLASK_API_URLenvironment variable (empty by default) - Simplified build process to not copy packages folder
2. Storage Architecture
The application uses a unified storage service (src/lib/storage-service.ts) that:
Default Behavior (IndexedDB)
- Uses browser-native IndexedDB for all data persistence
- No external dependencies or API calls required
- Works offline and in all modern browsers
- Automatically initializes on first use
Optional Flask API
- Can be enabled via environment variable:
VITE_FLASK_API_URL - Can be enabled via UI settings (user preference)
- Automatically falls back to IndexedDB if Flask API fails
- Supports CORS for cross-origin deployments
3. How Storage Works
All data operations use the useKV hook:
import { useKV } from '@/hooks/use-kv'
// Usage in components
const [todos, setTodos, deleteTodos] = useKV('user-todos', [])
// Always use functional updates to avoid stale data
setTodos(currentTodos => [...currentTodos, newTodo])
The hook automatically:
- Uses IndexedDB by default
- Switches to Flask API if configured
- Falls back to IndexedDB if Flask fails
- Persists data across sessions
4. Configuration Options
Environment Variable (Docker)
# Use IndexedDB (default)
docker run -p 80:80 your-image
# Use Flask API
docker run -p 80:80 -e VITE_FLASK_API_URL=https://backend.example.com your-image
Runtime Configuration (JavaScript)
import { setFlaskAPI, disableFlaskAPI } from '@/lib/storage-service'
// Enable Flask API
setFlaskAPI('https://backend.example.com')
// Disable Flask API (back to IndexedDB)
disableFlaskAPI()
UI Settings
Users can configure the storage backend through the application settings:
- Storage Settings panel
- Feature Toggle Settings
- PWA Settings
5. Automatic Fallback
If the Flask API fails for any reason:
- Network error
- Server error (500)
- Timeout
- CORS issues
The storage service automatically:
- Logs a warning to console
- Switches to IndexedDB
- Continues operation without user intervention
- Updates the configuration to use IndexedDB
Benefits
✅ No External Dependencies
- Works out of the box with no backend required
- IndexedDB is built into all modern browsers
- No API keys or external services needed
✅ Resilient
- Automatic fallback prevents data loss
- Works offline by default
- No single point of failure
✅ Flexible
- Can use Flask API when available
- Supports multiple deployment scenarios
- Easy to switch between backends
✅ Docker Build Fixed
- Removed Alpine-specific issues
- Works on ARM64 and AMD64 architectures
- Faster builds with no workspace protocol errors
Migration Guide
For Users
No action required. The application automatically uses IndexedDB. All existing data is preserved.
For Developers
No code changes needed. All components already use the useKV hook which handles storage transparently.
For DevOps
To enable Flask API backend:
# Set environment variable at deployment time
VITE_FLASK_API_URL=https://backend.example.com
Testing
Test IndexedDB (Default)
- Open the application
- Create some data (todos, models, workflows, etc.)
- Refresh the page
- Data should persist
Test Flask API
- Set
VITE_FLASK_API_URLenvironment variable - Start the application
- Create some data
- Check Flask API logs for requests
Test Automatic Fallback
- Enable Flask API
- Stop the Flask backend
- Try to create/read data
- Application should continue working with IndexedDB
- Check console for fallback message
Related Files
src/lib/storage-service.ts- Main storage service implementationsrc/hooks/use-kv.ts- React hook for using storagesrc/components/StorageSettings.tsx- UI for storage configurationsrc/components/FeatureToggleSettings.tsx- Feature toggles including storageDockerfile- Updated container configuration.env.example- Environment variable examples
Future Enhancements
Potential Improvements
- Sync between backends - Sync IndexedDB data to Flask when it becomes available
- Storage usage monitoring - Track IndexedDB quota and usage
- Import/Export - Allow users to export IndexedDB data as JSON
- Conflict resolution - Handle data conflicts between backends
- Migration tools - Migrate data from IndexedDB to Flask and vice versa
Troubleshooting
Data not persisting
- Check browser console for IndexedDB errors
- Verify browser supports IndexedDB (all modern browsers do)
- Check that IndexedDB is not disabled in browser settings
Flask API not working
- Verify
VITE_FLASK_API_URLis set correctly - Check CORS configuration on Flask backend
- Verify Flask backend is accessible from browser
- Application will automatically fallback to IndexedDB
Docker build failing
- Ensure using
node:lts-slimnotnode:lts-alpine - Run
npm ciinstead ofnpm install - Remove
node_modulesandpackage-lock.jsonif issues persist
Conclusion
The packages folder has been successfully removed. The application now uses a clean, resilient storage architecture that defaults to IndexedDB and optionally supports Flask API with automatic fallback. This provides the best of both worlds: works out of the box with no setup, and can be enhanced with a backend when needed.