Service Layer high complexity backend
2
Dependencies
1
Dependents
1
Entities
1
Integrations

Description

Computes participant and activity counts broken down by geographic organizational units (regions, local chapters) as required by Bufdir reporting. Handles the hierarchical org structure across all four organizations (e.g., NHF's 9 regions and 1,400 local chapters).

Feature: Bufdir Data Aggregation

geographic-distribution-service

Summaries

Bufdir requires not just total participant counts but a geographic breakdown showing activity distribution across regions and local chapters — this is the component that produces that breakdown. For an organization like NHF with 1,400 local chapters, correctly attributing activities to the right geographic unit is essential for demonstrating nationwide reach and meeting regional funding criteria. Errors in geographic attribution could misrepresent an organization's footprint to Bufdir, potentially affecting funding allocations tied to regional activity thresholds. By handling the full complexity of the hierarchical organizational structure, this service ensures that geographic reporting accurately reflects where communities are being served — a key metric for demonstrating social impact.

This is a high-complexity component with significant domain complexity beyond pure technical implementation. The organizational hierarchy — regions containing local chapters, with members potentially belonging to multiple chapters — creates edge cases that require careful specification before development begins. Engage domain experts from NHF specifically to document the chapter membership rules, since their scale (1,400 chapters) is the stress case. The validateChapterAssignments() interface suggests a data quality step that may need to surface issues to end users, implying a frontend dependency.

Plan for performance testing against NHF-scale data volumes, as geographic aggregation across 1,400 chapters will be the most query-intensive operation in the system. Do not underestimate the time required to get the resolveOrgUnitForActivity() mapping logic correct across all four organizations.

The service consumes data via AggregationQueryBuilder and enforces org isolation through MultiOrgDataIsolator. The resolveOrgUnitForActivity(activityId) method is the core lookup that maps each activity record to its place in the organizational hierarchy — this likely requires a join through an org_units or chapters table and must handle activities linked to chapters that have since been merged or archived. The buildGeographicBreakdownPayload() method must produce output conforming to Bufdir's expected geographic schema, so maintain a schema version reference in the implementation. The most subtle implementation challenge is the multi-chapter membership case: a member belonging to two local chapters who attends an activity must contribute to exactly one chapter's count — establish and document the tie-breaking rule (e.g., primary chapter wins) and enforce it consistently.

Consider materializing intermediate geographic lookups in a temporary structure during an aggregation run to avoid O(n) database calls per activity record.

Responsibilities

  • Group aggregated metrics by region and local chapter
  • Resolve organizational unit hierarchy for each activity record
  • Handle members belonging to multiple local chapters without double-counting
  • Produce geographic breakdown in Bufdir-compatible format

Interfaces

getDistributionByRegion(orgId, periodId)
getDistributionByLocalChapter(orgId, periodId)
resolveOrgUnitForActivity(activityId)
buildGeographicBreakdownPayload(distribution)
validateChapterAssignments(records)

Relationships

Dependencies (2)

Components this component depends on

Dependents (1)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/geographic-distributions 7 endpoints
GET /api/v1/geographic-distributions
GET /api/v1/geographic-distributions/:id
POST /api/v1/geographic-distributions
PUT /api/v1/geographic-distributions/:id
DELETE /api/v1/geographic-distributions/:id
GET /api/v1/geographic-distributions/by-region
+1 more