# bold-desk/live-chat-web-sdk architecture

> Architecture diagram of the GitHub repository bold-desk/live-chat-web-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bold-desk/live-chat-web-sdk
- Repository: https://github.com/bold-desk/live-chat-web-sdk

## Overview

##### Project type and purpose
- This is a lightweight, TypeScript-based npm SDK (a client‐side library) that wraps and exposes the BoldDesk Live Chat widget functionality to host web applications (React, Vue, Angular). Its sole purpose is to provide a smooth integration layer and full TS support, bundling the widget code and exposing a simple API.

a. SDK Source Module
- src/live-chat.ts: core wrapper that initializes the BoldDesk widget, exposes methods for showing the chat, setting visitor info, hooking into events, etc.
b. Build & Packaging Layer
- rollup.config.js + tsconfig.json: compile TS → ES5/ESNext, bundle into a single distributable .js file, generate type declarations, manage external dependencies.
c. Package Metadata
- package.json: describes entry points, dependencies, peerDependencies (e.g., framework adapters), and published bundle.
d. Host Application (Consumer)
- Any web app (React/Vue/Angular) that installs this SDK via npm/yarn, imports the module, and calls its API to embed the chat widget.
e. External BoldDesk Chat Service
- The remote BoldDesk backend (over WebSocket/HTTPS) that actually powers the chat sessions, stores transcripts, and manages agent routing.

##### Relationships & Data Flows
- The Host App imports the SDK bundle.
- At runtime, the SDK injects the chat widget’s JavaScript/CSS, initializes the connection to BoldDesk service.
- Data flows:
- Host App → SDK API calls (e.g., init, openWidget)
- SDK → BoldDesk service (session auth, message send/receive)
- BoldDesk service → SDK (incoming messages, events) → Host App callbacks
- Build‐time flows:
- src/ (TS) → Rollup → dist/sdk.bundle.js + .d.ts → npm registry

##### Key architectural patterns & principles
- Wrapper/Facade pattern: SDK provides a simplified facade over the raw widget API.
- Publish-Subscribe or Event Emitter: SDK likely exposes events (onMessage, onAgentJoined).
- Universal Module Definition: bundle configured to work in CJS/ESM/browser global.
- Strict typing: TS interfaces for configurables, responses, and events.

##### Technologies & frameworks
- TypeScript (tsconfig.json)
- Rollup.js (rollup.config.js) for bundling
- npm package system (package.json)
- BoldDesk REST/WebSocket APIs (external service)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build-Time Packaging
    subgraph "Build & Packaging" 
        direction TB
        SRC["src/live-chat.ts"]:::sdk
        ROLLUP["rollup.config.js"]:::sdk
        TSCONFIG["tsconfig.json"]:::sdk
        PKG_META["package.json"]:::sdk
        LOCKFILE["package-lock.json"]:::sdk
        DOCS["README.md"]:::sdk
        SRC -->|"compile & bundle"| ROLLUP
        SRC -->|"type check"| TSCONFIG
        ROLLUP -->|"bundle + types"| DIST
        TSCONFIG --> DIST
        PKG_META --> DIST
    end

    DIST["dist/sdk.bundle.js + .d.ts"]:::sdk
    DIST -->|"publish"| NPM["npm registry"]:::external

    %% Runtime Integration
    subgraph "Runtime Integration"
        direction TB
        HOST["Host Web Application<br/>(React/Vue/Angular)"]:::host
        SDKBUNDLE["SDK Bundle<br/>(CJS/ESM/UMD)"]:::sdk
        BOLD["BoldDesk Live Chat Service"]:::external
        HOST -->|"import via npm"| SDKBUNDLE
        HOST -->|"init(), openWidget(), sendMessage()"| SDKBUNDLE
        SDKBUNDLE -->|"HTTPS/WebSocket chat API"| BOLD
        BOLD -->|"onMessage(), onAgentJoined()"| SDKBUNDLE
        SDKBUNDLE -->|"event callbacks"| HOST
    end

    %% Click Events
    click SRC "https://github.com/bold-desk/live-chat-web-sdk/blob/development/src/live-chat.ts"
    click ROLLUP "https://github.com/bold-desk/live-chat-web-sdk/blob/development/rollup.config.js"
    click TSCONFIG "https://github.com/bold-desk/live-chat-web-sdk/blob/development/tsconfig.json"
    click PKG_META "https://github.com/bold-desk/live-chat-web-sdk/blob/development/package.json"
    click LOCKFILE "https://github.com/bold-desk/live-chat-web-sdk/blob/development/package-lock.json"
    click DOCS "https://github.com/bold-desk/live-chat-web-sdk/blob/development/README.md"

    %% Styles
    classDef sdk fill:#D0E8FF,stroke:#0050B3,color:#000;
    classDef host fill:#DFFFE0,stroke:#008000,color:#000;
    classDef external fill:#FFE0B2,stroke:#FF8C00,color:#000;
```
