database-offline-sync
Skill4 starsChanged 39 days agoMITView on GitHub
Database engineering and offline-first architecture with Room, SQLite, PostgreSQL, Redis, DataStore, migrations, sync strategies, and conflict resolution
In this repository13 other files it gives its agents.
- ai-integration-engineerSkill
- android-cliSkill
- android-frontend-engineerSkill
- android-security-engineerSkill
- android-security-lab-builderSkill
- android-testing-engineerSkill
- android-ui-ux-designSkill
- app-performance-engineerSkill
- app-product-architectSkill
- backend-api-engineerSkill
- devops-release-engineerSkill
- firebase-supabase-engineerSkill
- fullstack-web-engineerSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 61
Follow this sequence for database and offline-first features:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database & Offline-First Engineering Skill
Trigger Conditions
Activate this skill when the task involves any of the following:
- Database schema design: Entity modeling, table structure, relationships (one-to-many, many-to-many), normalization, denormalization, index planning
- Offline support: Offline-first architecture, local caching, pending operation queues, connectivity-aware data fetching
- Data synchronization: Client-server sync, bidirectional sync, delta sync, full sync, background sync with WorkManager
- Database migrations: Room auto-migrations, manual migrations, schema versioning, zero-downtime migration, rollback
- Caching: Room as local cache, Redis caching, HTTP cache headers, in-memory cache, cache invalidation, stale-while-revalidate
- DataStore: Preferences DataStore, Proto DataStore, migration from SharedPreferences, typed key-value storage
- Query optimization: Index tuning, EXPLAIN QUERY PLAN, pagination, batch operations, transaction performance
- Conflict resolution: Last-write-wins, version vectors, merge strategies, conflict detection, user-prompted resolution
- Repository pattern: Data source abstraction, NetworkBoundResource, single source of truth, reactive data with Flow
Capabilities
Local Storage (Android)
- Room (SQLite ORM): Entity design with composite keys, indices, foreign keys, embedded objects; DAO with suspend functions, Flow, PagingSource; TypeConverters; KSP annotation processing; database inspector
- SQLite: Direct SQLiteDatabase access, WAL mode, pragma tuning, FTS (full-text search), custom functions
- DataStore: Preferences DataStore for simple key-value, Proto DataStore for typed objects with protobuf, migration from SharedPreferences, multi-process support
- EncryptedSharedPreferences: SQLCipher for encrypted Room databases
Backend Storage
- PostgreSQL: Schema design, JSONB columns, materialized views, partitioning, connection pooling (HikariCP), Exposed/jOOQ/JDBI query builders
- Redis: Caching layer, pub/sub for real-time sync notifications, sorted sets for leaderboards, streams for event sourcing, TTL-based expiration, cluster configuration
Architecture Patterns
- Repository pattern: Single source of truth, local-first reads, background network writes
- NetworkBoundResource: Fetch from cache, request from network, save response, serve cache
- Offline queue: Pending operations table with retry, exponential backoff, idempotency keys
- Sync engine: Delta sync with server timestamps, full sync fallback, pagination of sync batches
- Conflict resolution: Last-write-wins, client-wins, server-wins, three-way merge, vector clocks
- Reactive data: Room Flow queries, DataStore Flow, StateFlow in ViewModel, combine/transform operators
Operations
- Migrations: Room @AutoMigration, manual Migration class, MigrationTestHelper, destructive fallback, PostgreSQL Flyway/Alembic
- Testing: In-memory Room databases, migration tests, DAO tests with Robolectric, sync integration tests
- Monitoring: Database inspector, SQLite EXPLAIN, PostgreSQL EXPLAIN ANALYZE, query logging, sync status dashboards
- Performance: Index optimization, covering indices, batch inserts inside transactions, WAL journal mode, prepared statements, connection pooling
Workflow
Follow this sequence for database and offline-first features:
- Define Data Model -- Identify entities, relationships, and access patterns. Determine which data must be available offline and which is network-only.
- Design Schema -- Create Room @Entity classes with proper primary keys, indices, and foreign keys. Design server-side PostgreSQL tables. Map relationships (one-to-many with @Relation, many-to-many with junction tables).
- Implement DAO -- Write @Dao interfaces with suspend functions for writes, Flow<List
<T>> for reactive reads, PagingSource<Int, T> for paginated lists. Add @Transaction for compound operations. - Add Migrations -- Use @AutoMigration for simple changes (add column, add table). Write manual Migration for renames, data transforms, index changes. Always add migration tests.
- Build Repository -- Implement repository with local Room source and remote API source. Use NetworkBoundResource for read operations. Queue writes for offline support.
- Implement Sync -- Add ConnectivityManager monitoring. Build sync engine with delta timestamps. Use WorkManager for periodic and connectivity-triggered sync. Handle pagination of large sync payloads.
- Add Conflict Resolution -- Detect conflicts via version numbers or timestamps. Apply resolution strategy (LWW, merge, user-prompt). Log conflicts for audit. Test edge cases (simultaneous edits, network partitions).
- Test -- Unit test DAOs with in-memory database. Test migrations with MigrationTestHelper. Integration test sync with mock server. Test offline queue replay ordering.
Reference Files
references/room-database.md-- Room entities, DAOs, database setup, TypeConverters, coroutines, Flow, KSPreferences/datastore.md-- Preferences DataStore, Proto DataStore, Hilt integration, migrationreferences/migration-strategies.md-- Auto-migration, manual migration, testing, PostgreSQL migrationsreferences/offline-first.md-- NetworkBoundResource, offline queue, connectivity, WorkManager syncreferences/conflict-resolution.md-- LWW, merge, vector clocks, detection, testingreferences/caching-patterns.md-- Cache-aside, write-through, Redis, HTTP caching, invalidationreferences/query-optimization.md-- Indices, EXPLAIN, pagination, batch ops, WAL, connection pooling
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

