Service Layer high complexity backend
5
Dependencies
2
Dependents
7
Entities
2
Integrations

Description

Abstract service layer implementing the AccountingExporter interface. Selects the correct org-specific exporter implementation (XledgerExporter or DynamicsExporter) at runtime based on organization configuration. Orchestrates the full export pipeline: query approved claims, map fields, generate output, mark claims as exported, and persist export run metadata.

Feature: Accounting System Export and Integration

accounting-exporter-service

Summaries

The Accounting Exporter Service is the engine that drives the entire financial export process, automating the translation of approved expense claims into formats that accounting systems can directly import. By abstracting the differences between Xledger and Microsoft Dynamics into a single orchestrated pipeline, it allows the business to support multiple accounting systems without duplicating processes or training coordinators on system-specific workflows. It also enforces double-export prevention as a built-in safeguard, protecting the organisation from the accounting errors and reconciliation costs that arise when claims are exported more than once. This component directly reduces finance team labour and audit risk.

This is the highest-complexity backend component in the export subsystem, orchestrating five dependencies: `xledger-exporter`, `dynamics-exporter`, `double-export-guard`, `approved-claims-query`, and `export-run-repository`. Its delivery is on the critical path — all export UI flows depend on it functioning correctly. Key risks include integration testing across both exporter implementations and ensuring the double-export guard is correctly invoked before any claim processing begins. The `retryFailedExport(exportRunId)` interface adds complexity around idempotency — ensure the retry path is thoroughly tested for partial failure scenarios.

Plan for end-to-end integration tests with both Xledger and Dynamics configurations. Deployment must be coordinated with all dependent services being available.

This service implements the AccountingExporter interface and uses a strategy pattern: `resolveExporter(orgId)` selects either `XledgerExporter` or `DynamicsExporter` based on org configuration at runtime. The primary entry point `exportApprovedClaims(orgId, dateRange, triggeredBy)` orchestrates the pipeline sequentially: invoke `double-export-guard` first (abort if duplicate detected), call `approved-claims-query` for eligible claims, delegate to the resolved exporter for field mapping and output generation, then persist results via `export-run-repository`. Returns a structured `ExportResult` with included and skipped claim lists. The `retryFailedExport(exportRunId)` path must be idempotent — load the original export run state and resume from failure point.

Handles `expense_claim` and `export_run` data models. Backend-only execution context; no UI concerns.

Responsibilities

  • Resolve the correct exporter implementation for the requesting organization
  • Invoke claim query, field mapping, and file generation in sequence
  • Delegate to double-export guard before processing claims
  • Return a structured ExportResult including included and skipped claim lists

Interfaces

exportApprovedClaims(orgId, dateRange, triggeredBy)
resolveExporter(orgId): AccountingExporter
getExportStatus(exportRunId)
retryFailedExport(exportRunId)

Used Integrations (2)

External integrations and APIs this component relies on