Offline Contact Search Repository
Component Detail
Description
Searches the locally cached contacts stored in the Drift SQLite database when the device is offline. Provides the same interface as the Supabase repository so the service layer can switch transparently. Cache is populated during last successful online sync.
offline-search-repository
Summaries
The Offline Contact Search Repository ensures the platform remains functional when users lose internet connectivity — a scenario common in field environments, during travel, or at events with poor Wi-Fi coverage. Without offline search, users would be completely blocked from accessing their professional network in exactly the moments they need it most, such as during conferences or client visits. By providing access to a locally cached copy of contacts and notes, the application continues to deliver value and maintain user trust even in degraded network conditions. The cache freshness indicator gives users the confidence to act on search results, knowing how current the data is — a transparency feature that reduces support inquiries.
The Offline Search Repository is a low-complexity component with no outbound network dependencies, making it fast to implement and test in isolation using the Drift in-memory database. It must expose an identical interface signature to the Supabase repository to satisfy the service layer's transparent switching contract — this interface alignment must be verified during design review before coding begins. The cache it queries is populated by the Contact Cache Sync Repository, so a dependency exists on that component's cache schema being stable. QA must test: search returning cached results, the `getCacheFreshnessTimestamp()` display, the `isCacheAvailable()` false path (cold install, never synced), and graceful empty results when no matching cache entries exist.
Offline Contact Search Repository wraps a Drift-generated DAO to execute full-text or LIKE queries against locally persisted contacts and notes tables in the device's SQLite database. The `searchLocalContacts(String query)` method issues a Drift `customSelect` or generated query using a `%query%` LIKE pattern across name and organization columns. `searchLocalNotes(String query)` performs keyword matching on the cached note content column. Both methods return typed domain model lists using the same mapper classes as the Supabase repository to ensure interface parity.
`isCacheAvailable()` checks for at least one row in the contacts table. `getCacheFreshnessTimestamp()` reads the `last_sync_at` value written by the Contact Cache Sync Repository. Results include a flag (`isFromCache: true`) appended to domain models so the service and UI layers can surface the offline indicator. The Drift schema must match the sync repository's write schema exactly.
Responsibilities
- Query local Drift SQLite for contacts matching search term
- Search cached notes content by keyword
- Indicate results are from offline cache
- Expose cache freshness timestamp
Interfaces
searchLocalContacts(String query)
searchLocalNotes(String query)
getCacheFreshnessTimestamp()
isCacheAvailable()