···11----
22-description:
33-globs:
44-alwaysApply: false
55----
66-# Storage and Cache System
77-88-This directory contains utilities for handling local storage and caching operations in the Spark Social application.
99-1010-## Storage Components
1111-1212-- **LocalStorageInterface**: Abstract interface defining storage operations.
1313-- **SharedPrefsStorage**: Implementation using SharedPreferences for non-sensitive data.
1414-- **SecureStorage**: Implementation using FlutterSecureStorage for sensitive data.
1515-- **StorageManager**: Provides centralized access to all storage implementations.
1616-- **StorageConstants**: Constants for storage keys used throughout the app.
1717-- **SettingsRepository**: Manages application settings with interface and implementation.
1818-1919-## Cache Components
2020-2121-- **SQLCacheInterface**: Abstract interface for SQL-based cache operations.
2222-- **SQLCacheImpl**: SQLite implementation for persistent caching.
2323-- **CacheManagerInterface**: Abstract interface for cache management operations.
2424-- **CacheManagerImpl**: Implementation of cache manager with SQL backend.
2525-- **DownloadManagerInterface**: Abstract interface for download operations.
2626-- **DownloadManagerImpl**: Handles file downloads and caching.
2727-2828-## Usage Examples
2929-3030-### Basic Storage Operations
3131-3232-```dart
3333-// Access the storage manager from GetIt
3434-final storageManager = GetIt.instance<StorageManager>();
3535-3636-// Store a value in preferences (non-sensitive data)
3737-await storageManager.preferences.setString(StorageConstants.username, 'johndoe');
3838-3939-// Retrieve a value from preferences
4040-final username = await storageManager.preferences.getString(StorageConstants.username);
4141-4242-// Store sensitive data in secure storage
4343-await storageManager.secure.setString(StorageConstants.authToken, 'secret-token');
4444-4545-// Retrieve sensitive data
4646-final token = await storageManager.secure.getString(StorageConstants.authToken);
4747-```
4848-4949-### Storing Complex Objects
5050-5151-```dart
5252-// Define a User class with freezed
5353-@freezed
5454-class User with _$User {
5555- const factory User({
5656- required String id,
5757- required String name,
5858- required String email,
5959- }) = _User;
6060-6161- factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
6262-}
6363-6464-// Store a user object
6565-final user = User(id: '123', name: 'John Doe', email: 'john@example.com');
6666-await storageManager.preferences.setObject<User>(
6767- StorageConstants.user,
6868- user,
6969- (json) => User.fromJson(json)
7070-);
7171-7272-// Retrieve a user object
7373-final retrievedUser = await storageManager.preferences.getObject<User>(
7474- StorageConstants.user,
7575- (json) => User.fromJson(json)
7676-);
7777-```
7878-7979-### SQL Cache Operations
8080-8181-```dart
8282-// Access the SQL cache from GetIt
8383-final sqlCache = GetIt.instance<SQLCacheInterface>();
8484-8585-// Store data in cache
8686-await sqlCache.put('cache_key', {'data': 'value'});
8787-8888-// Retrieve data from cache
8989-final cachedData = await sqlCache.get('cache_key');
9090-9191-// Check if data exists in cache
9292-final exists = await sqlCache.exists('cache_key');
9393-9494-// Remove data from cache
9595-await sqlCache.remove('cache_key');
9696-9797-// Clear all cache
9898-await sqlCache.clear();
9999-```
100100-101101-### Cache Manager Operations
102102-103103-```dart
104104-// Access the cache manager from GetIt
105105-final cacheManager = GetIt.instance<CacheManagerInterface>();
106106-107107-// Get a file (from cache if available, or download it)
108108-final file = await cacheManager.getFile('https://example.com/image.jpg');
109109-110110-// Store a file in cache
111111-final bytes = await someImage.readAsBytes();
112112-await cacheManager.putFile('https://example.com/image.jpg', bytes);
113113-114114-// Get cache size
115115-final cacheSize = await cacheManager.getCacheSize();
116116-print('Cache size: ${cacheSize / 1024 / 1024} MB');
117117-118118-// Clear cache
119119-await cacheManager.clearCache();
120120-```
121121-122122-### Download Manager Operations
123123-124124-```dart
125125-// Access the download manager from GetIt
126126-final downloadManager = GetIt.instance<DownloadManagerInterface>();
127127-128128-// Download a file
129129-final downloadedFile = await downloadManager.downloadFile('https://example.com/file.pdf');
130130-131131-// Check download status
132132-final isDownloading = await downloadManager.isDownloading('https://example.com/file.pdf');
133133-134134-// Cancel download
135135-await downloadManager.cancelDownload('https://example.com/file.pdf');
136136-```
137137-138138-### Settings Repository
139139-140140-```dart
141141-// Access settings repository from GetIt
142142-final settingsRepository = GetIt.instance<SettingsRepository>();
143143-144144-// Get app settings
145145-final settings = await settingsRepository.getSettings();
146146-147147-// Update a setting
148148-await settingsRepository.updateSetting('theme_mode', 'dark');
149149-150150-// Reset settings to defaults
151151-await settingsRepository.resetSettings();
152152-```
153153-154154-## Available Services in GetIt
155155-156156-All storage and cache services are registered in the service locator and can be accessed via GetIt:
157157-158158-- `StorageManager` - Main storage management
159159-- `SQLCacheInterface` - SQL-based cache operations
160160-- `CacheManagerInterface` - File cache management
161161-- `DownloadManagerInterface` - File download operations
162162-- `SettingsRepository` - Application settings
163163-164164-## Best Practices
165165-166166-1. Always use interfaces when injecting dependencies
167167-2. Initialize storage manager and SQL cache during app startup
168168-3. Use appropriate storage type (secure vs. preferences) based on data sensitivity
169169-4. Cache frequently accessed data using the SQL cache
170170-5. Use the download manager for large files to avoid memory issues
171171-6. Monitor cache size and implement cleanup strategies
172172-7. Handle cache failures gracefully with fallback mechanisms
+1-1
.cursor/rules/project-overview.mdc
···55---
66# Spark Social - Project Overview
7788-This is a Flutter application for a social media platform inspired by TikTok, integrated with the Bluesky/AT Protocol.
88+This is a Flutter application for a social media platform inspired by TikTok, integrated with the AT Protocol.
991010## Main Entry Points
1111- [lib/main.dart](mdc:lib/main.dart) - Main application entry point
-26
.cursor/rules/task.mdc
···11----
22-description:
33-globs:
44-alwaysApply: false
55----
66-# Task Implementation and Tracking Guidelines
77-88-When you are asked to implement a new feature or a set of functionalities, please follow these steps:
99-1010-1. **Create a Detailed Plan Document**:
1111- * Create a new Markdown (`.md`) file in the root of the project or a relevant subdirectory
1212- * Name this file descriptively, for example, `feature_x_implementation_plan.md`.
1313- * In this document, outline all the steps required to implement the feature. Make these steps as detailed as necessary.
1414- * Each step should be a checklist item (e.g., `- [ ] Step 1: Description`).
1515-1616-2. **Reference and Update the Plan Document**:
1717- * As you work on implementing the feature, continuously refer back to this plan document.
1818- * When a step or a sub-task is completed, update the document by marking the corresponding checkbox (e.g., `- [x] Step 1: Description`).
1919- * Mention the status of the plan (e.g., "Updated `feature_x_implementation_plan.md`") in your responses at relevant stages, especially after completing a significant part of the task.
2020-2121-3. **Final Review**:
2222- * Once all tasks in the plan document are marked as complete, state that the feature implementation is finished according to the plan.
2323-2424-This process helps in keeping track of progress and ensures all aspects of the feature request are addressed systematically.
2525-2626-