# z33mscessex/midnight-agent-registry architecture

> Architecture diagram of the GitHub repository z33mscessex/midnight-agent-registry, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/z33mscessex/midnight-agent-registry
- Repository: https://github.com/z33mscessex/midnight-agent-registry

## Overview

This repository implements a Midnight agent registry and a demo discovery-to-paid-call workflow: an operator registers an agent and its price, a client discovers and checks its Agent Card, then pays through x402 and calls it with A2A. The registry API and contract provide the core on-chain record and ownership proofs; separate wallet utilities create and fund wallets. Major subsystems are included based on the README, but several demo and contract implementation relationships are documented there rather than verified from sampled source.

Main entry points: [`registry/demo/agent-b.ts`](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/agent-b.ts) (Agent B client), [`registry/api/index.ts`](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/api/index.ts) (Registry API), [`wallet/src/register-dust.ts`](https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/register-dust.ts) (DUST registration), [`registry/src/providers.ts`](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/providers.ts) (Chain providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_registry["Registry and identity"]
  node_register["Agent registration"]
  node_api["Registry API<br/>[index.ts]"]
  node_types["Registry types<br/>[common-types.ts]"]
  node_contract["Registry contract<br/>[registry.compact]"]
  node_witness["Ownership witness<br/>[witnesses.ts]"]
  node_providers["Chain providers<br/>[providers.ts]"]
  node_config["Network config<br/>[config.ts]"]
end

subgraph group_discovery["Agent discovery"]
  node_client["Agent B client<br/>[agent-b.ts]"]
  node_agentcard["Agent Card"]
end

subgraph group_payments["Payment and invocation"]
  node_agent["Agent A service<br/>[agent-a.ts]"]
  node_scheme["Midnight x402 scheme<br/>[midnight-x402.ts]"]
  node_facilitator["Payment facilitator<br/>[facilitator.ts]"]
end

subgraph group_wallets["Wallet operations"]
  node_wallet["Registry wallet<br/>[wallet.ts]"]
  node_walletcreate["Wallet creation<br/>[create-wallet.ts]"]
  node_seed[("Seed storage<br/>[seed.ts]")]
  node_dust["DUST registration<br/>[register-dust.ts]"]
  node_walletconfig["Wallet network config<br/>[config.ts]"]
end

node_operator(("Agent operator"))
node_indexer[("Midnight indexer")]
node_a2a["A2A service"]
node_payer(("Agent B operator"))
node_midnight[("Midnight network")]

node_operator -->|"registers agent"| node_register
node_register -->|"submits record"| node_api
node_api -->|"calls circuits"| node_contract
node_api -->|"uses types"| node_types
node_api -->|"reads state"| node_indexer
node_api -->|"uses providers"| node_providers
node_providers -->|"uses config"| node_config
node_providers -->|"configures access"| node_indexer
node_contract -->|"uses witness"| node_witness
node_client -->|"reads records"| node_indexer
node_client -->|"fetches and checks"| node_agentcard
node_client -->|"requests payment"| node_scheme
node_client -->|"calls agent"| node_a2a
node_a2a -->|"routes request"| node_agent
node_agent -->|"requires payment"| node_scheme
node_scheme -->|"submits proof"| node_facilitator
node_facilitator -->|"checks payer and price"| node_indexer
node_facilitator -->|"claims payment"| node_midnight
node_payer -->|"starts workflow"| node_client
node_client -->|"opens for payment"| node_wallet
node_walletcreate -->|"loads or creates"| node_seed
node_dust -->|"reads seed"| node_seed
node_dust -->|"uses endpoints"| node_walletconfig
node_wallet -.->|"submits transactions"| node_midnight
node_dust -->|"registers token"| node_midnight

click node_register "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/register-agent-a.ts"
click node_api "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/api/index.ts"
click node_types "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/api/common-types.ts"
click node_contract "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/contract/registry.compact"
click node_witness "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/contract/witnesses.ts"
click node_providers "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/providers.ts"
click node_config "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/config.ts"
click node_client "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/agent-b.ts"
click node_agent "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/agent-a.ts"
click node_scheme "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/midnight-x402.ts"
click node_facilitator "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/facilitator.ts"
click node_wallet "https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/wallet.ts"
click node_walletcreate "https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/create-wallet.ts"
click node_seed "https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/seed.ts"
click node_dust "https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/register-dust.ts"
click node_walletconfig "https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/config.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_register,node_api,node_types,node_contract,node_witness,node_providers,node_config toneBlue
class node_client,node_agentcard,node_indexer,node_midnight toneAmber
class node_agent,node_scheme,node_facilitator toneMint
class node_wallet,node_walletcreate,node_seed,node_dust,node_walletconfig toneRose
class node_operator,node_a2a,node_payer toneIndigo
```

## Components

### Registry and identity

- [Agent registration](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/register-agent-a.ts): `registry/demo/register-agent-a.ts`
- [Registry API](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/api/index.ts): `registry/api/index.ts`
- [Registry types](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/api/common-types.ts): `registry/api/common-types.ts`
- [Registry contract](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/contract/registry.compact): `registry/contract/registry.compact`
- [Ownership witness](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/contract/witnesses.ts): `registry/contract/witnesses.ts`
- [Chain providers](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/providers.ts): `registry/src/providers.ts`
- [Network config](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/config.ts): `registry/src/config.ts`

### Agent discovery

- [Agent B client](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/agent-b.ts): `registry/demo/agent-b.ts`
- **Agent Card**

### Payment and invocation

- [Agent A service](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/agent-a.ts): `registry/demo/agent-a.ts`
- [Midnight x402 scheme](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/midnight-x402.ts): `registry/demo/midnight-x402.ts`
- [Payment facilitator](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/demo/facilitator.ts): `registry/demo/facilitator.ts`

### Wallet operations

- [Registry wallet](https://github.com/z33mscessex/midnight-agent-registry/blob/main/registry/src/wallet.ts): `registry/src/wallet.ts`
- [Wallet creation](https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/create-wallet.ts): `wallet/src/create-wallet.ts`
- [Seed storage](https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/seed.ts): `wallet/src/seed.ts`
- [DUST registration](https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/register-dust.ts): `wallet/src/register-dust.ts`
- [Wallet network config](https://github.com/z33mscessex/midnight-agent-registry/blob/main/wallet/src/config.ts): `wallet/src/config.ts`

### Other components

- **Agent operator**
- **Midnight indexer**
- **A2A service**
- **Agent B operator**
- **Midnight network**

## Connections

- Agent operator → Agent registration: registers agent (evidence: `README.md`)
- Agent registration → Registry API: submits record (evidence: `README.md`)
- Registry API → Registry contract: calls circuits (evidence: `registry/api/index.ts`)
- Registry API → Registry types: uses types (evidence: `registry/api/index.ts`)
- Registry API → Midnight indexer: reads state (evidence: `registry/api/index.ts`)
- Registry API → Chain providers: uses providers (evidence: `registry/src/providers.ts`)
- Chain providers → Network config: uses config (evidence: `registry/src/providers.ts`)
- Chain providers → Midnight indexer: configures access (evidence: `registry/src/providers.ts`)
- Registry contract → Ownership witness: uses witness
- Agent B client → Midnight indexer: reads records (evidence: `README.md`)
- Agent B client → Agent Card: fetches and checks (evidence: `README.md`)
- Agent B client → Midnight x402 scheme: requests payment (evidence: `README.md`)
- Agent B client → A2A service: calls agent (evidence: `README.md`)
- A2A service → Agent A service: routes request (evidence: `README.md`)
- Agent A service → Midnight x402 scheme: requires payment (evidence: `README.md`)
- Midnight x402 scheme → Payment facilitator: submits proof (evidence: `README.md`)
- Payment facilitator → Midnight indexer: checks payer and price (evidence: `README.md`)
- Payment facilitator → Midnight network: claims payment (evidence: `README.md`)
- Agent B operator → Agent B client: starts workflow (evidence: `README.md`)
- Agent B client → Registry wallet: opens for payment (evidence: `README.md`)
- Wallet creation → Seed storage: loads or creates (evidence: `wallet/src/create-wallet.ts`)
- DUST registration → Seed storage: reads seed (evidence: `wallet/src/register-dust.ts`)
- DUST registration → Wallet network config: uses endpoints (evidence: `wallet/src/register-dust.ts`)
- Registry wallet → Midnight network: submits transactions
- DUST registration → Midnight network: registers token (evidence: `README.md`)
