Service Layer medium complexity backend
1
Dependencies
1
Dependents
3
Entities
1
Integrations

Description

Records an immutable audit entry for every Bufdir export, capturing who triggered the export, the timestamp, organisation, period covered, format, and output file reference. Supports compliance requirements and re-download of previously generated exports.

Feature: Bufdir Reporting & Export

bufdir-export-audit-service

Summaries

The Export Audit Log Service provides a permanent, tamper-resistant record of every Bufdir compliance report generated by the platform. For organisations receiving public funding through NHF, the ability to demonstrate exactly who ran a report, when, for which period, and where the output file is stored is not optional — it is a compliance requirement. This service eliminates the risk of disputed submissions or missing export records during audits, directly protecting the organisation from funding clawback or regulatory penalties. It also enables staff to re-download previously generated exports without re-running the pipeline, reducing operational friction and supporting transparency with both Bufdir and internal governance stakeholders.

This is a medium-complexity backend service with a hard dependency on the bufdir-export-audit-repository component, which must be delivered first. The service wraps the repository with business logic for status transitions — pending, complete, failed — so both components should ideally be developed in the same sprint. Testing requirements include verifying that audit entries are always created before export processing begins, that status updates propagate correctly through lifecycle states, and that the export history query is performant under multi-year date ranges. A key project risk is ensuring the audit record is written atomically with export initiation so that no export ever runs without a corresponding audit trail.

Plan for a database migration script to create the audit log table in Supabase as part of the deployment checklist.

The Export Audit Log Service is a backend service component wrapping the bufdir-export-audit-repository with higher-level orchestration logic. It exposes five primary methods: `createAuditEntry` initialises a pending record at export start, `updateAuditStatus` drives the status state machine (pending → complete/failed), and `attachExportFile` stores the finalised file URL once the export output is persisted to storage. `getExportHistory` and `getExportRecord` support the UI history view and re-download flows. The service should enforce that status can only progress forward (no reverting complete to pending) and that audit records are immutable once marked complete — logic that complements the append-only semantics enforced at the repository layer.

Inject this service into the export orchestrator so that audit lifecycle calls bracket the entire export execution. Use the bufdir_export_audit_log data model for the underlying schema. Ensure all methods are transactional-safe given Supabase's Postgres backend.

Responsibilities

  • Create an audit record when an export is initiated
  • Update record status as export progresses (pending, complete, failed)
  • Store reference to the generated export file
  • Provide query interface for export history

Interfaces

createAuditEntry(ExportRequest request, String triggeredByUserId)
updateAuditStatus(String exportId, ExportStatus status)
attachExportFile(String exportId, String fileUrl)
getExportHistory(String orgId, DateRange? period)
getExportRecord(String exportId)

Relationships

Dependencies (1)

Components this component depends on

Dependents (1)

Components that depend on this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/bufdir-export-audit 6 endpoints
GET /api/v1/bufdir-export-audit Get export history for an organisation
GET /api/v1/bufdir-export-audit/:audit_id Get a single audit record
POST /api/v1/bufdir-export-audit Create a new audit entry when an export is initiated
PUT /api/v1/bufdir-export-audit/:audit_id/status Update audit record status
PUT /api/v1/bufdir-export-audit/:audit_id/file Attach a generated file URL to an audit record
DELETE /api/v1/bufdir-export-audit/:audit_id Delete an audit record (admin only)