# process-intelligence1/ar-remittance-ptp architecture

> Architecture diagram of the GitHub repository process-intelligence1/ar-remittance-ptp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/process-intelligence1/ar-remittance-ptp
- Repository: https://github.com/process-intelligence1/ar-remittance-ptp

## Overview

This is an end-to-end AR remittance and promise-to-pay control tower. Customer email enters through Gmail, is stored and parsed, classified, extracted into invoice lines, matched against SAP open items, and surfaced to AR users for review and action with audit history. The graph also preserves dashboard, knowledge-base, PTP, demo, and snapshot capabilities. Some subsystem links rely on the SOURCE INDEX or README because their implementation excerpts were not provided; uncertain links are omitted.

Main entry points: [`frontend/src/App.tsx`](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/App.tsx) (Workbench shell), [`backend/app/pipeline.py`](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/pipeline.py) (Pipeline orchestrator), [`backend/app/gmail/poller.py`](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/gmail/poller.py) (Gmail poller), [`frontend/src/data/index.ts`](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/index.ts) (Data source adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Email intake"]
  node_poller["Gmail poller<br/>[poller.py]"]
  node_gmailclient["Gmail client<br/>[client.py]"]
  node_storage[("Email file storage<br/>[storage.py]")]
end

subgraph group_processing["Document processing"]
  node_pipeline["Pipeline orchestrator<br/>[pipeline.py]"]
  node_documents["Document reading<br/>[service.py]"]
  node_docformats["OCR and format parsers"]
  node_classification["Email classification<br/>[service.py]"]
  node_extraction["Invoice extraction<br/>[service.py]"]
  node_extractlogic["Extraction logic<br/>[extractor.py]"]
end

subgraph group_ar["AR matching"]
  node_matching["Work item matching<br/>[service.py]"]
  node_matchlogic["Candidate scoring<br/>[matcher.py]"]
  node_sap[("SAP reference data<br/>[sap.py]")]
  node_ptp["PTP commitments<br/>[ptp.py]"]
end

subgraph group_backend["API and state"]
  node_worker["Scheduled worker<br/>[worker.py]"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_workapi["Work item API<br/>[workitems.py]"]
  node_authapi["Authentication API<br/>[auth.py]"]
  node_ardb[("AR application data<br/>[ar.py]")]
  node_outbound["Outbound email<br/>[outbound.py]"]
  node_rules["Knowledge base rules<br/>[rules_defaults.py]"]
end

subgraph group_frontend["AR workbench"]
  node_app["Workbench shell<br/>[App.tsx]"]
  node_auth["Session context<br/>[AuthContext.tsx]"]
  node_datasource["Data source adapter<br/>[index.ts]"]
  node_live["Live API adapter<br/>[live.ts]"]
  node_queue["Action queue<br/>[Queue.tsx]"]
  node_detail["Case detail<br/>[RecordDetail.tsx]"]
  node_dashboard["Dashboard<br/>[Dashboard.tsx]"]
  node_audit["Audit view<br/>[Audit.tsx]"]
  node_knowledge["Knowledge base view<br/>[KnowledgeBase.tsx]"]
  node_ptpview["PTP view<br/>[RecordDetail.tsx]"]
  node_labels["Display labels<br/>[labels.ts]"]
end

node_customer(("Customer email"))
node_gmail(("Gmail inbox"))
node_user(("AR operator"))

node_customer -->|"sends email"| node_gmail
node_gmail -->|"provides messages"| node_poller
node_poller -->|"uses client"| node_gmailclient
node_poller -->|"stores files"| node_storage
node_worker -->|"runs polling"| node_poller
node_worker -->|"runs processing"| node_pipeline
node_pipeline -->|"runs reading"| node_documents
node_pipeline -->|"runs classification"| node_classification
node_pipeline -->|"runs extraction"| node_extraction
node_pipeline -->|"runs matching"| node_matching
node_documents -->|"uses parsers"| node_docformats
node_extraction -->|"calls extractor"| node_extractlogic
node_matching -->|"calls matcher"| node_matchlogic
node_matching -->|"loads reference data"| node_sap
node_pipeline -->|"records stage state"| node_ardb
node_matching -->|"saves work items"| node_ardb
node_poller -->|"saves email records"| node_ardb
node_poller -->|"attaches replies"| node_outbound
node_worker -->|"runs PTP work"| node_ptp
node_api -->|"registers route"| node_workapi
node_api -->|"registers route"| node_authapi
node_workapi -->|"reads and updates"| node_ardb
node_workapi -->|"serves file access"| node_storage
node_user -->|"uses workbench"| node_app
node_app -->|"provides session"| node_auth
node_app -->|"creates source"| node_datasource
node_auth -->|"sets token"| node_datasource
node_datasource -->|"selects live source"| node_live
node_live -->|"calls API"| node_api
node_app -->|"routes to queue"| node_queue
node_app -->|"routes to dashboard"| node_dashboard
node_app -->|"routes to audit"| node_audit
node_app -->|"routes to rules"| node_knowledge
node_queue -.->|"loads work items"| node_datasource
node_detail -->|"loads case data"| node_datasource
node_detail -.->|"shows commitments"| node_ptpview
node_dashboard -->|"loads metrics"| node_datasource
node_knowledge -.->|"manages rules"| node_rules
node_app -->|"uses labels"| node_labels

click node_poller "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/gmail/poller.py"
click node_gmailclient "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/gmail/client.py"
click node_storage "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/storage.py"
click node_pipeline "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/pipeline.py"
click node_documents "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/documents/service.py"
click node_docformats "https://github.com/process-intelligence1/ar-remittance-ptp/tree/main/backend/app/documents"
click node_classification "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/classification/service.py"
click node_extraction "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/extraction/service.py"
click node_extractlogic "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/extraction/extractor.py"
click node_matching "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/matching/service.py"
click node_matchlogic "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/matching/matcher.py"
click node_sap "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/models/sap.py"
click node_ptp "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/ptp.py"
click node_worker "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/worker.py"
click node_api "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/main.py"
click node_workapi "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/api/workitems.py"
click node_authapi "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/api/auth.py"
click node_ardb "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/models/ar.py"
click node_outbound "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/outbound.py"
click node_rules "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/rules_defaults.py"
click node_app "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/App.tsx"
click node_auth "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/auth/AuthContext.tsx"
click node_datasource "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/index.ts"
click node_live "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/live.ts"
click node_queue "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/Queue.tsx"
click node_detail "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/RecordDetail.tsx"
click node_dashboard "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/Dashboard.tsx"
click node_audit "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/Audit.tsx"
click node_knowledge "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/KnowledgeBase.tsx"
click node_ptpview "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/RecordDetail.tsx"
click node_labels "https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/labels.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_poller,node_gmailclient,node_storage toneBlue
class node_pipeline,node_documents,node_docformats,node_classification,node_extraction,node_extractlogic toneAmber
class node_matching,node_matchlogic,node_sap,node_ptp toneMint
class node_worker,node_api,node_workapi,node_authapi,node_ardb,node_outbound,node_rules toneRose
class node_app,node_auth,node_datasource,node_live,node_queue,node_detail,node_dashboard,node_audit,node_knowledge,node_ptpview,node_labels,node_customer,node_gmail,node_user toneIndigo
```

## Components

### Email intake

- [Gmail poller](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/gmail/poller.py): `backend/app/gmail/poller.py`
- [Gmail client](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/gmail/client.py): `backend/app/gmail/client.py`
- [Email file storage](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/storage.py): `backend/app/storage.py`

### Document processing

- [Pipeline orchestrator](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/pipeline.py): `backend/app/pipeline.py`
- [Document reading](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/documents/service.py): `backend/app/documents/service.py`
- [OCR and format parsers](https://github.com/process-intelligence1/ar-remittance-ptp/tree/main/backend/app/documents): `backend/app/documents`
- [Email classification](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/classification/service.py): `backend/app/classification/service.py`
- [Invoice extraction](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/extraction/service.py): `backend/app/extraction/service.py`
- [Extraction logic](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/extraction/extractor.py): `backend/app/extraction/extractor.py`

### AR matching

- [Work item matching](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/matching/service.py): `backend/app/matching/service.py`
- [Candidate scoring](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/matching/matcher.py): `backend/app/matching/matcher.py`
- [SAP reference data](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/models/sap.py): `backend/app/models/sap.py`
- [PTP commitments](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/ptp.py): `backend/app/ptp.py`

### API and state

- [Scheduled worker](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/worker.py): `backend/app/worker.py`
- [FastAPI routes](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/main.py): `backend/app/main.py`
- [Work item API](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/api/workitems.py): `backend/app/api/workitems.py`
- [Authentication API](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [AR application data](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/models/ar.py): `backend/app/models/ar.py`
- [Outbound email](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/outbound.py): `backend/app/outbound.py`
- [Knowledge base rules](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/backend/app/rules_defaults.py): `backend/app/rules_defaults.py`

### AR workbench

- [Workbench shell](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Session context](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/auth/AuthContext.tsx): `frontend/src/auth/AuthContext.tsx`
- [Data source adapter](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/index.ts): `frontend/src/data/index.ts`
- [Live API adapter](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/live.ts): `frontend/src/data/live.ts`
- [Action queue](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/Queue.tsx): `frontend/src/pages/Queue.tsx`
- [Case detail](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/RecordDetail.tsx): `frontend/src/pages/RecordDetail.tsx`
- [Dashboard](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/Dashboard.tsx): `frontend/src/pages/Dashboard.tsx`
- [Audit view](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/Audit.tsx): `frontend/src/pages/Audit.tsx`
- [Knowledge base view](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/KnowledgeBase.tsx): `frontend/src/pages/KnowledgeBase.tsx`
- [PTP view](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/pages/RecordDetail.tsx): `frontend/src/pages/RecordDetail.tsx`
- [Display labels](https://github.com/process-intelligence1/ar-remittance-ptp/blob/main/frontend/src/data/labels.ts): `frontend/src/data/labels.ts`

### Other components

- **Customer email**
- **Gmail inbox**
- **AR operator**

## Connections

- Customer email → Gmail inbox: sends email
- Gmail inbox → Gmail poller: provides messages (evidence: `backend/app/gmail/poller.py`)
- Gmail poller → Gmail client: uses client (evidence: `backend/app/gmail/poller.py`)
- Gmail poller → Email file storage: stores files (evidence: `backend/app/gmail/poller.py`)
- Scheduled worker → Gmail poller: runs polling (evidence: `backend/app/worker.py`)
- Scheduled worker → Pipeline orchestrator: runs processing (evidence: `backend/app/worker.py`)
- Pipeline orchestrator → Document reading: runs reading (evidence: `backend/app/pipeline.py`)
- Pipeline orchestrator → Email classification: runs classification (evidence: `backend/app/pipeline.py`)
- Pipeline orchestrator → Invoice extraction: runs extraction (evidence: `backend/app/pipeline.py`)
- Pipeline orchestrator → Work item matching: runs matching (evidence: `backend/app/pipeline.py`)
- Document reading → OCR and format parsers: uses parsers (evidence: `backend/app/documents/service.py`)
- Invoice extraction → Extraction logic: calls extractor (evidence: `backend/app/extraction/service.py`)
- Work item matching → Candidate scoring: calls matcher (evidence: `backend/app/matching/service.py`)
- Work item matching → SAP reference data: loads reference data (evidence: `backend/app/matching/service.py`)
- Pipeline orchestrator → AR application data: records stage state (evidence: `backend/app/pipeline.py`)
- Work item matching → AR application data: saves work items (evidence: `backend/app/matching/service.py`)
- Gmail poller → AR application data: saves email records (evidence: `backend/app/gmail/poller.py`)
- Gmail poller → Outbound email: attaches replies (evidence: `backend/app/gmail/poller.py`)
- Scheduled worker → PTP commitments: runs PTP work (evidence: `backend/app/worker.py`)
- FastAPI routes → Work item API: registers route (evidence: `backend/app/main.py`)
- FastAPI routes → Authentication API: registers route (evidence: `backend/app/main.py`)
- Work item API → AR application data: reads and updates (evidence: `backend/app/api/workitems.py`)
- Work item API → Email file storage: serves file access (evidence: `backend/app/api/workitems.py`)
- AR operator → Workbench shell: uses workbench (evidence: `frontend/src/App.tsx`)
- Workbench shell → Session context: provides session (evidence: `frontend/src/App.tsx`)
- Workbench shell → Data source adapter: creates source (evidence: `frontend/src/App.tsx`)
- Session context → Data source adapter: sets token (evidence: `frontend/src/auth/AuthContext.tsx`)
- Data source adapter → Live API adapter: selects live source (evidence: `frontend/src/data/index.ts`)
- Live API adapter → FastAPI routes: calls API
- Workbench shell → Action queue: routes to queue (evidence: `frontend/src/App.tsx`)
- Workbench shell → Dashboard: routes to dashboard (evidence: `frontend/src/App.tsx`)
- Workbench shell → Audit view: routes to audit (evidence: `frontend/src/App.tsx`)
- Workbench shell → Knowledge base view: routes to rules (evidence: `frontend/src/App.tsx`)
- Action queue → Data source adapter: loads work items
- Case detail → Data source adapter: loads case data (evidence: `frontend/src/pages/RecordDetail.tsx`)
- Case detail → PTP view: shows commitments (evidence: `frontend/src/pages/RecordDetail.tsx`)
- Dashboard → Data source adapter: loads metrics (evidence: `frontend/src/pages/Dashboard.tsx`)
- Knowledge base view → Knowledge base rules: manages rules
- Workbench shell → Display labels: uses labels (evidence: `frontend/src/App.tsx`)
