# codewithmuh/shopagent architecture

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

- Interactive diagram: https://gitdiagram.com/codewithmuh/shopagent
- Repository: https://github.com/codewithmuh/shopagent

## Overview

ShopAgent is a multi-tenant shopping assistant: shoppers converse with Leo to find products and place or track orders; merchants connect Shopify to populate the catalog; companies embed the agent and authorize payments through webhooks. The graph preserves these workflows plus voice, merchant operations, and company access. Edges rely on README statements, shown excerpts, or SOURCE INDEX references; unsampled implementations and uncertain links are omitted.

Main entry points: [`backend/agent/tools.py`](https://github.com/codewithmuh/shopagent/blob/main/backend/agent/tools.py) (Shopping tools), [`backend/integrations/shopify.py`](https://github.com/codewithmuh/shopagent/blob/main/backend/integrations/shopify.py) (Shopify sync), [`frontend/src/components/chat/ChatWidget.tsx`](https://github.com/codewithmuh/shopagent/blob/main/frontend/src/components/chat/ChatWidget.tsx) (Shopper chat), [`backend/integrations/webhooks.py`](https://github.com/codewithmuh/shopagent/blob/main/backend/integrations/webhooks.py) (Payment webhooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shopper["Shopper experience"]
  node_shopper_ui["Shopper chat<br/>[ChatWidget.tsx]"]
  node_voice["Voice mode<br/>[VoiceMode.tsx]"]
  node_ws_client["WebSocket client<br/>[websocket.ts]"]
end

subgraph group_agent["Agent and commerce"]
  node_agent_socket["Agent consumer<br/>[consumers.py]"]
  node_agent_loop["Claude tool loop<br/>[agent.py]"]
  node_agent_memory["Conversation memory<br/>[memory.py]"]
  node_shopping_tools["Shopping tools<br/>[tools.py]"]
  node_catalog[("Product catalog<br/>[models.py]")]
  node_shopper_data[("Users and addresses<br/>[models.py]")]
  node_orders[("Orders<br/>[models.py]")]
end

subgraph group_merchant["Merchant catalog"]
  node_merchant_user[("Merchant<br/>[models.py]")]
  node_merchant_portal["Merchant portal<br/>[page.tsx]"]
  node_merchant_api["Merchant API<br/>[views.py]"]
  node_shopify_sync["Shopify sync<br/>[shopify.py]"]
end

subgraph group_company["Company integration"]
  node_company_portal["Company portal<br/>[page.tsx]"]
  node_company_auth["API key authentication<br/>[authentication.py]"]
  node_company_data[("Company and usage<br/>[models.py]")]
  node_webhook_client["Payment webhooks<br/>[webhooks.py]"]
end

node_shopper(("Shopper"))
node_shopify{{"Shopify"}}
node_s3[("Image storage")]
node_company_user(("Company operator"))
node_host_app{{"Host application"}}

node_shopper -->|"chats with"| node_shopper_ui
node_shopper_ui -.->|"sends messages"| node_ws_client
node_ws_client -->|"opens WebSocket"| node_agent_socket
node_agent_socket -->|"dispatches to"| node_agent_loop
node_agent_loop -->|"uses tools"| node_shopping_tools
node_agent_socket -->|"references"| node_agent_memory
node_shopping_tools -->|"accesses catalog"| node_catalog
node_shopping_tools -->|"manages users"| node_shopper_data
node_shopping_tools -->|"handles orders"| node_orders
node_voice -->|"adds voice"| node_shopper_ui
node_shopper_ui -->|"offers voice mode"| node_voice
node_merchant_user -->|"manages store"| node_merchant_portal
node_merchant_portal -->|"connects Shopify"| node_merchant_api
node_merchant_api -->|"starts sync"| node_shopify_sync
node_shopify_sync -->|"fetches products"| node_shopify
node_shopify_sync -->|"updates products"| node_catalog
node_shopify_sync -.->|"stores images"| node_s3
node_company_user -->|"manages integration"| node_company_portal
node_company_portal -->|"uses credentials"| node_company_auth
node_company_auth -->|"validates company"| node_company_data
node_company_data -->|"configures payments"| node_webhook_client
node_shopping_tools -->|"requests payment checks"| node_webhook_client
node_webhook_client -->|"sends signed events"| node_host_app
node_webhook_client -->|"logs webhook"| node_company_data

click node_shopper_ui "https://github.com/codewithmuh/shopagent/blob/main/frontend/src/components/chat/ChatWidget.tsx"
click node_voice "https://github.com/codewithmuh/shopagent/blob/main/frontend/src/components/chat/VoiceMode.tsx"
click node_ws_client "https://github.com/codewithmuh/shopagent/blob/main/frontend/src/lib/websocket.ts"
click node_agent_socket "https://github.com/codewithmuh/shopagent/blob/main/backend/agent/consumers.py"
click node_agent_loop "https://github.com/codewithmuh/shopagent/blob/main/backend/agent/agent.py"
click node_agent_memory "https://github.com/codewithmuh/shopagent/blob/main/backend/agent/memory.py"
click node_shopping_tools "https://github.com/codewithmuh/shopagent/blob/main/backend/agent/tools.py"
click node_catalog "https://github.com/codewithmuh/shopagent/blob/main/backend/products/models.py"
click node_shopper_data "https://github.com/codewithmuh/shopagent/blob/main/backend/users/models.py"
click node_orders "https://github.com/codewithmuh/shopagent/blob/main/backend/orders/models.py"
click node_merchant_user "https://github.com/codewithmuh/shopagent/blob/main/backend/merchants/models.py"
click node_merchant_portal "https://github.com/codewithmuh/shopagent/blob/main/frontend/src/app/merchant/connections/page.tsx"
click node_merchant_api "https://github.com/codewithmuh/shopagent/blob/main/backend/merchants/views.py"
click node_shopify_sync "https://github.com/codewithmuh/shopagent/blob/main/backend/integrations/shopify.py"
click node_company_portal "https://github.com/codewithmuh/shopagent/blob/main/frontend/src/app/portal/dashboard/page.tsx"
click node_company_auth "https://github.com/codewithmuh/shopagent/blob/main/backend/companies/authentication.py"
click node_company_data "https://github.com/codewithmuh/shopagent/blob/main/backend/companies/models.py"
click node_webhook_client "https://github.com/codewithmuh/shopagent/blob/main/backend/integrations/webhooks.py"

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_shopper_ui,node_voice,node_ws_client toneBlue
class node_agent_socket,node_agent_loop,node_agent_memory,node_shopping_tools,node_catalog,node_shopper_data,node_orders,node_s3 toneAmber
class node_merchant_user,node_merchant_portal,node_merchant_api,node_shopify_sync toneMint
class node_company_portal,node_company_auth,node_company_data,node_webhook_client toneRose
class node_shopper,node_shopify,node_company_user,node_host_app toneIndigo
```

## Components

### Shopper experience

- [Shopper chat](https://github.com/codewithmuh/shopagent/blob/main/frontend/src/components/chat/ChatWidget.tsx): `frontend/src/components/chat/ChatWidget.tsx`
- [Voice mode](https://github.com/codewithmuh/shopagent/blob/main/frontend/src/components/chat/VoiceMode.tsx): `frontend/src/components/chat/VoiceMode.tsx`
- [WebSocket client](https://github.com/codewithmuh/shopagent/blob/main/frontend/src/lib/websocket.ts): `frontend/src/lib/websocket.ts`

### Agent and commerce

- [Agent consumer](https://github.com/codewithmuh/shopagent/blob/main/backend/agent/consumers.py): `backend/agent/consumers.py`
- [Claude tool loop](https://github.com/codewithmuh/shopagent/blob/main/backend/agent/agent.py): `backend/agent/agent.py`
- [Conversation memory](https://github.com/codewithmuh/shopagent/blob/main/backend/agent/memory.py): `backend/agent/memory.py`
- [Shopping tools](https://github.com/codewithmuh/shopagent/blob/main/backend/agent/tools.py): `backend/agent/tools.py`
- [Product catalog](https://github.com/codewithmuh/shopagent/blob/main/backend/products/models.py): `backend/products/models.py`
- [Users and addresses](https://github.com/codewithmuh/shopagent/blob/main/backend/users/models.py): `backend/users/models.py`
- [Orders](https://github.com/codewithmuh/shopagent/blob/main/backend/orders/models.py): `backend/orders/models.py`

### Merchant catalog

- [Merchant](https://github.com/codewithmuh/shopagent/blob/main/backend/merchants/models.py): `backend/merchants/models.py`
- [Merchant portal](https://github.com/codewithmuh/shopagent/blob/main/frontend/src/app/merchant/connections/page.tsx): `frontend/src/app/merchant/connections/page.tsx`
- [Merchant API](https://github.com/codewithmuh/shopagent/blob/main/backend/merchants/views.py): `backend/merchants/views.py`
- [Shopify sync](https://github.com/codewithmuh/shopagent/blob/main/backend/integrations/shopify.py): `backend/integrations/shopify.py`

### Company integration

- [Company portal](https://github.com/codewithmuh/shopagent/blob/main/frontend/src/app/portal/dashboard/page.tsx): `frontend/src/app/portal/dashboard/page.tsx`
- [API key authentication](https://github.com/codewithmuh/shopagent/blob/main/backend/companies/authentication.py): `backend/companies/authentication.py`
- [Company and usage](https://github.com/codewithmuh/shopagent/blob/main/backend/companies/models.py): `backend/companies/models.py`
- [Payment webhooks](https://github.com/codewithmuh/shopagent/blob/main/backend/integrations/webhooks.py): `backend/integrations/webhooks.py`

### Other components

- **Shopper**
- **Shopify**
- **Image storage**
- **Company operator**
- **Host application**

## Connections

- Shopper → Shopper chat: chats with (evidence: `README.md`)
- Shopper chat → WebSocket client: sends messages
- WebSocket client → Agent consumer: opens WebSocket (evidence: `README.md`)
- Agent consumer → Claude tool loop: dispatches to (evidence: `backend/agent/consumers.py`)
- Claude tool loop → Shopping tools: uses tools (evidence: `README.md`)
- Agent consumer → Conversation memory: references (evidence: `backend/agent/consumers.py`)
- Shopping tools → Product catalog: accesses catalog (evidence: `backend/agent/tools.py`)
- Shopping tools → Users and addresses: manages users (evidence: `backend/agent/tools.py`)
- Shopping tools → Orders: handles orders (evidence: `backend/agent/tools.py`)
- Voice mode → Shopper chat: adds voice (evidence: `README.md`)
- Shopper chat → Voice mode: offers voice mode (evidence: `README.md`)
- Merchant → Merchant portal: manages store (evidence: `README.md`)
- Merchant portal → Merchant API: connects Shopify (evidence: `README.md`)
- Merchant API → Shopify sync: starts sync (evidence: `backend/merchants/views.py`)
- Shopify sync → Shopify: fetches products (evidence: `backend/integrations/shopify.py`)
- Shopify sync → Product catalog: updates products (evidence: `backend/integrations/shopify.py`)
- Shopify sync → Image storage: stores images (evidence: `backend/integrations/shopify.py`)
- Company operator → Company portal: manages integration (evidence: `README.md`)
- Company portal → API key authentication: uses credentials (evidence: `README.md`)
- API key authentication → Company and usage: validates company (evidence: `backend/companies/authentication.py`)
- Company and usage → Payment webhooks: configures payments (evidence: `README.md`)
- Shopping tools → Payment webhooks: requests payment checks (evidence: `backend/agent/tools.py`)
- Payment webhooks → Host application: sends signed events (evidence: `backend/integrations/webhooks.py`)
- Payment webhooks → Company and usage: logs webhook (evidence: `backend/integrations/webhooks.py`)
