# fernandogarzaaa/paypilot architecture

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

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

## Overview

PayPilot turns a user’s natural-language commerce request into PayPal operations: the web agent or an MCP client invokes shared tools, which validate and dispatch invoice, payment-search, refund, and account-summary actions through a PayPal client and configurable transport. The web surface can hold money-moving actions for human confirmation. The README and excerpts establish these main paths; detailed web routing and some tool implementations were not fully sampled.

Main entry points: [`paypilot/paypal_client.py`](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py) (PayPal REST client), [`paypilot/tools.py`](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/tools.py) (Tool dispatcher), [`paypilot/web.py`](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/web.py) (Web API), [`paypilot/agent.py`](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/agent.py) (Agent loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["Access surfaces"]
  node_web_ui["Chat UI<br/>[index.html]"]
  node_web_backend["Web API<br/>[web.py]"]
  node_mcp_server["MCP server<br/>[mcp_server.py]"]
end

subgraph group_agent["Agent workflow"]
  node_agent_loop["Agent loop<br/>[agent.py]"]
  node_model_client["Model client<br/>[agent.py]"]
end

subgraph group_operations["Commerce operations"]
  node_tool_dispatch["Tool dispatcher<br/>[tools.py]"]
  node_invoice_ops["Invoice operations<br/>[paypal_client.py]"]
  node_payment_ops["Payment search and refunds<br/>[paypal_client.py]"]
  node_account_summary["Account summary<br/>[tools.py]"]
end

subgraph group_connectivity["PayPal connectivity"]
  node_paypal_client["PayPal REST client<br/>[paypal_client.py]"]
  node_transport["HTTP transport<br/>[transport.py]"]
  node_mock_transport[("Mock PayPal backend<br/>[transport.py]")]
end

node_user(("User"))
node_mcp_client(("MCP client"))
node_model_service{{"Chat model"}}
node_paypal_service{{"PayPal API"}}

node_user -->|"sends request"| node_web_ui
node_web_ui -->|"posts chat"| node_web_backend
node_web_backend -->|"runs agent"| node_agent_loop
node_agent_loop -->|"requests completion"| node_model_client
node_model_client -->|"calls endpoint"| node_model_service
node_agent_loop -->|"executes calls"| node_tool_dispatch
node_web_backend -->|"executes confirmed actions"| node_tool_dispatch
node_user -->|"requests operation"| node_mcp_client
node_mcp_client -->|"calls tools"| node_mcp_server
node_mcp_server -->|"dispatches tools"| node_tool_dispatch
node_tool_dispatch -->|"calls operations"| node_paypal_client
node_paypal_client -->|"sends requests"| node_transport
node_transport -->|"calls REST API"| node_paypal_service
node_paypal_client -.->|"uses when configured"| node_mock_transport
node_paypal_client -->|"implements invoices"| node_invoice_ops
node_paypal_client -->|"implements search and refunds"| node_payment_ops
node_tool_dispatch -->|"builds summary"| node_account_summary

click node_web_ui "https://github.com/fernandogarzaaa/paypilot/blob/main/webui/index.html"
click node_web_backend "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/web.py"
click node_mcp_server "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/mcp_server.py"
click node_agent_loop "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/agent.py"
click node_model_client "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/agent.py"
click node_tool_dispatch "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/tools.py"
click node_invoice_ops "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py"
click node_payment_ops "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py"
click node_account_summary "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/tools.py"
click node_paypal_client "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py"
click node_transport "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/transport.py"
click node_mock_transport "https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/transport.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_web_ui,node_web_backend,node_mcp_server,node_user,node_mcp_client toneBlue
class node_agent_loop,node_model_client toneAmber
class node_tool_dispatch,node_invoice_ops,node_payment_ops,node_account_summary,node_paypal_service toneMint
class node_paypal_client,node_transport,node_mock_transport toneRose
class node_model_service toneIndigo
```

## Components

### Access surfaces

- [Chat UI](https://github.com/fernandogarzaaa/paypilot/blob/main/webui/index.html): `webui/index.html`
- [Web API](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/web.py): `paypilot/web.py`
- [MCP server](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/mcp_server.py): `paypilot/mcp_server.py`

### Agent workflow

- [Agent loop](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/agent.py): `paypilot/agent.py`
- [Model client](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/agent.py): `paypilot/agent.py`

### Commerce operations

- [Tool dispatcher](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/tools.py): `paypilot/tools.py`
- [Invoice operations](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py): `paypilot/paypal_client.py`
- [Payment search and refunds](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py): `paypilot/paypal_client.py`
- [Account summary](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/tools.py): `paypilot/tools.py`

### PayPal connectivity

- [PayPal REST client](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/paypal_client.py): `paypilot/paypal_client.py`
- [HTTP transport](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/transport.py): `paypilot/transport.py`
- [Mock PayPal backend](https://github.com/fernandogarzaaa/paypilot/blob/main/paypilot/transport.py): `paypilot/transport.py`

### Other components

- **User**
- **MCP client**
- **Chat model**
- **PayPal API**

## Connections

- User → Chat UI: sends request (evidence: `README.md`)
- Chat UI → Web API: posts chat (evidence: `paypilot/web.py`)
- Web API → Agent loop: runs agent (evidence: `paypilot/web.py`)
- Agent loop → Model client: requests completion (evidence: `paypilot/agent.py`)
- Model client → Chat model: calls endpoint (evidence: `paypilot/agent.py`)
- Agent loop → Tool dispatcher: executes calls (evidence: `paypilot/agent.py`)
- Web API → Tool dispatcher: executes confirmed actions (evidence: `paypilot/web.py`)
- User → MCP client: requests operation (evidence: `README.md`)
- MCP client → MCP server: calls tools (evidence: `README.md`)
- MCP server → Tool dispatcher: dispatches tools (evidence: `paypilot/mcp_server.py`)
- Tool dispatcher → PayPal REST client: calls operations (evidence: `paypilot/tools.py`)
- PayPal REST client → HTTP transport: sends requests (evidence: `paypilot/paypal_client.py`)
- HTTP transport → PayPal API: calls REST API (evidence: `README.md`)
- PayPal REST client → Mock PayPal backend: uses when configured (evidence: `paypilot/paypal_client.py`)
- PayPal REST client → Invoice operations: implements invoices (evidence: `README.md`)
- PayPal REST client → Payment search and refunds: implements search and refunds (evidence: `README.md`)
- Tool dispatcher → Account summary: builds summary (evidence: `paypilot/tools.py`)
