# vindyang/straitsx-888 architecture

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

- Interactive diagram: https://gitdiagram.com/vindyang/straitsx-888
- Repository: https://github.com/vindyang/straitsx-888

## Overview

#### Purpose and workspace
This monorepo implements mandated AI-agent payments over x402/XSGD. Its core security boundary is pre-signing policy enforcement: an authorization is evaluated against an on-chain mandate and runtime constraints before the isolated signer can produce an EIP-3009 signature. Node/TypeScript services run in a pnpm workspace; Solidity contract work uses Foundry. Shared wire contracts and conventions live in `packages/contracts/src/index.ts`, `packages/contracts/src/validation.ts`, and `packages/contracts/registry.json`.

#### User and service entry points
The human entry point is the Next.js dashboard, with pages and API façade under `services/dashboard/app/page.tsx`, `services/dashboard/app/api/run/route.ts`, and `services/dashboard/app/api/mandates/route.ts`. It proxies/operator-controls runs, mandates, revocation, receipts, and ledger views.
The agent-facing entry point is the orchestrator HTTP service: `services/agent-orchestrator/src/main.ts`, `services/agent-orchestrator/src/app.ts`, and `services/agent-orchestrator/src/routes/run.ts`. Checkout-specific requests enter through `services/agent-orchestrator/src/routes/checkout.ts`.

#### Agent execution and checkout orchestration
The orchestrator owns the payment-run lifecycle and coordinates downstream dependencies. Its main pipeline is `services/agent-orchestrator/src/run/pipeline.ts`, with run state in `services/agent-orchestrator/src/run/store.ts`. It discovers/validates merchant offers before issuing payment actions via `services/agent-orchestrator/src/discovery/discover.ts`.
For card/MCP-driven checkout, `services/agent-orchestrator/src/card-gateway/pay-and-issue.ts` and `services/agent-orchestrator/src/checkout/checkout-worker.ts` form a separate adapter boundary. Post-issuance checks capture spend evidence and constrain checkout domains in `services/agent-orchestrator/src/post-issuance/capture-spend-attestation.ts` and `services/agent-orchestrator/src/post-issuance/assert-checkout-domain.ts`.

#### Policy and durable decision record
Policy service is the authorization gate between orchestration and signing: `services/policy-service/src/app.ts`, `services/policy-service/src/matcher.ts`, and `services/policy-service/src/signing.ts`. Its staged checks verify mandate liveness, policy hash, chain/asset, recipient, amount, budget window, validity, and intent binding/match under `services/policy-service/src/checks/index.ts`.
Ledger service provides the durable operational record used by policy, dashboard, and orchestrator: `services/ledger-service/src/app.ts`, `services/ledger-service/src/store.ts`, and `services/ledger-service/src/index.ts`. The precise backing store is not evident from the tree; callers must treat it as the decision/audit boundary rather than independently reconstructing state.

#### Chain custody, mandates, and signing
`packages/contracts-sol/src/MandateRegistry.sol` is the on-chain mandate registry, deployed on Avalanche Fuji and mainnet. Its generated client ABI/registry must flow through `packages/contracts/registry.json` and `scripts/sync-registry.ts`, not hand edits.
`services/chain-gateway/src/app.ts`, `services/chain-gateway/src/chain.ts`, and `services/chain-gateway/src/routes/mandate.ts` are the exclusive JSON-RPC boundary for mandate reads, balances, settlement, and revoke transaction construction. No other component should open chain RPC connections.
`services/signer-service/src/app.ts`, `services/signer-service/src/sign/pipeline.ts`, and `services/signer-service/src/keys/kms-key-source.ts` isolate key access and signing. Policy is its only intended caller; AWS KMS is the production custody dependency. README notes the current service may still be an explicit stub, so readiness must verify actual signing capabilities rather than health alone.

#### Trust boundaries and control flow
All internal calls require `X-Internal-Token` and fail closed. The intended path is: dashboard/agent request → orchestrator → policy checks using ledger and chain gateway → policy calls signer → signed x402 authorization is used for settlement → evidence/receipts return through orchestrator/dashboard. The signer is network-isolated from orchestrator and dashboard; chain access is centralized in chain-gateway.
Human control is represented by on-chain mandate revocation, assembled through `services/chain-gateway/src/routes/build-revoke.ts` and surfaced by `services/dashboard/app/api/revoke/[mandateId]/route.ts`. A revoked mandate should block future authorization before signatures exist.

