# ritikmdsgithub/flowisechatembed architecture

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

- Interactive diagram: https://gitdiagram.com/ritikmdsgithub/flowisechatembed
- Repository: https://github.com/ritikmdsgithub/flowisechatembed

## Overview

##### Project Type & Purpose
- This is a front-end JavaScript/TypeScript UI library (“Flowise Embed”) designed to be embedded in any website.
- It provides a chatbot widget (popup or full-page) that communicates with an external Flowise API server.

##### File Structure Analysis
- Top-level:
- src/ – React + TSX source code for all UI components, features, utilities, queries, and initialization logic.
- dist/ – Built output (ES modules, type declarations, web.js) produced by Rollup.
- rollup.config.js, package.json, tsconfig.json – Build configuration.
- src/register.tsx & src/web.ts – Bootstrapper files that expose Chatbot.init and Chatbot.initFull via a web entry point.

##### README Insights
- Shows how end users embed the library via a `<script type="module">` tag pointing to dist/web.js or CDN.
- Describes two modes: PopUp (injected button that launches chat widget) and FullPage (custom element `<flowise-fullchatbot>`).
- Highlights configuration options (theme, observers, chatflowConfig) that flow from init functions into the React component tree.

##### Main Components
a. Host Website
- Contains: the embedding `<script>`, optional `<flowise-fullchatbot>` element, and custom styling on `<body>`.
b. Flowise-Embed SDK (Client Library)
- Initialization Layer
– Chatbot.init() & Chatbot.initFull(): parse user config, mount React root.
- UI Layer
- Communication Layer
– sendMessageQuery.ts and fetch wrappers in utils: handle HTTP calls to `apiHost`.
- Utilities
– audioRecording, isMobileSignal, event observers.
- Packaging
– Rollup-packaged modules (ESM, UMD distributions, type definitions).
c. External Flowise API Server
- Receives chatflowid and messages, returns bot responses.

##### Relationships & Data Flows
- Host Website loads the SDK via `<script>` → SDK Initialization Layer instantiates React UI into DOM.
- UI Layer renders chat elements based on user interaction → Communication Layer sends requests to the API Host over HTTP.
- API Host responds → Communication Layer relays responses back into UI Layer → UI updates bubble components.
- Observers (callbacks) emit signals back to Host Website if configured.

##### Architectural Patterns & Design Principles
- Feature-based organization: three feature modes (bubble/popup/full) isolated under src/features.
- Separation of concerns: UI vs data fetching vs initialization vs utilities.
- Build-time bundling: Rollup used to produce optimized, tree-shakable outputs in dist/.

##### Elements
- Clear labels for each layer and folder grouping (src/components, src/features, src/utils, src/queries).
- Blue for code modules,
- Green for network interactions,
- Orange for DOM/host interactions.
- Rectangles for code,

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Host Website
    HostWebsite("Host Website<br/>(<script> & &lt;flowise-fullchatbot&gt;)"):::host

    %% Flowise Embed SDK Container
    subgraph "Flowise Embed SDK"
        direction TB
        subgraph "Initialization Layer"
            direction TB
            ChatbotInit["Chatbot.init Module"]:::code
            ChatbotFull["Chatbot.initFull Module"]:::code
        end

        subgraph "UI Layer"
            direction TB
            CoreComponents["Components (src/components)"]:::code
            subgraph "Feature Modes"
                direction TB
                BubbleFeature["Bubble Feature<br/>(src/features/bubble/)"]:::code
                PopupFeature["Popup Feature<br/>(src/features/popup/)"]:::code
                FullFeature["FullPage Feature<br/>(src/features/full/)"]:::code
            end
        end

        subgraph "Communication Layer"
            direction TB
            SendMessageQuery["sendMessageQuery.ts"]:::network
        end

        subgraph "Utilities"
            direction TB
            Utils["Utilities (src/utils)"]:::code
        end

        subgraph "Packaging & Distribution"
            direction TB
            Packaging["dist/web.js"]:::code
        end
    end

    %% External API Host
    APIHost(("(External Flowise API Server)")):::network

    %% Connections
    HostWebsite -->|"load SDK script"| ChatbotInit
    HostWebsite -->|"load SDK script"| ChatbotFull
    ChatbotInit -->|"mount React UI"| CoreComponents
    ChatbotFull -->|"mount React UI"| CoreComponents
    CoreComponents -->|"uses features"| BubbleFeature
    CoreComponents -->|"uses features"| PopupFeature
    CoreComponents -->|"uses features"| FullFeature
    BubbleFeature -->|"render UI components"| CoreComponents
    PopupFeature -->|"render UI components"| CoreComponents
    FullFeature -->|"render UI components"| CoreComponents
    CoreComponents -->|"invoke HTTP"| SendMessageQuery
    SendMessageQuery -->|"HTTP POST /messages"| APIHost
    APIHost -->|"response"| SendMessageQuery
    SendMessageQuery -->|"callback data"| CoreComponents
    CoreComponents -->|"observer callbacks"| HostWebsite

    %% Click Events
    click ChatbotInit "https://github.com/ritikmdsgithub/flowisechatembed/blob/main/src/register.tsx"
    click ChatbotFull "https://github.com/ritikmdsgithub/flowisechatembed/blob/main/src/web.ts"
    click CoreComponents "https://github.com/ritikmdsgithub/flowisechatembed/tree/main/src/components"
    click BubbleFeature "https://github.com/ritikmdsgithub/flowisechatembed/tree/main/src/features/bubble/"
    click PopupFeature "https://github.com/ritikmdsgithub/flowisechatembed/tree/main/src/features/popup/"
    click FullFeature "https://github.com/ritikmdsgithub/flowisechatembed/tree/main/src/features/full/"
    click SendMessageQuery "https://github.com/ritikmdsgithub/flowisechatembed/blob/main/src/queries/sendMessageQuery.ts"
    click Utils "https://github.com/ritikmdsgithub/flowisechatembed/tree/main/src/utils"
    click Packaging "https://github.com/ritikmdsgithub/flowisechatembed/blob/main/dist/web.js"

    %% Styles
    classDef code fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1,stroke-width:1px;
    classDef network fill:#C8E6C9,stroke:#388E3C,color:#1B5E20,stroke-width:1px;
    classDef host fill:#FFE0B2,stroke:#F57C00,color:#E65100,stroke-width:1px;
```
