Service Layer medium complexity Shared Component backend
1
Dependencies
2
Dependents
1
Entities
0
Integrations

Description

Manages the definition and boundaries of Bufdir reporting periods (typically annual). Determines which activity records fall within a given period and exposes period metadata needed by aggregation and export steps.

Feature: Bufdir Data Aggregation

reporting-period-service

Summaries

The Reporting Period Service establishes the precise time boundaries that determine which activities count toward each Bufdir submission. Without accurate period definitions, organizations risk including out-of-scope data in official reports or missing activities that should be counted — both of which create compliance exposure. By centralizing period management, this component ensures all four partner organizations operate on consistent, auditable reporting windows, supporting clean historical comparisons year over year. Its ability to support re-aggregation over historical periods also means that if source data corrections are made after initial submission, corrected reports can be generated without manual date filtering, reducing the administrative cost of amendments.

This is a medium-complexity shared component that serves as a foundational dependency for both the aggregation pipeline and the export workflow. Because virtually every other data query in the reporting feature is scoped by a reporting period ID, this component should be delivered and tested early in the sprint sequence — it is a blocking dependency even though it carries medium complexity. The createReportingPeriod() and closeReportingPeriod() interfaces suggest an administrative workflow that needs to be coordinated with the product team to define who can create/close periods and whether any approval gates exist. The multi-organization scope (each org maintains its own periods) requires careful testing of period isolation to ensure Organization A's closed period doesn't affect Organization B's active aggregation.

The service wraps the BufdirMetricsRepository for period metadata persistence and exposes a clean domain interface to callers. The isWithinPeriod(date, periodId) method is called frequently during aggregation filtering and should be optimized — consider caching period boundary lookups in memory for the duration of an aggregation run to avoid repeated database reads. The listReportingPeriods(orgId) method supports historical re-aggregation by providing the full period history per organization. The closeReportingPeriod() call should enforce a state machine transition (open → closed) with database-level constraints to prevent mutation of closed-period data.

Ensure period start/end dates are stored and compared in UTC to avoid timezone edge cases when organizations span multiple time zones. The getCurrentReportingPeriod() method needs a defined behavior when no active period exists — return null or throw — document this contract explicitly for callers.

Responsibilities

  • Define and store reporting period start/end dates per organization
  • Filter activity records by reporting period boundary
  • Provide current active reporting period for each organization
  • Support historical period lookups for re-aggregation

Interfaces

getCurrentReportingPeriod(orgId)
getReportingPeriodById(periodId)
listReportingPeriods(orgId)
isWithinPeriod(date, periodId)
createReportingPeriod(orgId, startDate, endDate)
closeReportingPeriod(periodId)

Relationships

Dependencies (1)

Components this component depends on

Dependents (2)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/reporting-periods 7 endpoints
GET /api/v1/reporting-periods
GET /api/v1/reporting-periods/current
GET /api/v1/reporting-periods/:id
POST /api/v1/reporting-periods
PUT /api/v1/reporting-periods/:id
DELETE /api/v1/reporting-periods/:id
+1 more