#### Deployment and infrastructure
AWS infrastructure is layered: account/IAM/audit bootstrap in `infra/bootstrap/main.tf`, shared foundation in `infra/foundation/main.tf`, A/B services in `infra/module-ab/main.tf`, and independently deployable Module C integration in `infra/module-c-integration/main.tf` plus `infra/module-c/main.tf`. Module C container publishing/deployment is driven by `scripts/publish-module-c-images.sh` and `scripts/deploy-module-c.sh`.
Material external services are Avalanche C-Chain RPC, deployed `MandateRegistry`, XSGD token contracts, AWS KMS, and merchant/card MCP surfaces. Container entry points include `services/agent-orchestrator/Dockerfile` and `services/dashboard/Dockerfile`.

Main entry points: [`services/agent-orchestrator/src/run/pipeline.ts`](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/run/pipeline.ts) (Payment Run Pipeline), [`services/agent-orchestrator/src/card-gateway/pay-and-issue.ts`](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/card-gateway/pay-and-issue.ts) (Card / MCP Checkout), [`services/chain-gateway/src/app.ts`](https://github.com/vindyang/straitsx-888/blob/main/services/chain-gateway/src/app.ts) (Chain Gateway), [`services/dashboard/app/api/run/route.ts`](https://github.com/vindyang/straitsx-888/blob/main/services/dashboard/app/api/run/route.ts) (Dashboard API Façade)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_dashboard["Next.js Dashboard<br/>human control UI<br/>[page.tsx]"]
  node_dashboard_api["Dashboard API Façade<br/>Next.js routes<br/>[route.ts]"]
  node_orchestrator_api["Agent Orchestrator API<br/>HTTP service<br/>[app.ts]"]
end

subgraph group_orchestration["Execution"]
  node_run_pipeline["Payment Run Pipeline<br/>run lifecycle<br/>[pipeline.ts]"]
  node_run_store[("Run State<br/>run store<br/>[store.ts]")]
  node_offer_discovery["Offer Discovery<br/>merchant validation<br/>[discover.ts]"]
  node_checkout_adapter["Card / MCP Checkout<br/>checkout adapter<br/>[pay-and-issue.ts]"]
  node_post_issuance["Spend Evidence Checks<br/>post-issuance controls"]
end

subgraph group_control["Authorization &amp; Custody"]
  node_policy_service{{"Policy Service<br/>authorization gate<br/>[app.ts]"}}
  node_policy_checks["Mandate &amp; Intent Checks<br/>policy checks<br/>[index.ts]"]
  node_ledger[("Decision Ledger<br/>durable audit record<br/>[store.ts]")]
  node_signer{{"Isolated Signer<br/>EIP-3009 signer<br/>[pipeline.ts]"}}
  node_kms["AWS KMS<br/>key custody<br/>[kms-key-source.ts]"]
end

subgraph group_chain["Chain Boundary"]
  node_chain_gateway{{"Chain Gateway<br/>exclusive JSON-RPC boundary<br/>[app.ts]"}}
  node_mandate_registry["MandateRegistry<br/>Solidity contract"]
  node_contract_registry["Contract Registry<br/>generated ABI registry<br/>[registry.json]"]
  node_avalanche(("Avalanche C-Chain RPC<br/>external RPC"))
end

subgraph group_platform["Deployment"]
  node_module_ab["Core Service Infrastructure<br/>Terraform module A/B<br/>[main.tf]"]
  node_module_c["Module C Integration<br/>deployable Terraform module<br/>[main.tf]"]
end

node_merchant_mcp(("Merchant / Card MCP<br/>external checkout"))

node_dashboard -->|"operator actions"| node_dashboard_api
node_dashboard_api -->|"proxy runs and views"| node_orchestrator_api
node_dashboard_api -->|"revoke request"| node_chain_gateway
node_orchestrator_api -->|"start payment run"| node_run_pipeline
node_run_pipeline -->|"persist lifecycle"| node_run_store
node_run_pipeline -->|"discover and validate offer"| node_offer_discovery
node_run_pipeline -->|"request authorization"| node_policy_service
node_run_pipeline -->|"card/MCP checkout"| node_checkout_adapter
node_checkout_adapter -->|"checkout interaction"| node_merchant_mcp
node_checkout_adapter -->|"issued payment"| node_post_issuance
node_post_issuance -->|"spend evidence"| node_ledger
node_policy_service -->|"evaluate"| node_policy_checks
node_policy_checks -->|"read decision state"| node_ledger
node_policy_checks -->|"verify mandate and chain state"| node_chain_gateway
node_policy_service -->|"authorized signing only"| node_signer
node_signer -->|"key access"| node_kms
node_chain_gateway -->|"JSON-RPC only"| node_avalanche
node_chain_gateway -->|"read, settle, revoke"| node_mandate_registry
node_contract_registry -.->|"generated ABI/deployment data"| node_mandate_registry
node_module_ab -.->|"deploys core services"| node_orchestrator_api
node_module_c -.->|"deploys integration"| node_checkout_adapter

click node_dashboard "https://github.com/vindyang/straitsx-888/blob/main/services/dashboard/app/page.tsx"
click node_dashboard_api "https://github.com/vindyang/straitsx-888/blob/main/services/dashboard/app/api/run/route.ts"
click node_orchestrator_api "https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/app.ts"
click node_run_pipeline "https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/run/pipeline.ts"
click node_run_store "https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/run/store.ts"
click node_offer_discovery "https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/discovery/discover.ts"
click node_checkout_adapter "https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/card-gateway/pay-and-issue.ts"
click node_post_issuance "https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/post-issuance/capture-spend-attestation.ts"
click node_policy_service "https://github.com/vindyang/straitsx-888/blob/main/services/policy-service/src/app.ts"
click node_policy_checks "https://github.com/vindyang/straitsx-888/blob/main/services/policy-service/src/checks/index.ts"
click node_ledger "https://github.com/vindyang/straitsx-888/blob/main/services/ledger-service/src/store.ts"
click node_signer "https://github.com/vindyang/straitsx-888/blob/main/services/signer-service/src/sign/pipeline.ts"
click node_kms "https://github.com/vindyang/straitsx-888/blob/main/services/signer-service/src/keys/kms-key-source.ts"
click node_chain_gateway "https://github.com/vindyang/straitsx-888/blob/main/services/chain-gateway/src/app.ts"
click node_mandate_registry "https://github.com/vindyang/straitsx-888/blob/main/packages/contracts-sol/src/MandateRegistry.sol"
click node_contract_registry "https://github.com/vindyang/straitsx-888/blob/main/packages/contracts/registry.json"
click node_module_ab "https://github.com/vindyang/straitsx-888/blob/main/infra/module-ab/main.tf"
click node_module_c "https://github.com/vindyang/straitsx-888/blob/main/infra/module-c-integration/main.tf"

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_dashboard,node_dashboard_api,node_orchestrator_api toneBlue
class node_run_pipeline,node_run_store,node_offer_discovery,node_checkout_adapter,node_post_issuance toneAmber
class node_policy_service,node_policy_checks,node_ledger,node_signer,node_kms toneMint
class node_chain_gateway,node_mandate_registry,node_contract_registry,node_avalanche toneRose
class node_module_ab,node_module_c toneIndigo
class node_merchant_mcp toneNeutral
```

## Components

### Entry Points

- [Next.js Dashboard](https://github.com/vindyang/straitsx-888/blob/main/services/dashboard/app/page.tsx): human control UI · Operator views and controls runs, mandates, receipts, and ledger. · `services/dashboard/app/page.tsx`
- [Dashboard API Façade](https://github.com/vindyang/straitsx-888/blob/main/services/dashboard/app/api/run/route.ts): Next.js routes · `services/dashboard/app/api/run/route.ts`
- [Agent Orchestrator API](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/app.ts): HTTP service · `services/agent-orchestrator/src/app.ts`

### Execution

- [Payment Run Pipeline](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/run/pipeline.ts): run lifecycle · `services/agent-orchestrator/src/run/pipeline.ts`
- [Run State](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/run/store.ts): run store · `services/agent-orchestrator/src/run/store.ts`
- [Offer Discovery](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/discovery/discover.ts): merchant validation · `services/agent-orchestrator/src/discovery/discover.ts`
- [Card / MCP Checkout](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/card-gateway/pay-and-issue.ts): checkout adapter · `services/agent-orchestrator/src/card-gateway/pay-and-issue.ts`
- [Spend Evidence Checks](https://github.com/vindyang/straitsx-888/blob/main/services/agent-orchestrator/src/post-issuance/capture-spend-attestation.ts): post-issuance controls · Captures spend attestations and restricts checkout domains. · `services/agent-orchestrator/src/post-issuance/capture-spend-attestation.ts`

### Authorization & Custody

- [Policy Service](https://github.com/vindyang/straitsx-888/blob/main/services/policy-service/src/app.ts): authorization gate · Only pre-signing policy decision path. · `services/policy-service/src/app.ts`
- [Mandate & Intent Checks](https://github.com/vindyang/straitsx-888/blob/main/services/policy-service/src/checks/index.ts): policy checks · Checks liveness, policy, asset, recipient, limits, validity, and intent. · `services/policy-service/src/checks/index.ts`
- [Decision Ledger](https://github.com/vindyang/straitsx-888/blob/main/services/ledger-service/src/store.ts): durable audit record · Authoritative operational decision and audit boundary. · `services/ledger-service/src/store.ts`
- [Isolated Signer](https://github.com/vindyang/straitsx-888/blob/main/services/signer-service/src/sign/pipeline.ts): EIP-3009 signer · Network-isolated signer; policy is its intended caller. · `services/signer-service/src/sign/pipeline.ts`
- [AWS KMS](https://github.com/vindyang/straitsx-888/blob/main/services/signer-service/src/keys/kms-key-source.ts): key custody · `services/signer-service/src/keys/kms-key-source.ts`

### Chain Boundary

- [Chain Gateway](https://github.com/vindyang/straitsx-888/blob/main/services/chain-gateway/src/app.ts): exclusive JSON-RPC boundary · Centralizes mandate reads, balances, settlement, and revoke construction. · `services/chain-gateway/src/app.ts`
- [MandateRegistry](https://github.com/vindyang/straitsx-888/blob/main/packages/contracts-sol/src/MandateRegistry.sol): Solidity contract · On-chain mandate registry on Avalanche Fuji and mainnet. · `packages/contracts-sol/src/MandateRegistry.sol`
- [Contract Registry](https://github.com/vindyang/straitsx-888/blob/main/packages/contracts/registry.json): generated ABI registry · Generated ABI and deployment registry; not hand edited. · `packages/contracts/registry.json`
- **Avalanche C-Chain RPC**: external RPC

### Deployment

- [Core Service Infrastructure](https://github.com/vindyang/straitsx-888/blob/main/infra/module-ab/main.tf): Terraform module A/B · `infra/module-ab/main.tf`
- [Module C Integration](https://github.com/vindyang/straitsx-888/blob/main/infra/module-c-integration/main.tf): deployable Terraform module · Independently deployable integration module. · `infra/module-c-integration/main.tf`

### Other components

- **Merchant / Card MCP**: external checkout

## Connections

- Next.js Dashboard → Dashboard API Façade: operator actions
- Dashboard API Façade → Agent Orchestrator API: proxy runs and views
- Dashboard API Façade → Chain Gateway: revoke request
- Agent Orchestrator API → Payment Run Pipeline: start payment run
- Payment Run Pipeline → Run State: persist lifecycle
- Payment Run Pipeline → Offer Discovery: discover and validate offer
- Payment Run Pipeline → Policy Service: request authorization
- Payment Run Pipeline → Card / MCP Checkout: card/MCP checkout
- Card / MCP Checkout → Merchant / Card MCP: checkout interaction
- Card / MCP Checkout → Spend Evidence Checks: issued payment
- Spend Evidence Checks → Decision Ledger: spend evidence
- Policy Service → Mandate & Intent Checks: evaluate
- Mandate & Intent Checks → Decision Ledger: read decision state
- Mandate & Intent Checks → Chain Gateway: verify mandate and chain state
- Policy Service → Isolated Signer: authorized signing only
- Isolated Signer → AWS KMS: key access
- Chain Gateway → Avalanche C-Chain RPC: JSON-RPC only
- Chain Gateway → MandateRegistry: read, settle, revoke
- Contract Registry → MandateRegistry: generated ABI/deployment data
- Core Service Infrastructure → Agent Orchestrator API: deploys core services
- Module C Integration → Card / MCP Checkout: deploys integration
