# rileycreighton/dispatch-public architecture

> Architecture diagram of the GitHub repository rileycreighton/dispatch-public, 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/rileycreighton/dispatch-public
- Repository: https://github.com/rileycreighton/dispatch-public

## Overview

Dispatch adds wallet- and agent-based digital purchases to an existing merchant site. A buyer reviews a quote, authorizes payment through the browser or an x402 client, and retrieves private digital goods; the API and worker maintain separate durable payment and delivery states, with recovery and merchant controls. The graph preserves documented operator, refund, webhook, and agent capabilities. Some worker and delivery wiring is unsampled, so those links rely on README statements rather than inferred calls.

Main entry points: [`apps/web/src/main.tsx`](https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/main.tsx) (Browser checkout), [`packages/db/src/commerce.ts`](https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/commerce.ts) (Commerce service), [`apps/api/src/app.ts`](https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/app.ts) (API server), [`packages/buyer/src/client.ts`](https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/client.ts) (Agent purchase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_buyer["Buyer experience"]
  node_browser["Browser checkout<br/>[main.tsx]"]
  node_operator_ui["Operator console<br/>[operator.tsx]"]
  node_buyer_client["Agent purchase client<br/>[client.ts]"]
  node_buyer_contracts["Buyer contracts<br/>[contracts.ts]"]
  node_buyer_signer["Wallet signer<br/>[signer.ts]"]
  node_buyer_journal[("Purchase journal<br/>[journal.ts]")]
end

subgraph group_api["Checkout API"]
  node_api_server["API server<br/>[app.ts]"]
  node_commerce_routes["Checkout routes<br/>[commerce.ts]"]
  node_operator_routes["Operator routes<br/>[operator.ts]"]
  node_commerce_service["Commerce service<br/>[commerce.ts]"]
  node_security["Runtime security<br/>[index.ts]"]
end

subgraph group_payments["Payment processing"]
  node_payment_application["x402 payment application<br/>[application.ts]"]
  node_payment_rules["Payment domain rules<br/>[payment.ts]"]
  node_payment_worker["Payment worker<br/>[payments.ts]"]
  node_worker_runner["Worker runtime<br/>[local-digital.ts]"]
end

subgraph group_operations["Merchant operations"]
end

subgraph group_storage["Persistence and delivery"]
  node_settlement_store[("Settlement ledger<br/>[payment-worker.ts]")]
  node_private_files[("Private file store<br/>[files.ts]")]
  node_delivery_store[("Delivery state<br/>[delivery.ts]")]
  node_delivery_transport["Delivery transport<br/>[transport.ts]"]
  node_webhook["Receipt webhook<br/>[webhook.ts]"]
  node_refund_store[("Refund state<br/>[refunds.ts]")]
end

node_buyer_actor(("Buyer"))
node_merchant_site["Merchant website"]
node_postgres[("PostgreSQL")]
node_facilitator["Payment facilitator"]
node_evm["EVM network"]

node_merchant_site -->|"links to"| node_browser
node_buyer_actor -->|"purchases through"| node_browser
node_buyer_actor -->|"purchases through"| node_buyer_client
node_browser -->|"requests checkout"| node_api_server
node_buyer_client -->|"requests checkout"| node_api_server
node_browser -->|"signs with"| node_buyer_signer
node_browser -->|"uses"| node_buyer_client
node_browser -->|"validates with"| node_buyer_contracts
node_buyer_client -->|"uses"| node_buyer_signer
node_buyer_client -->|"uses"| node_buyer_contracts
node_browser -->|"records recovery state"| node_buyer_journal
node_api_server -->|"routes to"| node_commerce_routes
node_api_server -->|"routes to"| node_operator_routes
node_commerce_routes -->|"calls"| node_commerce_service
node_commerce_service -->|"builds payment requirements"| node_payment_application
node_commerce_service -->|"validates purchase rules"| node_payment_rules
node_commerce_service -->|"reads delivery state"| node_delivery_store
node_commerce_service -->|"serves private assets"| node_private_files
node_operator_routes -->|"handles refunds"| node_refund_store
node_operator_routes -->|"reads operator state"| node_commerce_service
node_operator_ui -->|"manages products"| node_api_server
node_worker_runner -->|"starts"| node_payment_worker
node_payment_worker -->|"reconciles settlements"| node_settlement_store
node_settlement_store -->|"validates settlement"| node_payment_application
node_settlement_store -->|"submits operations"| node_facilitator
node_payment_worker -->|"verifies and settles"| node_facilitator
node_facilitator -.->|"observes transactions"| node_evm
node_settlement_store -->|"persists ledger"| node_postgres
node_worker_runner -->|"configures delivery"| node_delivery_transport
node_delivery_transport -.->|"advances delivery state"| node_delivery_store
node_delivery_store -->|"authorizes asset retrieval"| node_private_files
node_delivery_store -->|"prepares signed receipts"| node_webhook
node_webhook -.->|"delivers receipt"| node_merchant_site
node_api_server -->|"uses security controls"| node_security
node_operator_ui -.->|"reviews refunds"| node_refund_store

click node_browser "https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/main.tsx"
click node_operator_ui "https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/operator.tsx"
click node_buyer_client "https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/client.ts"
click node_buyer_contracts "https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/contracts.ts"
click node_buyer_signer "https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/signer.ts"
click node_buyer_journal "https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/journal.ts"
click node_api_server "https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/app.ts"
click node_commerce_routes "https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/commerce.ts"
click node_operator_routes "https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/operator.ts"
click node_commerce_service "https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/commerce.ts"
click node_payment_application "https://github.com/rileycreighton/dispatch-public/blob/main/packages/payments/src/application.ts"
click node_payment_rules "https://github.com/rileycreighton/dispatch-public/blob/main/packages/domain/src/payment.ts"
click node_payment_worker "https://github.com/rileycreighton/dispatch-public/blob/main/apps/worker/src/payments.ts"
click node_worker_runner "https://github.com/rileycreighton/dispatch-public/blob/main/apps/worker/src/local-digital.ts"
click node_settlement_store "https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/payment-worker.ts"
click node_private_files "https://github.com/rileycreighton/dispatch-public/blob/main/packages/fulfillment/src/files.ts"
click node_delivery_store "https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/delivery.ts"
click node_delivery_transport "https://github.com/rileycreighton/dispatch-public/blob/main/packages/fulfillment/src/transport.ts"
click node_webhook "https://github.com/rileycreighton/dispatch-public/blob/main/packages/fulfillment/src/webhook.ts"
click node_refund_store "https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/refunds.ts"
click node_security "https://github.com/rileycreighton/dispatch-public/blob/main/packages/security/src/index.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_browser,node_operator_ui,node_buyer_client,node_buyer_contracts,node_buyer_signer,node_buyer_journal toneBlue
class node_api_server,node_commerce_routes,node_operator_routes,node_commerce_service,node_security,node_postgres toneAmber
class node_payment_application,node_payment_rules,node_payment_worker,node_worker_runner toneMint
class node_settlement_store,node_private_files,node_delivery_store,node_delivery_transport,node_webhook,node_refund_store,node_buyer_actor,node_merchant_site,node_facilitator,node_evm toneIndigo
```

## Components

### Buyer experience

- [Browser checkout](https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/main.tsx): `apps/web/src/main.tsx`
- [Operator console](https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/operator.tsx): `apps/web/src/operator.tsx`
- [Agent purchase client](https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/client.ts): `packages/buyer/src/client.ts`
- [Buyer contracts](https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/contracts.ts): `packages/buyer/src/contracts.ts`
- [Wallet signer](https://github.com/rileycreighton/dispatch-public/blob/main/packages/buyer/src/signer.ts): `packages/buyer/src/signer.ts`
- [Purchase journal](https://github.com/rileycreighton/dispatch-public/blob/main/apps/web/src/journal.ts): `apps/web/src/journal.ts`

### Checkout API

- [API server](https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/app.ts): `apps/api/src/app.ts`
- [Checkout routes](https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/commerce.ts): `apps/api/src/commerce.ts`
- [Operator routes](https://github.com/rileycreighton/dispatch-public/blob/main/apps/api/src/operator.ts): `apps/api/src/operator.ts`
- [Commerce service](https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/commerce.ts): `packages/db/src/commerce.ts`
- [Runtime security](https://github.com/rileycreighton/dispatch-public/blob/main/packages/security/src/index.ts): `packages/security/src/index.ts`

### Payment processing

- [x402 payment application](https://github.com/rileycreighton/dispatch-public/blob/main/packages/payments/src/application.ts): `packages/payments/src/application.ts`
- [Payment domain rules](https://github.com/rileycreighton/dispatch-public/blob/main/packages/domain/src/payment.ts): `packages/domain/src/payment.ts`
- [Payment worker](https://github.com/rileycreighton/dispatch-public/blob/main/apps/worker/src/payments.ts): `apps/worker/src/payments.ts`
- [Worker runtime](https://github.com/rileycreighton/dispatch-public/blob/main/apps/worker/src/local-digital.ts): `apps/worker/src/local-digital.ts`

### Persistence and delivery

- [Settlement ledger](https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/payment-worker.ts): `packages/db/src/payment-worker.ts`
- [Private file store](https://github.com/rileycreighton/dispatch-public/blob/main/packages/fulfillment/src/files.ts): `packages/fulfillment/src/files.ts`
- [Delivery state](https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/delivery.ts): `packages/db/src/delivery.ts`
- [Delivery transport](https://github.com/rileycreighton/dispatch-public/blob/main/packages/fulfillment/src/transport.ts): `packages/fulfillment/src/transport.ts`
- [Receipt webhook](https://github.com/rileycreighton/dispatch-public/blob/main/packages/fulfillment/src/webhook.ts): `packages/fulfillment/src/webhook.ts`
- [Refund state](https://github.com/rileycreighton/dispatch-public/blob/main/packages/db/src/refunds.ts): `packages/db/src/refunds.ts`

### Other components

- **Buyer**
- **Merchant website**
- **PostgreSQL**
- **Payment facilitator**
- **EVM network**

## Connections

- Merchant website → Browser checkout: links to (evidence: `README.md`)
- Buyer → Browser checkout: purchases through (evidence: `README.md`)
- Buyer → Agent purchase client: purchases through (evidence: `README.md`)
- Browser checkout → API server: requests checkout (evidence: `README.md`)
- Agent purchase client → API server: requests checkout (evidence: `README.md`)
- Browser checkout → Wallet signer: signs with (evidence: `apps/web/src/main.tsx`)
- Browser checkout → Agent purchase client: uses (evidence: `apps/web/src/main.tsx`)
- Browser checkout → Buyer contracts: validates with (evidence: `apps/web/src/main.tsx`)
- Agent purchase client → Wallet signer: uses (evidence: `packages/buyer/src/client.ts`)
- Agent purchase client → Buyer contracts: uses (evidence: `packages/buyer/src/client.ts`)
- Browser checkout → Purchase journal: records recovery state (evidence: `apps/web/src/main.tsx`)
- API server → Checkout routes: routes to (evidence: `apps/api/src/app.ts`)
- API server → Operator routes: routes to (evidence: `apps/api/src/app.ts`)
- Checkout routes → Commerce service: calls (evidence: `apps/api/src/commerce.ts`)
- Commerce service → x402 payment application: builds payment requirements (evidence: `packages/db/src/commerce.ts`)
- Commerce service → Payment domain rules: validates purchase rules (evidence: `apps/api/src/commerce.ts`)
- Commerce service → Delivery state: reads delivery state (evidence: `packages/db/src/commerce.ts`)
- Commerce service → Private file store: serves private assets (evidence: `apps/api/src/commerce.ts`)
- Operator routes → Refund state: handles refunds (evidence: `apps/api/src/app.ts`)
- Operator routes → Commerce service: reads operator state (evidence: `apps/api/src/operator.ts`)
- Operator console → API server: manages products (evidence: `README.md`)
- Worker runtime → Payment worker: starts (evidence: `apps/worker/src/local-digital.ts`)
- Payment worker → Settlement ledger: reconciles settlements (evidence: `apps/worker/src/payments.ts`)
- Settlement ledger → x402 payment application: validates settlement (evidence: `packages/db/src/payment-worker.ts`)
- Settlement ledger → Payment facilitator: submits operations (evidence: `README.md`)
- Payment worker → Payment facilitator: verifies and settles (evidence: `apps/worker/src/payments.ts`)
- Payment facilitator → EVM network: observes transactions
- Settlement ledger → PostgreSQL: persists ledger (evidence: `README.md`)
- Worker runtime → Delivery transport: configures delivery (evidence: `apps/worker/src/local-digital.ts`)
- Delivery transport → Delivery state: advances delivery state
- Delivery state → Private file store: authorizes asset retrieval (evidence: `packages/db/src/delivery.ts`)
- Delivery state → Receipt webhook: prepares signed receipts (evidence: `packages/db/src/delivery.ts`)
- Receipt webhook → Merchant website: delivers receipt
- API server → Runtime security: uses security controls (evidence: `apps/api/src/main.ts`)
- Operator console → Refund state: reviews refunds (evidence: `README.md`)
