Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt

Use this file to discover all available pages before exploring further.

Spec: specs/fa/specs/FA-22-accounts-payable-automation.md
Status: ๐Ÿ“ Planned
Constitution: ยง1.3 (Integration Patterns), ยง2.1 (Integration documentation)

Overview

FA-22 adds invoice scan/OCR, duplicate detection, and 3-way match automation. It integrates with PF-27 (Platform AI), FA-03/FA-04 (bills, POs, receipts), and FW-16 (workflow events).

Integration Points (from spec)

DependencyPatternPurpose
PF-27 (AI)Platform Layer (edge function)Document extraction in fa-scan-invoice; no PHI in prompts.
FA-03 / FA-04Same core (FA)Read fa_vendor_bills, fa_purchase_orders, fa_po_receipts; write/update fa_vendor_bills when linking scan or flagging duplicate.
FW-16Event-BasedPublish fa_bill_scan_completed, fa_bill_duplicate_flagged for workflow subscriptions.

Event Contracts (FW-16)

Channel: fa_events (or equivalent).
Subscribers: FW-16 (Workflow Events) โ€“ register event_type values below for workflow triggers.
Canonical event names use snake_case past-tense: fa_bill_scan_completed, fa_bill_duplicate_flagged. Full contracts: EVENT_CONTRACTS.md.

fa_bill_scan_completed

When: After invoice scan completes and result is stored in fa_invoice_scans. Payload schema (JSON):
FieldTypeRequiredDescription
event_typestringyes"fa_bill_scan_completed"
organization_iduuidyesTenant scope
timestampstring (ISO 8601)yesEvent time
user_iduuidnoWhen user-initiated
correlation_idstringnoWhen chaining events
scan_iduuidyesfa_invoice_scans.id
vendor_bill_iduuid | nullyesSet when linked to bill
confidence_scorenumberyesOCR confidence
scanned_textstringnoOptional extracted text
scan_statusstringnoe.g. success, partial
source_systemstringnoe.g. fa-scan-invoice
metadataobjectnoExtra key-value
Example payload:
{
  "event_type": "fa_bill_scan_completed",
  "organization_id": "550e8400-e29b-41d4-a716-446655440000",
  "timestamp": "2026-02-12T12:00:00Z",
  "user_id": "660e8400-e29b-41d4-a716-446655440001",
  "scan_id": "770e8400-e29b-41d4-a716-446655440002",
  "vendor_bill_id": null,
  "confidence_score": 0.92,
  "scan_status": "success",
  "source_system": "fa-scan-invoice"
}

fa_bill_duplicate_flagged

When: After duplicate detection creates a fa_duplicate_detection_log entry. Payload schema (JSON):
FieldTypeRequiredDescription
event_typestringyes"fa_bill_duplicate_flagged"
organization_iduuidyesTenant scope
timestampstring (ISO 8601)yesEvent time
user_iduuidnoWhen user-initiated
correlation_idstringnoWhen chaining (e.g. batch)
vendor_bill_iduuidyesBill that was flagged
suspected_duplicate_of_iduuidyesExisting bill it matches
match_scorenumberyesSimilarity score
match_reasonstringyesShort reason
log_iduuidyesfa_duplicate_detection_log.id
invoice_idstringnoInvoice number if available
detected_duplicatesarraynoOptional list of match ids
source_systemstringnoe.g. fa-detect-duplicates
metadataobjectnoExtra key-value
Example payload:
{
  "event_type": "fa_bill_duplicate_flagged",
  "organization_id": "550e8400-e29b-41d4-a716-446655440000",
  "timestamp": "2026-02-12T12:05:00Z",
  "vendor_bill_id": "880e8400-e29b-41d4-a716-446655440003",
  "suspected_duplicate_of_id": "990e8400-e29b-41d4-a716-446655440004",
  "match_score": 0.98,
  "match_reason": "Same vendor, amount within 2%, date within 30 days",
  "log_id": "aa0e8400-e29b-41d4-a716-446655440005",
  "source_system": "fa-detect-duplicates"
}

API / Edge Functions

  • fa-scan-invoice: Invokes PF-27 for extraction; writes to fa_invoice_scans and storage bucket fa-invoice-scans. No direct API contract with other cores; called from FA UI.
  • fa-detect-duplicates: Runs on bill insert or cron; writes fa_duplicate_detection_log. Internal to FA.
  • fa-auto-match-3way: Returns suggested matches for PO-Receipt-Bill; internal to FA or called from FA UI.

Security & Tenant Isolation

  • All FA-22 tables and storage bucket are scoped by organization_id.
  • PF-27 calls use edge function only; no PHI in prompts (anonymized identifiers if needed).
  • Event payloads include organization_id for subscriber filtering.

Cross-Core Integration Matrix

See CROSS_CORE_INTEGRATIONS.md: FA โ†’ FW-16 (Event) for fa_bill_scan_completed and fa_bill_duplicate_flagged.