medium priority low complexity documentation pending documentor Tier 5

Acceptance Criteria

Documentation covers all five services: BufdirActivityQueryService, BufdirColumnMappingService, BufdirExcelCsvGenerator, BufdirPdfGenerator, BufdirAttachmentBundler
Each service section includes: class/interface definition with all public methods, parameter types and descriptions, return types, and thrown exceptions
A data flow diagram (ASCII or Mermaid format) illustrates the full pipeline: query → column mapping → file generation → bundling → delivery
Error handling contract section specifies which exceptions each service throws, under what conditions, and how callers should handle them
Integration guide section provides a complete orchestrator code example showing how to invoke all five services in sequence
Each service section includes at least one runnable Dart code example demonstrating the primary use case
Documentation is in English throughout
Documentation file is located at docs/bufdir-export-services.md within the project repository

Technical Requirements

frameworks
Dart dartdoc conventions
Mermaid (for data flow diagrams)
apis
Supabase Storage API (referenced in BufdirAttachmentBundler and delivery sections)
data models
BufdirActivityRecord
BufdirColumnMapping
BufdirExportArtifact
BufdirBundleManifest
BufdirReportingPeriod
performance requirements
Document the 5-second query SLA from task-017 in the BufdirActivityQueryService section
Document batch size recommendations for large exports
security requirements
Document that service role key is required for storage write operations
Note RLS policy requirements for each service's database interactions
Document signed URL expiry expectations for delivery artifacts

Execution Context

Execution Tier
Tier 5

Tier 5 - 253 tasks

Can start after Tier 4 completes

Implementation Notes

Structure the documentation file as follows: (1) Overview — purpose of the epic, Bufdir reporting context, pipeline summary; (2) Data Flow Diagram — Mermaid sequenceDiagram or flowchart showing the 5-stage pipeline; (3) Service Reference sections (one per service) — interface definition, parameters, return values, error handling, code example; (4) Integration Guide — complete orchestrator pattern showing services wired together; (5) Error Handling Reference — consolidated table of all exceptions across services. For code examples, use realistic but synthetic data (no real org names). Mermaid is preferred over ASCII for diagrams as it renders natively in GitHub and most documentation platforms. When documenting error contracts, distinguish between recoverable errors (e.g., missing attachment → logged, excluded) and fatal errors (e.g., database connection failure → exception propagated).

The integration guide example should mirror the pattern the orchestrator epic will actually use — coordinate with the orchestrator epic author to ensure alignment before finalizing.

Testing Requirements

No automated tests required for documentation tasks. Manual review checklist: (1) verify all public method signatures match current source code; (2) confirm code examples compile without errors by running dart analyze on snippets; (3) confirm Mermaid diagram renders correctly in GitHub Markdown preview; (4) peer review by one other developer who was not the author to confirm clarity and completeness.

Component
Bufdir API Integration Service (Future)
service medium
Epic Risks (3)
high impact medium prob technical

NHF contacts can belong to up to five local chapters simultaneously. If the deduplication logic in the activity query service incorrectly attributes cross-chapter activities, organisations will either under-report or over-report to Bufdir, which could trigger grant clawback or compliance investigations.

Mitigation & Contingency

Mitigation: Implement deduplication using the existing multi-chapter membership service as the source of truth for chapter affiliation. Write test fixtures covering all known multi-chapter edge cases and validate outputs against manually prepared reference exports from NHF.

Contingency: If deduplication cannot be made deterministic for complex hierarchies before release, gate the export behind an org-level feature flag and require NHF to validate a preview export against their manual Excel before enabling in production.

medium impact medium prob dependency

Server-side Dart libraries for Excel generation are less mature than equivalents in Node.js or Python. The chosen library may lack support for Bufdir-required formatting features (merged cells, data validation, specific date formats), requiring significant workaround effort or a library switch mid-implementation.

Mitigation & Contingency

Mitigation: Evaluate the top two Dart xlsx libraries (excel, spreadsheet_decoder) against a Bufdir template sample file before committing. Identify all required formatting features and verify library support in a spike.

Contingency: If no Dart library meets requirements, implement the Excel generation as a Supabase Edge Function in TypeScript using the well-supported ExcelJS library, exposing it to the Dart backend via an internal RPC call.

medium impact medium prob integration

The attachment bundler must retrieve documents from Supabase Storage that were uploaded by the document attachments feature. If storage paths, RLS policies, or signed URL expiry have not been standardised across features, the bundler may fail to retrieve attachments at export time.

Mitigation & Contingency

Mitigation: Audit the document attachments feature's storage schema and RLS policies before implementing the bundler. Agree on a stable internal service-account access pattern for cross-feature storage reads.

Contingency: If cross-feature storage access cannot be made reliable, implement the bundler to include only attachments that can be retrieved successfully and produce a manifest listing any attachments that could not be bundled, rather than failing the entire export.