Data Layer low complexity Shared Component mobile
0
Dependencies
0
Dependents
1
Entities
0
Integrations

Description

Maintains a local Drift SQLite cache of contacts and notes fetched from Supabase, used by the offline search repository. Refreshes the cache after successful online fetches from the contact list feature.

Feature: Contact & Notes Search

contact-cache-sync-repository

Summaries

The Contact Cache Sync Repository is the foundation of the platform's offline resilience strategy. It ensures that users always have a recent, locally available snapshot of their contact network, enabling the application to function in environments where internet access is intermittent or unavailable. As a shared component serving multiple features — including contact listing and search — it centralizes cache management logic, preventing redundant implementations and reducing maintenance costs across the codebase. Reliable cache synchronization directly protects user productivity: professionals who lose connectivity mid-event can continue accessing, searching, and referencing contacts without interruption, reinforcing the platform's value proposition as a dependable field tool.

The Contact Cache Sync Repository is marked as a shared component, meaning changes to its schema or interface have cross-feature impact across both the contact list and search features. Schema changes must go through a coordinated review process, and any modifications require regression testing across all consuming features. It has no outbound component dependencies, so it can be developed early as a foundational infrastructure piece. The `pruneDeleted(List activeIds)` interface implies the component must receive active ID sets from the contact list sync flow — coordinate with the contact list feature team to define the data handoff contract.

Testing must cover: upsert idempotency, cache invalidation correctness, timestamp tracking per organization, and deletion pruning without data loss.

Contact Cache Sync Repository uses Drift DAOs to manage the local SQLite cache of contacts, peer mentors, and notes. `upsertContacts(List contacts)` performs a Drift `insertOrReplace` batch operation, mapping domain model fields to Drift-generated data class constructors. `upsertNotes(List notes)` follows the same pattern for the notes table. `clearCache(String orgId)` executes a Drift `deleteWhere` scoped to the provided org ID, used before a full re-sync.

`getLastSyncTimestamp(String orgId)` reads from a dedicated `sync_metadata` table keyed by org ID. `pruneDeleted(List activeIds)` issues a `deleteWhere` using a NOT IN clause to remove records whose server-side IDs no longer appear in the latest fetch. As a shared component, the Drift schema this repository writes to is the read schema for both the Offline Search Repository and the contact list feature's offline browsing — schema changes must be coordinated and migration scripts must be included in any schema-altering PR.

Responsibilities

  • Write fetched contacts to local Drift tables
  • Invalidate and refresh cache on sync
  • Track last sync timestamp per organization
  • Prune stale or deleted records

Interfaces

upsertContacts(List contacts)
upsertNotes(List notes)
clearCache(String orgId)
getLastSyncTimestamp(String orgId)
pruneDeleted(List activeIds)

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/cache/sync 6 endpoints
GET /api/v1/cache/sync
GET /api/v1/cache/sync/:id
POST /api/v1/cache/sync
PUT /api/v1/cache/sync/:id
DELETE /api/v1/cache/sync/:id
GET /api/v1/cache/sync/timestamp