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

Description

Server-side service that renders the structured Bufdir export payload into a formatted PDF document. Runs inside the Supabase Edge Function to avoid client-side memory constraints. Produces a downloadable binary that the client saves locally.

Feature: Bufdir Report Export

pdf-generation-service

Summaries

The PDF Generation Service allows NHF administrators to produce an official, professionally formatted Bufdir report that can be submitted or archived without any additional formatting work. By running entirely server-side inside the Supabase Edge Function, it avoids the memory and performance limitations of browser-based PDF rendering, ensuring that even large national-scope reports covering thousands of activities are generated reliably. The output is a ready-to-submit document that includes organisation branding, reporting period metadata, and a unique report identifier, giving auditors and Bufdir reviewers confidence in the document's provenance and completeness.

PDF generation is a medium-complexity component with a hard dependency on the Bufdir Category Mapper completing its mapping validation before rendering can succeed. The primary delivery risk is library selection for server-side PDF rendering within the Supabase Edge Function environment, which has runtime size and dependency constraints not present in a standard Node.js server. Proof-of-concept testing of the chosen PDF library against Edge Function limits should be scheduled before full implementation begins. Testing must cover large payloads (national-scope exports), correct handling of Norwegian characters, table pagination across page breaks, and consistent rendering across the PDF viewer landscape used by Bufdir reviewers.

The PDF Generation Service is a backend service running inside a Supabase Edge Function that transforms a structured Bufdir export payload into a binary PDF document. It depends on the Bufdir Category Mapper to ensure all activity types are correctly labelled before rendering. The generate(payload, metadata) interface is the entry point; internally it calls renderTable for the activity data grid, addHeader for org name and reporting period, and addFooter for generation timestamp and reportId, then returns raw bytes via toBytes(). Choose a PDF library compatible with Deno/Edge Function constraints (e.g., pdf-lib or jsPDF server-side).

The returned binary is streamed back to the client as an application/pdf response. Store a reference in the generated-report data model for audit trail purposes. Design the rendering pipeline to be table-driven so that future Bufdir column schema changes only require payload structure updates, not renderer refactoring.

Responsibilities

  • Render Bufdir data payload as a formatted PDF
  • Apply organisation branding and report metadata
  • Return PDF binary to client for download

Interfaces

generate(payload, metadata)
renderTable(data)
addHeader(org, period, scope)
addFooter(generatedAt, reportId)
toBytes()

Relationships

Dependencies (1)

Components this component depends on

Dependents (2)

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/pdf-generation 1 endpoints
POST /api/v1/pdf-generation/generate Generate a PDF report from aggregated export data