# mikeypetrillo/agent402 architecture

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

- Interactive diagram: https://gitdiagram.com/mikeypetrillo/agent402
- Repository: https://github.com/mikeypetrillo/agent402

## Overview

Agent402 is a self-hostable marketplace and paid tool server for AI agents, with human-facing reports and a separate pay-per-crawl product. The main agent workflow is discovery through MCP, then a tool call whose paid access can use x402 or MPP; framework adapters provide additional entry points. Other documented branches include tool routing, seller rankings, metered model access, decision planning, and tollbooth deployment. The supplied excerpts do not include the main server or most tool implementations, so edges are limited to README statements and visible imports; some subsystem paths use existing source directories where implementation files were not shown.

Main entry points: [`mcp/index.js`](https://github.com/mikeypetrillo/agent402/blob/main/mcp/index.js) (MCP server), [`tollbooth/index.js`](https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/index.js) (Tollbooth gate), [`services/decide/server.js`](https://github.com/mikeypetrillo/agent402/blob/main/services/decide/server.js) (Decision service), [`client/index.js`](https://github.com/mikeypetrillo/agent402/blob/main/client/index.js) (Payment client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent_access["Agent access"]
  node_mcp["MCP server<br/>[index.js]"]
  node_adapters["Framework adapters"]
  node_client["Payment client<br/>[index.js]"]
end

subgraph group_discovery["Discovery and planning"]
  node_tool_catalog["Tool catalog<br/>[output-schemas.js]"]
  node_tool_search["Tool search<br/>[search.js]"]
  node_router["Smart router<br/>[routing-proof.js]"]
  node_leaderboard["Seller leaderboard"]
  node_decision_planner["Decision planner<br/>[planner.js]"]
  node_decision_service["Decision service<br/>[server.js]"]
end

subgraph group_paid_services["Paid services"]
  node_tool_execution["Tool execution"]
  node_model_gateway["LLM gateway<br/>[llm-gateway-kit.js]"]
  node_facilitator["Payment facilitator<br/>[index.js]"]
  node_reports_monitors["Reports and monitors"]
end

subgraph group_site_monetization["Site monetization"]
  node_tollbooth["Tollbooth gate<br/>[index.js]"]
  node_tollbooth_edge["Edge tollbooth<br/>[edge.js]"]
  node_tollbooth_dashboard["Tollbooth dashboard<br/>[dashboard.js]"]
end

node_agent(("AI agent"))
node_seller(("x402 seller"))
node_payment_networks{{"Payment networks"}}
node_website(("Website or API"))

node_agent -->|"calls tools"| node_mcp
node_agent -->|"uses integration"| node_adapters
node_mcp -->|"resolves names"| node_tool_catalog
node_mcp -->|"searches tools"| node_tool_search
node_mcp -->|"invokes tools"| node_tool_execution
node_tool_search -.->|"finds matches"| node_tool_catalog
node_agent -->|"requests routing"| node_router
node_agent -->|"reads rankings"| node_leaderboard
node_decision_service -->|"parses decisions"| node_decision_planner
node_decision_service -.->|"returns candidates"| node_agent
node_tool_execution -.->|"serves inference"| node_model_gateway
node_agent -->|"pays per call"| node_client
node_client -->|"pays request"| node_seller
node_seller -->|"settles payments"| node_payment_networks
node_agent -->|"buys reports"| node_reports_monitors
node_website -->|"gates requests"| node_tollbooth
node_tollbooth -->|"collects payment"| node_payment_networks
node_tollbooth_edge -->|"runs gate"| node_tollbooth
node_tollbooth_dashboard -.->|"shows analytics"| node_tollbooth

click node_mcp "https://github.com/mikeypetrillo/agent402/blob/main/mcp/index.js"
click node_adapters "https://github.com/mikeypetrillo/agent402/tree/main/adapters"
click node_client "https://github.com/mikeypetrillo/agent402/blob/main/client/index.js"
click node_tool_catalog "https://github.com/mikeypetrillo/agent402/blob/main/mcp/output-schemas.js"
click node_tool_search "https://github.com/mikeypetrillo/agent402/blob/main/src/tools/search.js"
click node_router "https://github.com/mikeypetrillo/agent402/blob/main/src/routing-proof.js"
click node_leaderboard "https://github.com/mikeypetrillo/agent402/tree/main/src"
click node_decision_planner "https://github.com/mikeypetrillo/agent402/blob/main/services/decide/planner.js"
click node_decision_service "https://github.com/mikeypetrillo/agent402/blob/main/services/decide/server.js"
click node_tool_execution "https://github.com/mikeypetrillo/agent402/tree/main/src/tools"
click node_model_gateway "https://github.com/mikeypetrillo/agent402/blob/main/src/tools/llm-gateway-kit.js"
click node_facilitator "https://github.com/mikeypetrillo/agent402/blob/main/facilitator/index.js"
click node_reports_monitors "https://github.com/mikeypetrillo/agent402/tree/main/services/live"
click node_tollbooth "https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/index.js"
click node_tollbooth_edge "https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/edge.js"
click node_tollbooth_dashboard "https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/dashboard.js"

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_mcp,node_adapters,node_client toneBlue
class node_tool_catalog,node_tool_search,node_router,node_leaderboard,node_decision_planner,node_decision_service toneAmber
class node_tool_execution,node_model_gateway,node_facilitator,node_reports_monitors,node_website toneMint
class node_tollbooth,node_tollbooth_edge,node_tollbooth_dashboard toneRose
class node_agent,node_seller,node_payment_networks toneIndigo
```

## Components

### Agent access

- [MCP server](https://github.com/mikeypetrillo/agent402/blob/main/mcp/index.js): `mcp/index.js`
- [Framework adapters](https://github.com/mikeypetrillo/agent402/tree/main/adapters): `adapters`
- [Payment client](https://github.com/mikeypetrillo/agent402/blob/main/client/index.js): `client/index.js`

### Discovery and planning

- [Tool catalog](https://github.com/mikeypetrillo/agent402/blob/main/mcp/output-schemas.js): `mcp/output-schemas.js`
- [Tool search](https://github.com/mikeypetrillo/agent402/blob/main/src/tools/search.js): `src/tools/search.js`
- [Smart router](https://github.com/mikeypetrillo/agent402/blob/main/src/routing-proof.js): `src/routing-proof.js`
- [Seller leaderboard](https://github.com/mikeypetrillo/agent402/tree/main/src): `src`
- [Decision planner](https://github.com/mikeypetrillo/agent402/blob/main/services/decide/planner.js): `services/decide/planner.js`
- [Decision service](https://github.com/mikeypetrillo/agent402/blob/main/services/decide/server.js): `services/decide/server.js`

### Paid services

- [Tool execution](https://github.com/mikeypetrillo/agent402/tree/main/src/tools): `src/tools`
- [LLM gateway](https://github.com/mikeypetrillo/agent402/blob/main/src/tools/llm-gateway-kit.js): `src/tools/llm-gateway-kit.js`
- [Payment facilitator](https://github.com/mikeypetrillo/agent402/blob/main/facilitator/index.js): `facilitator/index.js`
- [Reports and monitors](https://github.com/mikeypetrillo/agent402/tree/main/services/live): `services/live`

### Site monetization

- [Tollbooth gate](https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/index.js): `tollbooth/index.js`
- [Edge tollbooth](https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/edge.js): `tollbooth/edge.js`
- [Tollbooth dashboard](https://github.com/mikeypetrillo/agent402/blob/main/tollbooth/dashboard.js): `tollbooth/dashboard.js`

### Other components

- **AI agent**
- **x402 seller**
- **Payment networks**
- **Website or API**

## Connections

- AI agent → MCP server: calls tools (evidence: `README.md`)
- AI agent → Framework adapters: uses integration (evidence: `README.md`)
- MCP server → Tool catalog: resolves names (evidence: `mcp/index.js`)
- MCP server → Tool search: searches tools (evidence: `README.md`)
- MCP server → Tool execution: invokes tools (evidence: `README.md`)
- Tool search → Tool catalog: finds matches
- AI agent → Smart router: requests routing (evidence: `README.md`)
- AI agent → Seller leaderboard: reads rankings (evidence: `README.md`)
- Decision service → Decision planner: parses decisions (evidence: `services/decide/server.js`)
- Decision service → AI agent: returns candidates
- Tool execution → LLM gateway: serves inference (evidence: `src/tools/llm-gateway-kit.js`)
- AI agent → Payment client: pays per call (evidence: `README.md`)
- Payment client → x402 seller: pays request (evidence: `README.md`)
- x402 seller → Payment networks: settles payments (evidence: `README.md`)
- AI agent → Reports and monitors: buys reports (evidence: `README.md`)
- Website or API → Tollbooth gate: gates requests (evidence: `README.md`)
- Tollbooth gate → Payment networks: collects payment (evidence: `tollbooth/index.js`)
- Edge tollbooth → Tollbooth gate: runs gate
- Tollbooth dashboard → Tollbooth gate: shows analytics (evidence: `tollbooth/index.js`)
