# pranavagarwal2101-byte/concord-ai architecture

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

- Interactive diagram: https://gitdiagram.com/pranavagarwal2101-byte/concord-ai
- Repository: https://github.com/pranavagarwal2101-byte/concord-ai

## Overview

Concord is a merchant-side commerce API that lets AI buyer agents discover products and propose purchases while server-side policy and a human approval gate control payment. The main flow is chat → agent tool dispatch → catalog search → policy evaluation → checkout intent and confirmation → Razorpay verification, with trace-linked audit records shown live or reconstructed in the browser. The graph also includes the browser’s direct checkout driver and audit views. Relationships follow the excerpts, SOURCE INDEX references, and README; unsampled route wiring is not inferred.

Main entry points: [`apps/server/src/checkout/confirm.ts`](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/confirm.ts) (Checkout confirmation), [`apps/server/src/audit/writer.ts`](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/audit/writer.ts) (Audit writer), [`apps/server/src/agent/loop.ts`](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/loop.ts) (Agent loop), [`apps/web/src/components/Chat.tsx`](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/Chat.tsx) (Chat UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_buyer["Buyer experience"]
  node_webapp["Demo app<br/>[App.tsx]"]
  node_chat["Chat UI<br/>[Chat.tsx]"]
  node_chatstate["Chat state<br/>[useAgentChat.ts]"]
  node_checkoutdriver["Checkout driver<br/>[CheckoutDriver.tsx]"]
  node_widget["Payment widget"]
  node_api["Browser API<br/>[api.ts]"]
end

subgraph group_agent["Agent and discovery"]
  node_agentroute["Agent endpoint<br/>[agent.ts]"]
  node_loop["Agent loop<br/>[loop.ts]"]
  node_gemini["Gemini client<br/>[client.ts]"]
  node_tools["Tool declarations<br/>[tools.ts]"]
  node_catalog["Catalog search<br/>[search.ts]"]
  node_products["Product repository<br/>[repository.ts]"]
end

subgraph group_commerce["Commerce controls"]
  node_policy["Checkout policy"]
  node_initiate["Checkout initiation<br/>[initiate.ts]"]
  node_confirm["Checkout confirmation<br/>[confirm.ts]"]
  node_intents["Checkout intents<br/>[intents.ts]"]
  node_state["Checkout state<br/>[state-machine.ts]"]
  node_razorpay["Razorpay gateway<br/>[razorpay.ts]"]
  node_verify["Payment verification<br/>[verify.ts]"]
end

subgraph group_observability["Audit and trace"]
  node_auditwriter["Audit writer<br/>[writer.ts]"]
  node_auditquery["Audit query<br/>[query.ts]"]
  node_auditpanel["Audit panel<br/>[AuditPanel.tsx]"]
  node_auditstream["Audit stream hook<br/>[useAuditStream.ts]"]
  node_sqlite[("SQLite database<br/>[index.ts]")]
end

subgraph group_shared["Shared contracts"]
  node_contracts["Shared contracts<br/>[checkout.ts]"]
end

node_buyer(("Buyer"))

node_buyer -->|"sends messages"| node_chat
node_webapp -->|"renders"| node_chat
node_webapp -->|"renders"| node_checkoutdriver
node_webapp -->|"renders"| node_auditpanel
node_chat -->|"uses"| node_chatstate
node_chat -->|"renders"| node_widget
node_chatstate -->|"posts chat"| node_api
node_api -.->|"calls"| node_agentroute
node_checkoutdriver -->|"opens handoff"| node_widget
node_widget -->|"submits verification"| node_verify
node_agentroute -->|"runs"| node_loop
node_loop -->|"requests generation"| node_gemini
node_gemini -->|"declares tools"| node_tools
node_loop -->|"dispatches calls"| node_tools
node_loop -.->|"searches catalog"| node_catalog
node_catalog -.->|"loads products"| node_products
node_initiate -.->|"gets catalog"| node_products
node_initiate -.->|"evaluates checkout"| node_policy
node_confirm -->|"rechecks quote"| node_policy
node_confirm -->|"finds token"| node_intents
node_confirm -->|"locks and advances"| node_state
node_confirm -->|"creates order"| node_razorpay
node_verify -.->|"verifies payment"| node_razorpay
node_auditwriter -->|"writes entries"| node_sqlite
node_auditquery -->|"reads entries"| node_sqlite
node_auditpanel -->|"uses live stream"| node_auditstream
node_auditstream -.->|"receives SSE events"| node_auditwriter
node_auditpanel -.->|"loads trace history"| node_auditquery
node_policy -.->|"records decisions"| node_auditwriter
node_confirm -->|"records outcomes"| node_auditwriter
node_agentroute -->|"records agent events"| node_auditwriter
node_chatstate -->|"uses checkout shape"| node_contracts

click node_webapp "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/App.tsx"
click node_chat "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/Chat.tsx"
click node_chatstate "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/hooks/useAgentChat.ts"
click node_checkoutdriver "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/CheckoutDriver.tsx"
click node_widget "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/RazorpayCheckout.tsx"
click node_api "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/lib/api.ts"
click node_agentroute "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/routes/agent.ts"
click node_loop "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/loop.ts"
click node_gemini "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/client.ts"
click node_tools "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/tools.ts"
click node_catalog "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/catalog/search.ts"
click node_products "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/catalog/repository.ts"
click node_policy "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/policy/evaluate-checkout.ts"
click node_initiate "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/initiate.ts"
click node_confirm "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/confirm.ts"
click node_intents "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/intents.ts"
click node_state "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/state-machine.ts"
click node_razorpay "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/payments/razorpay.ts"
click node_verify "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/verify.ts"
click node_auditwriter "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/audit/writer.ts"
click node_auditquery "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/audit/query.ts"
click node_auditpanel "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/AuditPanel.tsx"
click node_auditstream "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/hooks/useAuditStream.ts"
click node_sqlite "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/db/index.ts"
click node_contracts "https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/packages/shared/src/schema/checkout.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_webapp,node_chat,node_chatstate,node_checkoutdriver,node_widget,node_api toneBlue
class node_agentroute,node_loop,node_gemini,node_tools,node_catalog,node_products toneAmber
class node_policy,node_initiate,node_confirm,node_intents,node_state,node_razorpay,node_verify toneMint
class node_auditwriter,node_auditquery,node_auditpanel,node_auditstream,node_sqlite toneRose
class node_contracts,node_buyer toneIndigo
```

## Components

### Buyer experience

- [Demo app](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [Chat UI](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/Chat.tsx): `apps/web/src/components/Chat.tsx`
- [Chat state](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/hooks/useAgentChat.ts): `apps/web/src/hooks/useAgentChat.ts`
- [Checkout driver](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/CheckoutDriver.tsx): `apps/web/src/components/CheckoutDriver.tsx`
- [Payment widget](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/RazorpayCheckout.tsx): `apps/web/src/components/RazorpayCheckout.tsx`
- [Browser API](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/lib/api.ts): `apps/web/src/lib/api.ts`

### Agent and discovery

- [Agent endpoint](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/routes/agent.ts): `apps/server/src/routes/agent.ts`
- [Agent loop](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/loop.ts): `apps/server/src/agent/loop.ts`
- [Gemini client](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/client.ts): `apps/server/src/agent/client.ts`
- [Tool declarations](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/agent/tools.ts): `apps/server/src/agent/tools.ts`
- [Catalog search](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/catalog/search.ts): `apps/server/src/catalog/search.ts`
- [Product repository](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/catalog/repository.ts): `apps/server/src/catalog/repository.ts`

### Commerce controls

- [Checkout policy](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/policy/evaluate-checkout.ts): `apps/server/src/policy/evaluate-checkout.ts`
- [Checkout initiation](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/initiate.ts): `apps/server/src/checkout/initiate.ts`
- [Checkout confirmation](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/confirm.ts): `apps/server/src/checkout/confirm.ts`
- [Checkout intents](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/intents.ts): `apps/server/src/checkout/intents.ts`
- [Checkout state](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/state-machine.ts): `apps/server/src/checkout/state-machine.ts`
- [Razorpay gateway](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/payments/razorpay.ts): `apps/server/src/payments/razorpay.ts`
- [Payment verification](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/checkout/verify.ts): `apps/server/src/checkout/verify.ts`

### Audit and trace

- [Audit writer](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/audit/writer.ts): `apps/server/src/audit/writer.ts`
- [Audit query](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/audit/query.ts): `apps/server/src/audit/query.ts`
- [Audit panel](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/components/AuditPanel.tsx): `apps/web/src/components/AuditPanel.tsx`
- [Audit stream hook](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/web/src/hooks/useAuditStream.ts): `apps/web/src/hooks/useAuditStream.ts`
- [SQLite database](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/apps/server/src/db/index.ts): `apps/server/src/db/index.ts`

### Shared contracts

- [Shared contracts](https://github.com/pranavagarwal2101-byte/concord-ai/blob/main/packages/shared/src/schema/checkout.ts): `packages/shared/src/schema/checkout.ts`

### Other components

- **Buyer**

## Connections

- Buyer → Chat UI: sends messages
- Demo app → Chat UI: renders (evidence: `apps/web/src/App.tsx`)
- Demo app → Checkout driver: renders (evidence: `apps/web/src/App.tsx`)
- Demo app → Audit panel: renders (evidence: `apps/web/src/App.tsx`)
- Chat UI → Chat state: uses (evidence: `apps/web/src/components/Chat.tsx`)
- Chat UI → Payment widget: renders (evidence: `apps/web/src/components/Chat.tsx`)
- Chat state → Browser API: posts chat (evidence: `apps/web/src/hooks/useAgentChat.ts`)
- Browser API → Agent endpoint: calls
- Checkout driver → Payment widget: opens handoff (evidence: `apps/web/src/components/CheckoutDriver.tsx`)
- Payment widget → Payment verification: submits verification (evidence: `apps/web/src/components/RazorpayCheckout.tsx`)
- Agent endpoint → Agent loop: runs (evidence: `apps/server/src/routes/agent.ts`)
- Agent loop → Gemini client: requests generation (evidence: `apps/server/src/agent/loop.ts`)
- Gemini client → Tool declarations: declares tools (evidence: `apps/server/src/agent/client.ts`)
- Agent loop → Tool declarations: dispatches calls (evidence: `apps/server/src/agent/loop.ts`)
- Agent loop → Catalog search: searches catalog
- Catalog search → Product repository: loads products
- Checkout initiation → Product repository: gets catalog
- Checkout initiation → Checkout policy: evaluates checkout
- Checkout confirmation → Checkout policy: rechecks quote (evidence: `apps/server/src/checkout/confirm.ts`)
- Checkout confirmation → Checkout intents: finds token (evidence: `apps/server/src/checkout/confirm.ts`)
- Checkout confirmation → Checkout state: locks and advances (evidence: `apps/server/src/checkout/confirm.ts`)
- Checkout confirmation → Razorpay gateway: creates order (evidence: `apps/server/src/checkout/confirm.ts`)
- Payment verification → Razorpay gateway: verifies payment
- Audit writer → SQLite database: writes entries (evidence: `apps/server/src/audit/writer.ts`)
- Audit query → SQLite database: reads entries (evidence: `apps/server/src/audit/query.ts`)
- Audit panel → Audit stream hook: uses live stream (evidence: `apps/web/src/components/AuditPanel.tsx`)
- Audit stream hook → Audit writer: receives SSE events
- Audit panel → Audit query: loads trace history
- Checkout policy → Audit writer: records decisions
- Checkout confirmation → Audit writer: records outcomes (evidence: `apps/server/src/checkout/confirm.ts`)
- Agent endpoint → Audit writer: records agent events (evidence: `apps/server/src/routes/agent.ts`)
- Chat state → Shared contracts: uses checkout shape (evidence: `apps/web/src/hooks/useAgentChat.ts`)
