How ritikmdsgithub/flowisechatembed works
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,