Service Layer low complexity backend
1
Dependencies
2
Dependents
0
Entities
0
Integrations

Description

Lightweight service that serialises the export payload as a UTF-8 CSV file. Acts as a simpler fallback before the Bufdir API is available. Ensures correct column headers matching Bufdir's expected fields.

Feature: Bufdir Report Export

csv-generation-service

Summaries

The CSV Generation Service provides an immediate, low-risk path to Bufdir reporting before the full API integration is negotiated and ratified. Organisations can begin exporting and manually submitting structured data files to Bufdir right away, ensuring reporting obligations are met on schedule without waiting for a more complex integration to be completed. This reduces compliance risk for NHF and its member organisations during the transition period. The service also acts as an independent verification tool: exported CSV files can be reviewed in standard spreadsheet software, allowing administrators to spot-check data quality before any submission is made.

CSV generation is the lowest-complexity output format in the export pipeline and is well-suited for delivery in the earliest sprint milestone to demonstrate end-to-end export capability to stakeholders. It shares a dependency on the Bufdir Category Mapper with the PDF and API submission paths. Key delivery considerations are correct UTF-8 encoding with BOM handling for Norwegian locale characters (æ, ø, å) which are frequently mishandled by naive CSV implementations, and column header alignment with Bufdir's latest published field specification. Testing should include opening the output file in both Excel and LibreOffice Calc to verify encoding and column structure.

Low maintenance burden once delivered; schema changes are isolated to the getHeaders() method.

The CSV Generation Service is a lightweight backend service that serialises the Bufdir export payload into a UTF-8 encoded CSV file with headers matching Bufdir's published field specification. It depends on the Bufdir Category Mapper to resolve activity type codes before serialisation. The generate(payload, metadata) interface produces the internal state; toCSVString() emits the final string; getHeaders() returns the ordered column array; and escapeField(value) handles RFC 4180 quoting plus Norwegian character encoding edge cases. Implement using a streaming approach for large payloads to avoid holding the full document in memory.

The generated content should be stored as a reference in the generated-report data model. Design the header/field mapping as a configuration array so future Bufdir column changes do not require logic refactoring — only the column definition needs updating.

Responsibilities

  • Serialize export payload to CSV with Bufdir-compatible headers
  • Handle special characters and Norwegian locale encoding
  • Return CSV string for download

Interfaces

generate(payload, metadata)
toCSVString()
getHeaders()
escapeField(value)

Relationships

Dependencies (1)

Components this component depends on

Dependents (2)

Components that depend on this component

API Contract

View full contract →
REST /api/v1/csv-generation 2 endpoints
POST /api/v1/csv-generation/generate Generate a CSV export from aggregated data
GET /api/v1/csv-generation/headers Get expected CSV column headers for Bufdir export format