Supabase Contact Chapter Adapter
Component Detail
Description
Low-level Supabase client adapter that maps ContactChapter domain objects to and from Supabase database rows. Handles RLS policy compliance and exposes the raw query interface used by the Contact Chapter Repository and Cross-Chapter Activity Query.
supabase-contact-chapter-adapter
Summaries
This foundational component ensures that all contact-to-chapter relationship data is stored, retrieved, and secured correctly within the Supabase cloud database. It acts as the single gateway through which the application reads and writes chapter membership records, meaning it directly underpins every feature that involves knowing which contacts belong to which chapters. Its built-in support for Row Level Security policies ensures that organizations can only access their own data, which is a critical requirement for multi-organization deployments and a key trust signal for partner organizations. Investing in a well-built adapter here reduces the risk of data leaks and ensures compliance with data governance expectations across all chapters using the platform.
This is a medium-complexity infrastructure component that sits at the foundation of the data layer, meaning several higher-level components — including the Contact Chapter Repository and Cross-Chapter Activity Query — cannot be built or tested without it. It should be prioritized early in the sprint schedule to unblock dependent work. Development requires familiarity with Supabase PostgREST query syntax, RLS policy configuration, and domain-to-database serialization patterns. Testing should include both unit tests with mocked Supabase responses and integration tests against a staging Supabase instance to verify RLS filtering behaves correctly under different auth contexts.
Since this adapter has no dependencies of its own, it can be developed independently in parallel with other foundational work.
This adapter wraps the Supabase client for the contact_chapters table, providing six discrete interfaces: insert, delete, selectByContact, selectByChapter, countByContact, and joinActivities. It handles serialization of ContactChapter domain objects to and from Map
Error handling must map Supabase PostgrestException codes to typed domain exceptions rather than surfacing raw database errors upstream. Runs in both mobile and backend contexts, so the Supabase client instance must be injected rather than instantiated directly.
Responsibilities
- Execute Supabase PostgREST queries against contact_chapters table
- Serialize and deserialize ContactChapter domain objects
- Handle Supabase error codes and map to domain exceptions
- Support RLS policy filtering for multi-organization deployments
Interfaces
insert(Map<String, dynamic> data) → Future<void>
delete(String contactId, String chapterId) → Future<void>
selectByContact(String contactId) → Future<List<Map<String, dynamic>>>
selectByChapter(String chapterId) → Future<List<Map<String, dynamic>>>
countByContact(String contactId) → Future<int>
joinActivities(String contactId) → Future<List<Map<String, dynamic>>>
Relationships
Dependents (3)
Components that depend on this component
Related Data Entities (1)
Data entities managed by this component