# zugzwang-world/graphpay architecture

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

- Interactive diagram: https://gitdiagram.com/zugzwang-world/graphpay
- Repository: https://github.com/zugzwang-world/graphpay

## Overview

GraphPay is a testnet agent-commerce demo: a customer describes a purchase, agents discover and assess shops, then a guarded payer completes x402 checkout through a facilitator. Payments are recorded in Arkiv for later reputation and explainable queries; merchants and customers can manage orders and agent authority. The map also includes the live phone/stage interfaces and the documented refund, reorder, and subscription paths. Some subsystem links are supported by the README rather than sampled implementation; unsampled details are not inferred.

Main entry points: [`packages/agents/src/buyer.mjs`](https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/buyer.mjs) (Buyer agents), [`packages/facilitator/src/pipeline.mjs`](https://github.com/zugzwang-world/graphpay/blob/main/packages/facilitator/src/pipeline.mjs) (Payment facilitator), [`apps/web/app/api/graphql/route.ts`](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/api/graphql/route.ts) (GraphQL and MCP), [`apps/web/lib/merchant-actions.server.ts`](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/merchant-actions.server.ts) (Merchant actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agents["Agent commerce"]
  node_agent_team["Buyer agents<br/>[buyer.mjs]"]
  node_shop_discovery["Shop discovery<br/>[graph.mjs]"]
  node_shop_ranking["Shop ranking<br/>[scoring.mjs]"]
end

subgraph group_payment["Checkout and settlement"]
  node_shopfront["Shopfront<br/>[server.mjs]"]
  node_facilitator["Payment facilitator<br/>[pipeline.mjs]"]
  node_checkout_contract["Checkout contract<br/>[index.mjs]"]
  node_whitechain[("Whitechain")]
end

subgraph group_memory["Arkiv money graph"]
  node_mirror_workers["Mirror workers<br/>[workers.mjs]"]
  node_arkiv[("Arkiv graph store<br/>[engine.mjs]")]
  node_graph_api["GraphQL and MCP<br/>[route.ts]"]
  node_explain_trace["Explain traces<br/>[arkiv.server.ts]"]
end

subgraph group_control["Merchant and owner controls"]
  node_merchant_controls["Merchant actions"]
  node_customer_controls["Customer controls"]
  node_ens_authority["ENS authority<br/>[actions.mjs]"]
  node_order_lifecycle["Refunds and renewals"]
end

subgraph group_interfaces["Demo interfaces"]
  node_phone_apps["Customer and merchant phones<br/>[customer.tsx]"]
  node_web_stage["Live demo stage<br/>[errand.ts]"]
  node_human_web["Customer and merchant web<br/>[page.tsx]"]
end

node_customer(("Customer"))
node_merchant(("Merchant"))

node_customer -->|"requests purchase"| node_agent_team
node_agent_team -->|"finds shops"| node_shop_discovery
node_agent_team -->|"asks reputation"| node_graph_api
node_graph_api -->|"queries graph"| node_arkiv
node_graph_api -->|"returns read trace"| node_explain_trace
node_agent_team -->|"ranks in code"| node_shop_ranking
node_agent_team -->|"requests checkout"| node_shopfront
node_shopfront -->|"delegates payment"| node_facilitator
node_facilitator -->|"checks agent status"| node_ens_authority
node_facilitator -->|"verifies and settles"| node_checkout_contract
node_checkout_contract -->|"records payment"| node_whitechain
node_whitechain -->|"emits checkout events"| node_mirror_workers
node_mirror_workers -->|"writes payment memory"| node_arkiv
node_merchant -->|"manages orders"| node_merchant_controls
node_merchant_controls -->|"dispatches or refunds"| node_checkout_contract
node_customer -->|"manages payer"| node_customer_controls
node_customer_controls -->|"pauses payer"| node_ens_authority
node_customer_controls -->|"changes subscription"| node_order_lifecycle
node_merchant_controls -->|"refunds or renews"| node_order_lifecycle
node_customer -->|"uses phone"| node_phone_apps
node_merchant -->|"uses phone"| node_phone_apps
node_phone_apps -->|"drives demo stage"| node_web_stage
node_customer -->|"uses web controls"| node_human_web
node_merchant -->|"uses merchant view"| node_human_web

click node_agent_team "https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/buyer.mjs"
click node_shop_discovery "https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/graph.mjs"
click node_shop_ranking "https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/scoring.mjs"
click node_shopfront "https://github.com/zugzwang-world/graphpay/blob/main/packages/checkout-kit/src/server.mjs"
click node_facilitator "https://github.com/zugzwang-world/graphpay/blob/main/packages/facilitator/src/pipeline.mjs"
click node_checkout_contract "https://github.com/zugzwang-world/graphpay/blob/main/packages/contracts/index.mjs"
click node_mirror_workers "https://github.com/zugzwang-world/graphpay/blob/main/packages/mirror/src/workers.mjs"
click node_arkiv "https://github.com/zugzwang-world/graphpay/blob/main/packages/arkiv-graph/src/engine.mjs"
click node_graph_api "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/api/graphql/route.ts"
click node_explain_trace "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/api/graphql/arkiv.server.ts"
click node_merchant_controls "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/merchant-actions.server.ts"
click node_customer_controls "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/customer-state.server.ts"
click node_ens_authority "https://github.com/zugzwang-world/graphpay/blob/main/packages/ens/src/actions.mjs"
click node_order_lifecycle "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/subscription.server.ts"
click node_phone_apps "https://github.com/zugzwang-world/graphpay/blob/main/apps/phones/src/customer.tsx"
click node_web_stage "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/stage/errand.ts"
click node_human_web "https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/customer/page.tsx"

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_agent_team,node_shop_discovery,node_shop_ranking toneBlue
class node_shopfront,node_facilitator,node_checkout_contract,node_whitechain toneAmber
class node_mirror_workers,node_arkiv,node_graph_api,node_explain_trace toneMint
class node_merchant_controls,node_customer_controls,node_ens_authority,node_order_lifecycle toneRose
class node_phone_apps,node_web_stage,node_human_web,node_customer,node_merchant toneIndigo
```

## Components

### Agent commerce

- [Buyer agents](https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/buyer.mjs): `packages/agents/src/buyer.mjs`
- [Shop discovery](https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/graph.mjs): `packages/agents/src/graph.mjs`
- [Shop ranking](https://github.com/zugzwang-world/graphpay/blob/main/packages/agents/src/scoring.mjs): `packages/agents/src/scoring.mjs`

### Checkout and settlement

- [Shopfront](https://github.com/zugzwang-world/graphpay/blob/main/packages/checkout-kit/src/server.mjs): `packages/checkout-kit/src/server.mjs`
- [Payment facilitator](https://github.com/zugzwang-world/graphpay/blob/main/packages/facilitator/src/pipeline.mjs): `packages/facilitator/src/pipeline.mjs`
- [Checkout contract](https://github.com/zugzwang-world/graphpay/blob/main/packages/contracts/index.mjs): `packages/contracts/index.mjs`
- **Whitechain**

### Arkiv money graph

- [Mirror workers](https://github.com/zugzwang-world/graphpay/blob/main/packages/mirror/src/workers.mjs): `packages/mirror/src/workers.mjs`
- [Arkiv graph store](https://github.com/zugzwang-world/graphpay/blob/main/packages/arkiv-graph/src/engine.mjs): `packages/arkiv-graph/src/engine.mjs`
- [GraphQL and MCP](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/api/graphql/route.ts): `apps/web/app/api/graphql/route.ts`
- [Explain traces](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/api/graphql/arkiv.server.ts): `apps/web/app/api/graphql/arkiv.server.ts`

### Merchant and owner controls

- [Merchant actions](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/merchant-actions.server.ts): `apps/web/lib/merchant-actions.server.ts`
- [Customer controls](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/customer-state.server.ts): `apps/web/lib/customer-state.server.ts`
- [ENS authority](https://github.com/zugzwang-world/graphpay/blob/main/packages/ens/src/actions.mjs): `packages/ens/src/actions.mjs`
- [Refunds and renewals](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/subscription.server.ts): `apps/web/lib/subscription.server.ts`

### Demo interfaces

- [Customer and merchant phones](https://github.com/zugzwang-world/graphpay/blob/main/apps/phones/src/customer.tsx): `apps/phones/src/customer.tsx`
- [Live demo stage](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/lib/stage/errand.ts): `apps/web/lib/stage/errand.ts`
- [Customer and merchant web](https://github.com/zugzwang-world/graphpay/blob/main/apps/web/app/customer/page.tsx): `apps/web/app/customer/page.tsx`

### Other components

- **Customer**
- **Merchant**

## Connections

- Customer → Buyer agents: requests purchase (evidence: `README.md`)
- Buyer agents → Shop discovery: finds shops (evidence: `README.md`)
- Buyer agents → GraphQL and MCP: asks reputation (evidence: `README.md`)
- GraphQL and MCP → Arkiv graph store: queries graph
- GraphQL and MCP → Explain traces: returns read trace (evidence: `README.md`)
- Buyer agents → Shop ranking: ranks in code (evidence: `README.md`)
- Buyer agents → Shopfront: requests checkout (evidence: `README.md`)
- Shopfront → Payment facilitator: delegates payment (evidence: `packages/checkout-kit/src/server.mjs`)
- Payment facilitator → ENS authority: checks agent status (evidence: `README.md`)
- Payment facilitator → Checkout contract: verifies and settles (evidence: `README.md`)
- Checkout contract → Whitechain: records payment (evidence: `README.md`)
- Whitechain → Mirror workers: emits checkout events
- Mirror workers → Arkiv graph store: writes payment memory
- Merchant → Merchant actions: manages orders (evidence: `README.md`)
- Merchant actions → Checkout contract: dispatches or refunds (evidence: `README.md`)
- Customer → Customer controls: manages payer (evidence: `README.md`)
- Customer controls → ENS authority: pauses payer (evidence: `README.md`)
- Customer controls → Refunds and renewals: changes subscription (evidence: `README.md`)
- Merchant actions → Refunds and renewals: refunds or renews (evidence: `README.md`)
- Customer → Customer and merchant phones: uses phone (evidence: `README.md`)
- Merchant → Customer and merchant phones: uses phone (evidence: `README.md`)
- Customer and merchant phones → Live demo stage: drives demo stage (evidence: `apps/phones/src/customer.tsx`)
- Customer → Customer and merchant web: uses web controls (evidence: `README.md`)
- Merchant → Customer and merchant web: uses merchant view (evidence: `README.md`)
