Infrastructure medium complexity backend
0
Dependencies
0
Dependents
0
Entities
0
Integrations

Description

Generates Excel (.xlsx) and CSV export files from mapped Bufdir rows. Uses a server-side Dart library to produce formatted spreadsheets with correct column headers, data types, and Bufdir-required formatting conventions.

Feature: Bufdir Reporting & Export

bufdir-excel-csv-generator

Summaries

The Excel and CSV File Generator directly enables compliance with Norway's Bufdir reporting mandate by producing submission-ready export files in the exact format the government agency requires. Without this component, organisations would face manual data re-entry into spreadsheet templates — a time-consuming, error-prone process that risks rejected submissions and potential funding consequences. By automating format compliance, including correct column headers, data types, date formats, and decimal separators per organisation, the platform eliminates a significant administrative burden and reduces submission errors to near zero. This translates to faster reporting cycles, lower staffing costs per submission, and increased confidence that regulatory obligations are met consistently across all client organisations.

This is a backend service component of medium complexity, implemented in server-side Dart using a spreadsheet library. Development must account for Bufdir's evolving column schema, meaning the component should be built with schema-driven configuration rather than hard-coded column definitions. Key dependencies are the data mapping pipeline that produces MappedRow objects and the BufdirColumnSchema definition — both must be stable before file generation can be validated end-to-end. Testing requires representative Bufdir datasets covering edge cases such as missing values, special characters, and per-org formatting variations.

Acceptance criteria must include validation against Bufdir's official import tool. Delivery risk is low-to-medium; the main risk is schema drift if Bufdir updates their template mid-sprint.

This backend Dart component exposes four primary interfaces: generateExcel(), generateCsv(), applyFormatting(), and getFileBytes(). It consumes List and a BufdirColumnSchema, applying per-org rules for date formats and decimal separators before serialising to bytes. The Excel output uses a server-side Dart xlsx library (e.g., excel package) to construct worksheets with typed cell values and column width hints. CSV output must handle delimiter and UTF-8 BOM encoding per Bufdir's requirements.

The component is stateless and returns raw Uint8List bytes, leaving file storage to the Export File Storage Adapter. Schema changes in Bufdir's template must be reflected in BufdirColumnSchema — the component itself should require no logic changes, only schema updates, making it resilient to reporting period changes.

Responsibilities

  • Produce .xlsx files with correct headers, column widths, and data formatting
  • Produce .csv files with correct delimiter and encoding for Bufdir's template
  • Apply per-org formatting rules (date format, decimal separator)
  • Return generated file as byte stream for upload to Supabase Storage

Interfaces

generateExcel(List<MappedRow> rows, BufdirColumnSchema schema)
generateCsv(List<MappedRow> rows, BufdirColumnSchema schema)
applyFormatting(Worksheet sheet, BufdirColumnSchema schema)
getFileBytes()

API Contract

View full contract →
REST /api/v1/bufdir-file-generation 3 endpoints
POST /api/v1/bufdir-file-generation/excel Generate an Excel file from mapped rows
POST /api/v1/bufdir-file-generation/csv Generate a CSV file from mapped rows
GET /api/v1/bufdir-file-generation/:export_id/download Download generated file bytes