ReaME TTS Storage Architecture
Overview
AudioFlow Reader implements a local-first architecture for text-to-speech storage, optimizing for reliable offline playback while preparing for future cloud synchronization.
Storage Strategy
Local Storage (IndexedDB)
-
Database: TextToSpeechDB (Dexie.js implementation)
-
Current Version: 3
-
Primary Storage: Audio blobs stored directly in IndexedDB
-
Size Limits: 50MB per audio file (configurable)
Data Schema
interface TextToSpeechEntry {
id?: number; // Auto-incrementing primary key
text: string; // Original text content
audioBlob: Blob; // Compressed audio data
size: number; // Storage size tracking
timestamp: Date; // Creation timestamp
sourceType: 'url' | 'paste'; // Content source
sourceUrl?: string; // Original URL if applicable
imageUrl?: string; // Associated image URL
syncStatus: 'pending' | 'synced'; // Cloud sync status
}
Indexing Strategy
-
Primary Index: Auto-incrementing ID
-
Secondary Indexes:
-
timestamp: For chronological queries
-
sourceType: For filtering by content source
-
syncStatus: For cloud sync management
-
Design Decisions
1. Blob Storage vs Base64
-
Decision: Store audio as Blob instead of Base64
-
Rationale:
-
~25% smaller storage footprint
-
Faster retrieval for playback
-
No encoding/decoding overhead
-
Native browser handling
-
2. Local-First Architecture
-
Decision: Prioritize local storage with sync preparation
-
Rationale:
-
Reliable offline playback
-
Better user experience
-
Reduced bandwidth usage
-
Future-proof for cloud sync
-
3. Size Management
-
Decision: Implement 50MB per-file limit
-
Rationale:
-
Prevents IndexedDB quota issues
-
Reasonable size for speech content
-
Balances quality and storage
-
Architecture Decisions
1. Connection Management
-
Decision: Use per-operation database connections instead of a global instance
-
Rationale:
-
Prevents issues with Promise cloning in IndexedDB
-
Ensures proper cleanup of database resources
-
Avoids state management complexity
-
-
Implementation: Each database operation creates its own connection and closes it after use
2. Audio Data Storage
-
Decision: Store audio as ArrayBuffer instead of Blob
-
Rationale:
-
ArrayBuffers are more efficiently stored in IndexedDB
-
Avoids DataCloneError issues with Blob objects
-
Maintains compatibility with Web Audio API
-
-
Implementation: Convert audio data to ArrayBuffer before storage, create Blob only when needed for playback
3. Storage Monitoring
-
Decision: Use polling instead of database hooks for storage monitoring
-
Rationale:
-
More reliable than hooks with per-operation connections
-
Simpler implementation
-
Regular updates without complex event handling
-
-
Implementation: Poll storage usage every 5 seconds in the StorageIndicator component
4. Error Handling
-
Decision: Implement comprehensive error handling at all database operations
-
Rationale:
-
Ensures database connections are always properly closed
-
Provides clear error messages for debugging
-
Maintains application stability
-
-
Implementation: Try-catch blocks with connection cleanup in finally blocks
Future Enhancements
1. Audio Compression
-
Implement Web Audio API compression
-
Add configurable quality settings
-
Optimize storage-quality trade-off
2. Cloud Sync (Supabase)
-
Implement background sync
-
Add conflict resolution
-
Manage bandwidth usage
-
Track sync status
3. Storage Management
-
Implement automatic cleanup
-
Add user storage preferences
-
Monitor and manage quotas
Technical Considerations
Browser Compatibility
-
IndexedDB support: All modern browsers
-
Storage limits: Browser-dependent
-
Blob handling: Standardized across platforms
Performance
-
Async operations for large files
-
Compressed storage for efficiency
-
Direct blob playback for performance
Security
-
Local-only storage currently
-
Prepared for secure cloud sync
-
No sensitive data exposure
Migration Strategy
-
Version control through Dexie
-
Automatic schema updates
-
Data preservation during upgrades