# manasi-choudhari/gandiva architecture

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

- Interactive diagram: https://gitdiagram.com/manasi-choudhari/gandiva
- Repository: https://github.com/manasi-choudhari/gandiva

## Overview

Gandiva is a pay-per-call marketplace for AI agents, with USDC payments over x402. The main workflow is: a user submits a task; Scout plans work, finds and ranks registry listings, and calls sellers through SafePayer; sellers verify payment, run their service, validate output, and settle; Scout validates the response, records the outcome, and returns a result visible through the dashboard and APIs. The graph also shows registry and ledger storage, payment safety layers, and the documented Ollama and Base Sepolia integrations. Some seller and buyer internals were only partially excerpted, so uncertain links are omitted.

Main entry points: [`src/sellers/index.ts`](https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/index.ts) (Seller routes), [`src/x402/paidRoute.ts`](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/paidRoute.ts) (Paid seller route), [`src/registry/store.ts`](https://github.com/manasi-choudhari/gandiva/blob/main/src/registry/store.ts) (Listings and reputation), [`src/x402/safePayer.ts`](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/safePayer.ts) (SafePayer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entry"]
  node_server["HTTP server<br/>[server.ts]"]
  node_dashboard["Dashboard<br/>[index.html]"]
end

subgraph group_buyer["Buyer workflow"]
  node_buyer_routes["Buyer API<br/>[routes.ts]"]
  node_scout["Scout orchestration<br/>[scout.ts]"]
  node_planner["Task planner<br/>[planner.ts]"]
end

subgraph group_market["Marketplace and sellers"]
  node_registry_routes["Registry API<br/>[routes.ts]"]
  node_registry_store["Listings and reputation<br/>[store.ts]"]
  node_seller_factory["Seller routes<br/>[index.ts]"]
  node_book_scraper["Book scraper<br/>[books.ts]"]
  node_fx_service["FX rates<br/>[fx.ts]"]
  node_llm_client["Ollama client<br/>[llm.ts]"]
end

subgraph group_payments["Payment safety"]
  node_paid_route["Paid seller route<br/>[paidRoute.ts]"]
  node_resource_server["x402 resource server<br/>[resourceServer.ts]"]
  node_safe_payer["SafePayer<br/>[safePayer.ts]"]
  node_budget["Budget reservations<br/>[budget.ts]"]
  node_schema["Schema validation<br/>[schema.ts]"]
end

subgraph group_state["Persistence"]
  node_sqlite[("SQLite database<br/>[db.ts]")]
end

node_user(("User or agent"))
node_facilitator{{"x402 facilitator"}}
node_base_usdc[("Base Sepolia USDC")]
node_ollama{{"Ollama service"}}

node_user -->|"submits task"| node_server
node_server -->|"mounts API"| node_buyer_routes
node_server -->|"mounts API"| node_registry_routes
node_server -->|"builds sellers"| node_seller_factory
node_buyer_routes -->|"dispatches requests"| node_scout
node_scout -->|"plans task"| node_planner
node_scout -->|"searches listings"| node_registry_store
node_scout -->|"pays sellers"| node_safe_payer
node_safe_payer -->|"reserves funds"| node_budget
node_safe_payer -->|"writes ledger"| node_registry_store
node_safe_payer -->|"validates response"| node_schema
node_safe_payer -->|"calls seller"| node_paid_route
node_registry_routes -->|"queries listings"| node_registry_store
node_seller_factory -->|"registers handlers"| node_paid_route
node_seller_factory -->|"seeds listings"| node_registry_store
node_seller_factory -->|"calls scraper"| node_book_scraper
node_seller_factory -->|"calls rates"| node_fx_service
node_seller_factory -->|"requests summaries"| node_llm_client
node_paid_route -->|"verifies and settles"| node_resource_server
node_paid_route -->|"checks seller output"| node_schema
node_paid_route -->|"records sales"| node_registry_store
node_resource_server -->|"verifies payment"| node_facilitator
node_facilitator -->|"settles transfer"| node_base_usdc
node_llm_client -->|"sends chat request"| node_ollama
node_registry_store -->|"reads and writes"| node_sqlite
node_paid_route -->|"claims nonce"| node_sqlite
node_dashboard -.->|"uses marketplace APIs"| node_registry_routes

click node_server "https://github.com/manasi-choudhari/gandiva/blob/main/src/server.ts"
click node_dashboard "https://github.com/manasi-choudhari/gandiva/blob/main/public/index.html"
click node_buyer_routes "https://github.com/manasi-choudhari/gandiva/blob/main/src/buyer/routes.ts"
click node_scout "https://github.com/manasi-choudhari/gandiva/blob/main/src/buyer/scout.ts"
click node_planner "https://github.com/manasi-choudhari/gandiva/blob/main/src/buyer/planner.ts"
click node_registry_routes "https://github.com/manasi-choudhari/gandiva/blob/main/src/registry/routes.ts"
click node_registry_store "https://github.com/manasi-choudhari/gandiva/blob/main/src/registry/store.ts"
click node_seller_factory "https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/index.ts"
click node_book_scraper "https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/books.ts"
click node_fx_service "https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/fx.ts"
click node_llm_client "https://github.com/manasi-choudhari/gandiva/blob/main/src/llm.ts"
click node_paid_route "https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/paidRoute.ts"
click node_resource_server "https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/resourceServer.ts"
click node_safe_payer "https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/safePayer.ts"
click node_budget "https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/budget.ts"
click node_schema "https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/schema.ts"
click node_sqlite "https://github.com/manasi-choudhari/gandiva/blob/main/src/db.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_server,node_dashboard,node_user toneBlue
class node_buyer_routes,node_scout,node_planner,node_base_usdc toneAmber
class node_registry_routes,node_registry_store,node_seller_factory,node_book_scraper,node_fx_service,node_llm_client toneMint
class node_paid_route,node_resource_server,node_safe_payer,node_budget,node_schema toneRose
class node_sqlite,node_facilitator,node_ollama toneIndigo
```

## Components

### Application entry

- [HTTP server](https://github.com/manasi-choudhari/gandiva/blob/main/src/server.ts): `src/server.ts`
- [Dashboard](https://github.com/manasi-choudhari/gandiva/blob/main/public/index.html): `public/index.html`

### Buyer workflow

- [Buyer API](https://github.com/manasi-choudhari/gandiva/blob/main/src/buyer/routes.ts): `src/buyer/routes.ts`
- [Scout orchestration](https://github.com/manasi-choudhari/gandiva/blob/main/src/buyer/scout.ts): `src/buyer/scout.ts`
- [Task planner](https://github.com/manasi-choudhari/gandiva/blob/main/src/buyer/planner.ts): `src/buyer/planner.ts`

### Marketplace and sellers

- [Registry API](https://github.com/manasi-choudhari/gandiva/blob/main/src/registry/routes.ts): `src/registry/routes.ts`
- [Listings and reputation](https://github.com/manasi-choudhari/gandiva/blob/main/src/registry/store.ts): `src/registry/store.ts`
- [Seller routes](https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/index.ts): `src/sellers/index.ts`
- [Book scraper](https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/books.ts): `src/sellers/books.ts`
- [FX rates](https://github.com/manasi-choudhari/gandiva/blob/main/src/sellers/fx.ts): `src/sellers/fx.ts`
- [Ollama client](https://github.com/manasi-choudhari/gandiva/blob/main/src/llm.ts): `src/llm.ts`

### Payment safety

- [Paid seller route](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/paidRoute.ts): `src/x402/paidRoute.ts`
- [x402 resource server](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/resourceServer.ts): `src/x402/resourceServer.ts`
- [SafePayer](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/safePayer.ts): `src/x402/safePayer.ts`
- [Budget reservations](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/budget.ts): `src/x402/budget.ts`
- [Schema validation](https://github.com/manasi-choudhari/gandiva/blob/main/src/x402/schema.ts): `src/x402/schema.ts`

### Persistence

- [SQLite database](https://github.com/manasi-choudhari/gandiva/blob/main/src/db.ts): `src/db.ts`

### Other components

- **User or agent**
- **x402 facilitator**
- **Base Sepolia USDC**
- **Ollama service**

## Connections

- User or agent → HTTP server: submits task (evidence: `README.md`)
- HTTP server → Buyer API: mounts API (evidence: `src/server.ts`)
- HTTP server → Registry API: mounts API (evidence: `src/server.ts`)
- HTTP server → Seller routes: builds sellers (evidence: `src/server.ts`)
- Buyer API → Scout orchestration: dispatches requests (evidence: `src/buyer/routes.ts`)
- Scout orchestration → Task planner: plans task (evidence: `src/buyer/scout.ts`)
- Scout orchestration → Listings and reputation: searches listings (evidence: `src/buyer/scout.ts`)
- Scout orchestration → SafePayer: pays sellers (evidence: `src/buyer/scout.ts`)
- SafePayer → Budget reservations: reserves funds (evidence: `src/x402/safePayer.ts`)
- SafePayer → Listings and reputation: writes ledger (evidence: `src/x402/safePayer.ts`)
- SafePayer → Schema validation: validates response (evidence: `src/x402/safePayer.ts`)
- SafePayer → Paid seller route: calls seller (evidence: `README.md`)
- Registry API → Listings and reputation: queries listings (evidence: `src/registry/routes.ts`)
- Seller routes → Paid seller route: registers handlers (evidence: `src/sellers/index.ts`)
- Seller routes → Listings and reputation: seeds listings (evidence: `src/sellers/index.ts`)
- Seller routes → Book scraper: calls scraper (evidence: `src/sellers/index.ts`)
- Seller routes → FX rates: calls rates (evidence: `src/sellers/index.ts`)
- Seller routes → Ollama client: requests summaries (evidence: `src/sellers/index.ts`)
- Paid seller route → x402 resource server: verifies and settles (evidence: `src/x402/paidRoute.ts`)
- Paid seller route → Schema validation: checks seller output (evidence: `src/x402/paidRoute.ts`)
- Paid seller route → Listings and reputation: records sales (evidence: `src/x402/paidRoute.ts`)
- x402 resource server → x402 facilitator: verifies payment (evidence: `README.md`)
- x402 facilitator → Base Sepolia USDC: settles transfer (evidence: `README.md`)
- Ollama client → Ollama service: sends chat request (evidence: `src/llm.ts`)
- Listings and reputation → SQLite database: reads and writes (evidence: `src/registry/store.ts`)
- Paid seller route → SQLite database: claims nonce (evidence: `src/x402/paidRoute.ts`)
- Dashboard → Registry API: uses marketplace APIs (evidence: `README.md`)
