# sugan-developerinnooryze-stack/leadryze_widget architecture

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

- Interactive diagram: https://gitdiagram.com/sugan-developerinnooryze-stack/leadryze_widget
- Repository: https://github.com/sugan-developerinnooryze-stack/leadryze_widget

## Overview

LeadRyze Chat Widget is a browser-embedded sales agent: a website visitor opens the widget, chats with the agent, and can be qualified into a CRM lead. The loader fetches tenant configuration and conversation history, then coordinates the Shadow-DOM UI and backend requests. The source also implements push-to-talk and continuous LiveKit voice, despite the README describing voice as out of scope. Backend and CRM stages are documented capabilities, not source modules in this repository; the sampled excerpts do not show every loader interaction.

Main entry points: [`src/loader.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/loader.ts) (Widget loader), [`src/voice/continuous.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/continuous.ts) (Continuous voice session), [`src/ui.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/ui.ts) (Chat interface), [`src/voice/voice-api.ts`](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/voice-api.ts) (Voice chat API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_embed["Embed and chat"]
  node_loader["Widget loader<br/>[loader.ts]"]
  node_config["API configuration<br/>[config.ts]"]
  node_identity["Visitor and session IDs<br/>[storage.ts]"]
  node_ui["Chat interface<br/>[ui.ts]"]
end

subgraph group_backend["Lead processing"]
  node_backend_api["Widget backend API"]
  node_ai_agent["AI sales agent"]
  node_crm[("LeadRyze CRM")]
end

subgraph group_voice["Voice interaction"]
  node_recorder["Audio recorder<br/>[recorder.ts]"]
  node_voice_api["Voice chat API client<br/>[voice-api.ts]"]
  node_player["Audio player<br/>[player.ts]"]
  node_continuous["Continuous voice session<br/>[continuous.ts]"]
  node_livekit["LiveKit service"]
end

subgraph group_voice_types["Voice contracts"]
  node_voice_types["Voice state and results<br/>[types.ts]"]
end

node_visitor(("Website visitor"))
node_tenant_site["Tenant website"]

node_tenant_site -->|"embeds script"| node_loader
node_visitor -->|"uses chat"| node_ui
node_loader -->|"reads API base"| node_config
node_loader -->|"gets IDs"| node_identity
node_loader -->|"fetches config, history"| node_backend_api
node_loader -->|"constructs and updates"| node_ui
node_ui -->|"invokes callbacks"| node_loader
node_loader -->|"sends chat"| node_backend_api
node_backend_api -->|"proxies requests"| node_ai_agent
node_ai_agent -->|"creates and assigns leads"| node_crm
node_loader -->|"starts recording"| node_recorder
node_loader -->|"submits recording"| node_voice_api
node_voice_api -->|"uploads voice chat"| node_backend_api
node_loader -->|"plays voice reply"| node_player
node_loader -->|"starts voice session"| node_continuous
node_continuous -->|"fetches voice token"| node_backend_api
node_continuous -->|"connects and streams"| node_livekit
node_continuous -->|"uses call state"| node_voice_types
node_voice_api -->|"returns voice result"| node_voice_types
node_ui -->|"uses call state"| node_voice_types

click node_loader "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/loader.ts"
click node_config "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/config.ts"
click node_identity "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/storage.ts"
click node_ui "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/ui.ts"
click node_recorder "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/recorder.ts"
click node_voice_api "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/voice-api.ts"
click node_player "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/player.ts"
click node_continuous "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/continuous.ts"
click node_voice_types "https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/types.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_loader,node_config,node_identity,node_ui toneBlue
class node_backend_api,node_ai_agent,node_crm toneAmber
class node_recorder,node_voice_api,node_player,node_continuous,node_livekit toneMint
class node_voice_types toneRose
class node_visitor,node_tenant_site toneIndigo
```

## Components

### Embed and chat

- [Widget loader](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/loader.ts): `src/loader.ts`
- [API configuration](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/config.ts): `src/config.ts`
- [Visitor and session IDs](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/storage.ts): `src/storage.ts`
- [Chat interface](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/ui.ts): `src/ui.ts`

### Lead processing

- **Widget backend API**
- **AI sales agent**
- **LeadRyze CRM**

### Voice interaction

- [Audio recorder](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/recorder.ts): `src/voice/recorder.ts`
- [Voice chat API client](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/voice-api.ts): `src/voice/voice-api.ts`
- [Audio player](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/player.ts): `src/voice/player.ts`
- [Continuous voice session](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/continuous.ts): `src/voice/continuous.ts`
- **LiveKit service**

### Voice contracts

- [Voice state and results](https://github.com/sugan-developerinnooryze-stack/leadryze_widget/blob/main/src/voice/types.ts): `src/voice/types.ts`

### Other components

- **Website visitor**
- **Tenant website**

## Connections

- Tenant website → Widget loader: embeds script (evidence: `README.md`)
- Website visitor → Chat interface: uses chat (evidence: `README.md`)
- Widget loader → API configuration: reads API base (evidence: `src/loader.ts`)
- Widget loader → Visitor and session IDs: gets IDs (evidence: `src/loader.ts`)
- Widget loader → Widget backend API: fetches config, history (evidence: `src/loader.ts`)
- Widget loader → Chat interface: constructs and updates (evidence: `src/loader.ts`)
- Chat interface → Widget loader: invokes callbacks (evidence: `src/ui.ts`)
- Widget loader → Widget backend API: sends chat (evidence: `src/loader.ts`)
- Widget backend API → AI sales agent: proxies requests (evidence: `README.md`)
- AI sales agent → LeadRyze CRM: creates and assigns leads (evidence: `README.md`)
- Widget loader → Audio recorder: starts recording (evidence: `src/loader.ts`)
- Widget loader → Voice chat API client: submits recording (evidence: `src/loader.ts`)
- Voice chat API client → Widget backend API: uploads voice chat (evidence: `src/voice/voice-api.ts`)
- Widget loader → Audio player: plays voice reply (evidence: `src/loader.ts`)
- Widget loader → Continuous voice session: starts voice session (evidence: `src/loader.ts`)
- Continuous voice session → Widget backend API: fetches voice token (evidence: `src/voice/continuous.ts`)
- Continuous voice session → LiveKit service: connects and streams (evidence: `src/voice/continuous.ts`)
- Continuous voice session → Voice state and results: uses call state (evidence: `src/voice/continuous.ts`)
- Voice chat API client → Voice state and results: returns voice result (evidence: `src/voice/voice-api.ts`)
- Chat interface → Voice state and results: uses call state (evidence: `src/ui.ts`)
