# allaingaye/paypilot-shield architecture

> Architecture diagram of the GitHub repository allaingaye/paypilot-shield, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/allaingaye/paypilot-shield
- Repository: https://github.com/allaingaye/paypilot-shield

## Overview

PayPilot Shield lets an owner manage suppliers, invoices, policy and approvals, then ask a read-only AI agent to request payment. The backend pipeline checks invoice and supplier data, applies signed policy and fraud checks, and either blocks, requests approval, or verifies and sends a payout; audit events support replay. The UI also exposes payments, invoices, suppliers, policy signing and replay. Relationships among pipeline stages are based on the README’s documented flow; sampled excerpts show pipeline responsibilities and webhook refresh, but not every internal call.

Main entry points: [`backend/app/services/pipeline.py`](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/pipeline.py) (Payment pipeline), [`backend/app/main.py`](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/main.py) (API application), [`frontend/src/App.tsx`](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/App.tsx) (Web application), [`frontend/src/lib/api.ts`](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/lib/api.ts) (Session and API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Owner interface"]
  node_webapp["Web application<br/>[App.tsx]"]
  node_agentui["Agent chat<br/>[AgentChat.tsx]"]
  node_policyui["Policy signing<br/>[Policy.tsx]"]
  node_approvalui["Approval review<br/>[Approvals.tsx]"]
  node_opsui["Operations views<br/>[Payments.tsx]"]
  node_replayui["Audit replay<br/>[Replay.tsx]"]
  node_authui["Session and API client<br/>[api.ts]"]
end

subgraph group_api["Backend API"]
  node_apiapp["API application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_agent["Agent tools<br/>[agent.py]"]
  node_invoiceapi["Invoice and supplier API<br/>[invoices.py]"]
  node_policyapi["Mandate API<br/>[mandates.py]"]
  node_approvalapi["Approval API<br/>[approvals.py]"]
  node_transactionapi["Transaction API<br/>[transactions.py]"]
  node_webhook["PayPal webhook<br/>[webhooks.py]"]
end

subgraph group_decision["Trust and payment"]
  node_pipeline["Payment pipeline<br/>[pipeline.py]"]
  node_truth["Truth checks<br/>[truth_check.py]"]
  node_decisionfn["Policy decision<br/>[decision.py]"]
  node_verifier["Pre-payout verifier<br/>[verifier.py]"]
  node_mandate["Signed mandate<br/>[mandate.py]"]
end

subgraph group_records["Data and integrations"]
  node_audit["Audit events<br/>[audit.py]"]
  node_models[("Business records<br/>[models.py]")]
  node_paypal["PayPal Payouts<br/>[paypal_client.py]"]
end

node_owner(("Owner"))
node_paypalservice(("PayPal service"))

node_owner -->|"uses"| node_webapp
node_webapp -->|"routes to"| node_agentui
node_webapp -->|"routes to"| node_policyui
node_webapp -->|"routes to"| node_approvalui
node_webapp -->|"routes to"| node_opsui
node_webapp -->|"routes to"| node_replayui
node_agentui -->|"requests API"| node_authui
node_policyui -->|"requests API"| node_authui
node_approvalui -->|"requests API"| node_authui
node_opsui -->|"requests API"| node_authui
node_replayui -->|"requests API"| node_authui
node_authui -->|"calls"| node_apiapp
node_apiapp -->|"routes to"| node_auth
node_apiapp -->|"routes to"| node_invoiceapi
node_apiapp -->|"routes to"| node_policyapi
node_apiapp -->|"routes to"| node_approvalapi
node_apiapp -->|"routes to"| node_transactionapi
node_apiapp -->|"routes to"| node_webhook
node_agent -->|"submits request"| node_pipeline
node_pipeline -->|"reads and writes"| node_models
node_pipeline -->|"checks invoice"| node_truth
node_pipeline -->|"evaluates policy"| node_decisionfn
node_pipeline -->|"loads signed rules"| node_mandate
node_pipeline -->|"rechecks before payout"| node_verifier
node_pipeline -->|"records steps"| node_audit
node_pipeline -->|"sends payout"| node_paypal
node_policyapi -->|"manages mandate"| node_mandate
node_webhook -->|"verifies event"| node_paypal
node_webhook -->|"refreshes transaction"| node_pipeline
node_paypalservice -->|"sends events"| node_webhook

click node_webapp "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/App.tsx"
click node_agentui "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/AgentChat.tsx"
click node_policyui "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Policy.tsx"
click node_approvalui "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Approvals.tsx"
click node_opsui "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Payments.tsx"
click node_replayui "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Replay.tsx"
click node_authui "https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/lib/api.ts"
click node_apiapp "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/main.py"
click node_auth "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/auth.py"
click node_agent "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/agent.py"
click node_invoiceapi "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/invoices.py"
click node_policyapi "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/mandates.py"
click node_approvalapi "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/approvals.py"
click node_transactionapi "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/transactions.py"
click node_pipeline "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/pipeline.py"
click node_truth "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/truth_check.py"
click node_decisionfn "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/decision.py"
click node_verifier "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/verifier.py"
click node_mandate "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/mandate.py"
click node_audit "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/audit.py"
click node_models "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/models.py"
click node_paypal "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/paypal_client.py"
click node_webhook "https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/webhooks.py"

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_webapp,node_agentui,node_policyui,node_approvalui,node_opsui,node_replayui,node_authui toneBlue
class node_apiapp,node_auth,node_agent,node_invoiceapi,node_policyapi,node_approvalapi,node_transactionapi,node_webhook toneAmber
class node_pipeline,node_truth,node_decisionfn,node_verifier,node_mandate toneMint
class node_audit,node_models,node_paypal toneRose
class node_owner,node_paypalservice toneIndigo
```

## Components

### Owner interface

- [Web application](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Agent chat](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/AgentChat.tsx): `frontend/src/pages/AgentChat.tsx`
- [Policy signing](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Policy.tsx): `frontend/src/pages/Policy.tsx`
- [Approval review](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Approvals.tsx): `frontend/src/pages/Approvals.tsx`
- [Operations views](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Payments.tsx): `frontend/src/pages/Payments.tsx`
- [Audit replay](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/pages/Replay.tsx): `frontend/src/pages/Replay.tsx`
- [Session and API client](https://github.com/allaingaye/paypilot-shield/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### Backend API

- [API application](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Agent tools](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/agent.py): `backend/app/services/agent.py`
- [Invoice and supplier API](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/invoices.py): `backend/app/routers/invoices.py`
- [Mandate API](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/mandates.py): `backend/app/routers/mandates.py`
- [Approval API](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/approvals.py): `backend/app/routers/approvals.py`
- [Transaction API](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/transactions.py): `backend/app/routers/transactions.py`
- [PayPal webhook](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/routers/webhooks.py): `backend/app/routers/webhooks.py`

### Trust and payment

- [Payment pipeline](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/pipeline.py): `backend/app/services/pipeline.py`
- [Truth checks](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/truth_check.py): `backend/app/services/truth_check.py`
- [Policy decision](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/decision.py): `backend/app/services/decision.py`
- [Pre-payout verifier](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/verifier.py): `backend/app/services/verifier.py`
- [Signed mandate](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/mandate.py): `backend/app/services/mandate.py`

### Data and integrations

- [Audit events](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/audit.py): `backend/app/services/audit.py`
- [Business records](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/models.py): `backend/app/models.py`
- [PayPal Payouts](https://github.com/allaingaye/paypilot-shield/blob/main/backend/app/services/paypal_client.py): `backend/app/services/paypal_client.py`

### Other components

- **Owner**
- **PayPal service**

## Connections

- Owner → Web application: uses
- Web application → Agent chat: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Policy signing: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Approval review: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Operations views: routes to (evidence: `frontend/src/App.tsx`)
- Web application → Audit replay: routes to (evidence: `frontend/src/App.tsx`)
- Agent chat → Session and API client: requests API (evidence: `frontend/src/pages/AgentChat.tsx`)
- Policy signing → Session and API client: requests API (evidence: `frontend/src/pages/Policy.tsx`)
- Approval review → Session and API client: requests API
- Operations views → Session and API client: requests API (evidence: `frontend/src/pages/Payments.tsx`)
- Audit replay → Session and API client: requests API
- Session and API client → API application: calls (evidence: `frontend/src/lib/api.ts`)
- API application → Authentication: routes to (evidence: `backend/app/main.py`)
- API application → Invoice and supplier API: routes to (evidence: `backend/app/main.py`)
- API application → Mandate API: routes to (evidence: `backend/app/main.py`)
- API application → Approval API: routes to (evidence: `backend/app/main.py`)
- API application → Transaction API: routes to (evidence: `backend/app/main.py`)
- API application → PayPal webhook: routes to (evidence: `backend/app/main.py`)
- Agent tools → Payment pipeline: submits request (evidence: `backend/app/services/agent.py`)
- Payment pipeline → Business records: reads and writes (evidence: `backend/app/services/pipeline.py`)
- Payment pipeline → Truth checks: checks invoice (evidence: `backend/app/services/pipeline.py`)
- Payment pipeline → Policy decision: evaluates policy (evidence: `backend/app/services/pipeline.py`)
- Payment pipeline → Signed mandate: loads signed rules (evidence: `backend/app/services/pipeline.py`)
- Payment pipeline → Pre-payout verifier: rechecks before payout (evidence: `backend/app/services/pipeline.py`)
- Payment pipeline → Audit events: records steps (evidence: `backend/app/services/pipeline.py`)
- Payment pipeline → PayPal Payouts: sends payout (evidence: `backend/app/services/pipeline.py`)
- Mandate API → Signed mandate: manages mandate (evidence: `backend/app/routers/mandates.py`)
- PayPal webhook → PayPal Payouts: verifies event (evidence: `backend/app/routers/webhooks.py`)
- PayPal webhook → Payment pipeline: refreshes transaction (evidence: `backend/app/routers/webhooks.py`)
- PayPal service → PayPal webhook: sends events (evidence: `backend/app/routers/webhooks.py`)
