Architecture Note · Security & Compliance
Deterministic GHG Accounting & EU CSRD Audit Architecture
How a FastAPI and SQLite ledger enforces versioned Scope 1–3 calculations, ESRS E1–S1 gap tracking, and dual Sustainability and Controller sign-off locks for external limited assurance.
The Operational Problem: Unverifiable Spreadsheets Behind Statutory CSRD Audits
Sustainability teams, corporate controllers, and supply-chain ESG leads face a statutory tie-out problem under the EU Corporate Sustainability Reporting Directive (CSRD) and ISSB standards. Activity data arrives fragmented across global facilities—utility electricity invoices in kWh, fleet diesel logs, maritime freight tonne-kilometres, and accounts-payable procurement spend across hubs from Frankfurt and Zurich to Tokyo, Singapore, and Toronto. When emissions inventories live in ad-hoc spreadsheets, external limited-assurance auditors cannot trace a reported tCO2e figure back to its emission-factor version, contractual renewable certificate, and underlying proof document, while Scope 3 reporting remains distorted by generic spend-based estimates.
Why Naive AI Wrappers Fail in GHG & CSRD Assurance
Sending raw utility bills and supplier ledgers to a generic LLM prompt breaks financial-grade carbon accounting along four predictable fault lines:
- Nondeterministic emissions math: Language models approximate unit conversions and blend outdated grid factors with supplier numbers, producing totals that cannot reproduce an exact
activity_value × factor_value = tCO2eaudit trail. - Conflated Scope 2 and Scope 3 baselines: Naive summaries collapse Scope 2 Market-based reporting (RECs, PPAs, and Guarantees of Origin) into Location-based grid averages, or leave Scope 3 Categories 1–15 locked to flat spend-based EEIO multipliers without separating data-refinement effects from physical abatement.
- Unsupervised supplier outreach and data egress: Allowing an automated agent to email, SMS, or cold-call Tier-1 vendors over unapproved channels creates compliance risk, while retaining uploaded invoices in third-party cloud logs exposes sensitive procurement spend.
- Uncontrolled period mutations: Without a cryptographic cutoff gate, late invoice corrections silently alter prior-quarter baselines after finance has prepared external assurance disclosures.
The Deterministic Architecture That Fixes It
A production ESG and CSRD ledger isolates deterministic accounting, versioned factor registries, and human sign-off gates inside a FastAPI and SQLite (WAL mode) backend:
- Versioned GHG Calculation Engine:
POST /api/ghg/calculateandGET /api/ghg/factorsoperate behind tenant-scoped invite tokens (scripts/mint_invite.py) with sliding-window rate limits, ingesting JSON batches or temporary multipart CSV/JSON uploads inESG_UPLOAD_DIRwith automatic 1-hour (3600s) auto-wipe. Calculations execute against versionedemission_factorstables in SQLite (EPA eGRID,DEFRA,IEA,Ecoinvent,US EEIO,EXIOBASE,PCAF), computing Scope 1 combustion, dual Scope 2 Location-based and Market-basedtCO2e, and Scope 3 Categories 1–15 withsupplier_specificprimary EPD overrides. - ESRS E1–S1 Double Materiality & Gated Outreach:
POST /api/csrd/assessscores quantitative datapoint coverage across ESRSE1–E5andS1againstesrs_datapoint_rulesthresholds and defaults toOfflineDeterministicAdapterwith zero external API keys required. Missing supplier datapoints generate structured primary-data requests restricted to verified Supplier Portal links or opt-in Official WhatsApp Business Cloud API workflows after explicit ESG-lead attestation. - EEIO vs. Supplier EPD Abatement Modeling: Across Logistics (
4,180 tCO2eEEIO vs.3,120 tCO2esupplier EPD), Cloud Infra (2,480vs.1,390 tCO2e), and Tier-1 Manufacturing (7,640vs.5,490 tCO2e), the comparator separates primary-data refinement from physical renewable PPA and clean-fleet abatement against internal carbon shadow pricing. - Dual Human Assurance Lock & Provenance Export:
POST /api/reports/{period}/assureenforcesHTTP 409 Conflictunless bothsustainability_lead_approved=trueandfinance_controller_approved=trueplusconfirm_assurance_lock=trueare submitted. Once locked, new calculations against that period fail closed withHTTP 409, aninventory_sha256is recorded inperiod_assurancesand SHA-256 hash-chainedaudit_logs, andGET /api/ghg/audit-trail(oraudit-trail.csv) exports full provenance with OWASP RFC 4180 formula-injection sanitization andpytest-verified math.
Operational Takeaway
External CSRD assurance requires reproducible arithmetic, not fluent summaries. When emission factors are version-locked in SQLite, Scope 2 dual reporting and Scope 3 EPD overrides preserve full formula provenance, supplier campaigns require human approval, and period cutoffs lock behind Sustainability and Finance Controller sign-off, teams cut audit tie-out friction without risking unverified numbers.