Cross-Chapter Activity Query
Component Detail
Description
Specialized query component that retrieves all activity records for a specific contact across all chapters they are affiliated with. Used exclusively by the duplicate detection service to fetch the comparison dataset efficiently using a join across contact_chapters and activities tables.
cross-chapter-activity-query
Summaries
This component is the backbone of the organization's duplicate prevention strategy, directly protecting data integrity across all chapters. By enabling the system to instantly recognize when the same contact has already been recorded in another chapter, it prevents double-counting of participants, which safeguards the accuracy of reporting to funders and Bufdir. Clean participation data directly supports grant compliance, reduces administrative rework caused by duplicate records, and builds trust with partner organizations who rely on accurate cross-chapter statistics. Without this capability, coordinators would face time-consuming manual deduplication and risk reporting errors that could affect funding outcomes.
This is a high-complexity data component with a targeted but critical scope — it exists solely to serve the duplicate detection service. Development requires careful query optimization to avoid N+1 fetch patterns across the contact_chapters and activities tables, which means a developer with strong SQL and Supabase PostgREST experience should be assigned. Testing must cover edge cases like contacts affiliated with many chapters and large activity histories, requiring realistic test data seeding. The component has a single upstream dependency on the supabase-contact-chapter-adapter, so that adapter must be stable before integration testing begins.
Performance benchmarks should be established early since slow queries here directly degrade the activity submission UX.
This component executes a join-based query across contact_chapters and activities tables, filtered by contactId with an optional DateRange parameter. It is consumed exclusively by the duplicate detection service and must return a unified List
The fetchActivitiesByTypeForContact interface supports targeted lookups for specific activity types on a given date, optimizing the common duplicate check path. Both mobile and backend execution contexts must be supported, so query construction must be environment-agnostic and rely on the adapter layer for connection management.
Responsibilities
- Join contact_chapters with activities on contact_id
- Filter results by contact_id and configurable date range
- Return a unified list of activities regardless of originating chapter
- Optimize query to avoid N+1 fetches across chapters
Interfaces
fetchActivitiesForContactAcrossChapters(String contactId, {DateRange? range}) → Future<List<Activity>>
fetchActivitiesByTypeForContact(String contactId, String activityType, DateTime date) → Future<List<Activity>>
Relationships
Dependencies (1)
Components this component depends on
Dependents (1)
Components that depend on this component
Related Data Entities (3)
Data entities managed by this component