Data Layer high complexity mobilebackend
1
Dependencies
1
Dependents
3
Entities
0
Integrations

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.

Feature: Multi-Chapter Membership Handling

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 regardless of which chapter originated each activity. The primary implementation challenge is avoiding N+1 fetches — the query must use a single Supabase PostgREST join (e.g., select with embedded resource or RPC) rather than iterating chapters. It depends on supabase-contact-chapter-adapter for raw query execution.

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

API Contract

View full contract →
REST /api/v1/activities 7 endpoints
GET /api/v1/activities List all activities across chapters
GET /api/v1/activities/:id Get a specific activity by ID
POST /api/v1/activities Create a new activity record
PUT /api/v1/activities/:id Update an activity record
DELETE /api/v1/activities/:id Delete an activity record
GET /api/v1/activities/contact/:contactId/across-chapters Fetch all activities for a contact across all chapters, with optional date range
+1 more