| name | Mobile Offline Storage |
| description | Cross-platform offline-first data management |
| version | 1.0.0 |
| category | Data Persistence |
| slug | offline-storage |
| status | active |
| graph | {"domains":["domain:mobile"],"specializations":["specialization:mobile-development"],"skillAreas":["skill-area:mobile-offline-sync","skill-area:mobile-local-databases"],"roles":["role:mobile-engineer"],"workflows":["workflow:feature-development","workflow:release-management"],"topics":["topic:accessibility","topic:offline-first"]} |
Mobile Offline Storage Skill
Overview
This skill provides cross-platform offline-first data management capabilities. It enables configuration of WatermelonDB, Realm, MMKV, and other offline storage solutions with sync queue architectures.
Allowed Tools
bash - Execute package managers and build tools
read - Analyze storage configurations and schemas
write - Generate models and sync logic
edit - Update storage implementations
glob - Search for storage files
grep - Search for patterns
Capabilities
WatermelonDB (React Native)
-
Schema Definition
- Define table schemas
- Configure column types
- Set up relations
- Handle migrations
-
Sync Engine
- Implement sync adapters
- Handle conflict resolution
- Configure batch operations
- Manage sync state
Realm (Cross-Platform)
-
Object Schemas
- Define Realm objects
- Configure primary keys
- Set up relationships
- Handle embedded objects
-
Realm Sync
- Configure Device Sync
- Handle flexible sync
- Manage subscriptions
- Handle conflicts
MMKV
- Key-Value Storage
- Configure MMKV instances
- Handle encryption
- Implement migrations
- Manage namespaces
Sync Architecture
-
Offline-First Patterns
- Design sync queues
- Handle network state
- Implement retry logic
- Manage pending operations
-
Conflict Resolution
- Last-write-wins strategy
- Merge strategies
- User resolution UI
- Audit logging
Target Processes
offline-first-architecture.js - Offline patterns
rest-api-integration.js - API sync
graphql-apollo-integration.js - GraphQL sync
Dependencies
- WatermelonDB (React Native)
- Realm SDK
- MMKV
- SQLite
Usage Examples
WatermelonDB Schema
import { appSchema, tableSchema } from '@nozbe/watermelondb';
export const schema = appSchema({
version: 1,
tables: [
tableSchema({
name: 'posts',
columns: [
{ name: 'title', type: 'string' },
{ name: 'body', type: 'string' },
{ name: 'is_published', type: 'boolean' },
{ name: 'author_id', type: 'string', isIndexed: true },
{ name: 'created_at', type: 'number' },
{ name: 'updated_at', type: 'number' },
],
}),
tableSchema({
name: 'comments',
columns: [
{ name: 'body', type: 'string' },
{ name: 'post_id', type: 'string', isIndexed: },
{ : , : },
{ : , : },
],
}),
],
});
WatermelonDB Model
import { Model, Q } from '@nozbe/watermelondb';
import { field, date, children, relation } from '@nozbe/watermelondb/decorators';
export class Post extends Model {
static table = 'posts';
static associations = {
comments: { type: 'has_many', foreignKey: 'post_id' },
author: { type: 'belongs_to', key: 'author_id' },
};
@field('title') title!: string;
@field('body') body!: string;
@field('is_published') isPublished!: boolean;
@field('author_id') authorId!: string;
@date('created_at') createdAt!: Date;
@date('updated_at') updatedAt!: Date;
@children('comments') comments!: Query<Comment>;
@relation('users', 'author_id') author!: Relation<>;
}
Sync Queue Implementation
interface SyncOperation {
id: string;
type: 'create' | 'update' | 'delete';
entity: string;
payload: any;
timestamp: number;
retryCount: number;
}
class SyncQueue {
private queue: SyncOperation[] = [];
private isProcessing = false;
async enqueue(operation: Omit<SyncOperation, 'id' | 'timestamp' | 'retryCount'>) {
const op: SyncOperation = {
...operation,
id: uuid(),
timestamp: Date.now(),
retryCount: 0,
};
this.queue.push(op);
await this.persistQueue();
this.processQueue();
}
private async () {
(. || .. === ) ;
isOnline = .().( state.);
(!isOnline) ;
. = ;
(.. > ) {
operation = .[];
{
.(operation);
..();
.();
} (error) {
operation.++;
(operation. >= ) {
..();
.(operation, error);
}
;
}
}
. = ;
}
() {
(operation.) {
:
api.(, operation.);
:
api.(, operation.);
:
api.();
}
}
}
Quality Gates
- Data integrity verified on sync
- Conflict resolution tested
- Offline functionality verified
- Migration tests passing
Related Skills
ios-persistence - iOS Core Data
android-room - Android Room
graphql-mobile - GraphQL offline
Version History