Service Layer high complexity mobilebackend
4
Dependencies
1
Dependents
1
Entities
1
Integrations

Description

Central service orchestrating the entire Bufdir export workflow. Calls the Supabase Edge Function with org_id, scope_id, and date range, receives the structured JSON payload, passes it to format generators, and persists the export record.

Feature: Bufdir Report Export

bufdir-export-service

Summaries

The Bufdir Export Service is the commercial centrepiece of the reporting capability — it is the single component that transforms raw activity data into a government-compliant Bufdir submission. By fully automating the aggregation, formatting, and delivery of regulatory reports, it eliminates dozens of hours of manual data compilation per reporting period for every organisation using the platform. This directly reduces operational costs, mitigates compliance risk from human error in manual reporting, and positions the product as a must-have tool for NHF-affiliated organisations subject to Bufdir reporting requirements. Its reliability directly determines whether clients meet statutory deadlines.

This is the highest-complexity component in the export feature and the critical path item for the entire Bufdir reporting milestone. It has four direct dependencies: the Supabase Edge Function, PDF and CSV generation services, and the generated-reports-repository — all of which must be stable before end-to-end testing can complete. Plan for integration testing to be the longest phase. Delivery risks include edge function latency under load, format generator failures for large datasets, and retry logic for failed exports.

Build retryFailedExport(reportId) and cancelExport() early to give QA a recovery path during testing. Allocate extra buffer time for network failure scenarios and partial export recovery.

This service acts as the orchestration layer for the export pipeline. previewExport(params) calls the edge function with a preview flag to return aggregated data without persisting a report record, while generateExport(params, format) triggers a full export run. The service passes org_id, scope_id, and date range to the Supabase Edge Function and receives a structured JSON payload, which is then routed to pdf-generation-service or csv-generation-service based on the selected format. On success, it calls generated-reports-repository to persist the export record.

cancelExport() must handle in-flight HTTP cancellation. Implement exponential backoff in retryFailedExport(reportId). The service runs in both mobile and backend contexts — ensure the mobile client calls only the public interface methods and never directly accesses the edge function.

Responsibilities

  • Invoke Supabase Edge Function with export parameters
  • Coordinate preview vs. finalised export flows
  • Route output to PDF or CSV generator
  • Persist export record in generated_reports

Interfaces

previewExport(params)
generateExport(params, format)
downloadExport(reportId)
cancelExport()
getExportHistory(scopeId)
retryFailedExport(reportId)

Relationships

Dependencies (4)

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/bufdir-exports 4 endpoints
POST /api/v1/bufdir-exports/preview Preview export before generation
POST /api/v1/bufdir-exports/generate Trigger full export generation
GET /api/v1/bufdir-exports/:report_id/download Download a completed export by report ID
DELETE /api/v1/bufdir-exports/:report_id/cancel Cancel an in-progress export