# sendbird/sendbird-uikit-react architecture

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

- Interactive diagram: https://gitdiagram.com/sendbird/sendbird-uikit-react
- Repository: https://github.com/sendbird/sendbird-uikit-react

## Overview

##### Project Type and Purpose
- This is a React-based UI kit library (“@sendbird/uikit-react”) that sits on top of the Sendbird JavaScript SDK.
- It provides ready-made, modular chat components (Channel, ChannelList, ChannelSettings, MessageSearch, OpenChannel, etc.) and an App shell that consumers can drop into their own web/mobile React projects.
- The repo also includes two demo apps (apps/testing and apps/visual-test) and a Storybook for visualizing components.

##### High-Level File Structure & Architecture
- Top-level config: CI/CD (.circleci/, .github/workflows), linting & formatting (.eslintrc.js, .stylelintrc.js), package management (yarnrc.yml, .yarn/), and build scripts (rollup.config.mjs, plopfile.js, scripts/).
- `src/` – the core library:
- `_externals/`: third-party libs (lamejs).
- `hooks/`: generic React hooks.
- `lib/`: Sendbird context provider, pubSub, handlers for SDK events.
- `modules/`: feature modules (Channel, GroupChannel, ChannelList, ChannelSettings, CreateChannel, Thread, etc.). Each module has its own React context provider, hooks, dux (redux-like local state), and presentational sub-components.
- `ui/`: low-level, reusable presentational components (Button, Avatar, Modal, MessageInput, etc.).
- `utils/`: shared utility functions and type helpers.
- `stories/`: Storybook stories and MDX docs.
- `apps/` – local demo projects:
- `apps/testing`: Vite-based playground using env variables for Sendbird App ID.
- `apps/visual-test`: visual regression test harness.
- Tests & CI:
- Unit & integration tests with Jest (`jest.config.js`, `jest-setup.js`).
- Visual tests (Playwright).
- CI pipelines automate lint, test, coverage, Storybook deployment, and package publishing.

##### Key Architectural Patterns
- Layered, modular design:
1. Core SDK layer (Sendbird JS SDK & external libs).
2. Context & state management layer (`lib/Sendbird`, module‐specific providers, dux).
3. Feature modules (`modules/*`): each encapsulates its own context, hooks, UI composition.
4. UI component layer (`ui/*`): stateless, reusable presentational components.
- React Context for global state (`SendBirdProvider`) and feature state (e.g., `ChannelProvider`).
- PubSub and event handlers abstract SDK callbacks.
- Pluggable build & code generation via Plop.js templates.

- Consumer Application
- Imports `@sendbird/uikit-react` (core library).
- Wraps root in `<SendBirdProvider>` → provides SDK, connection status.
- Renders feature components (`<App>`, `<ChannelList>`, `<Channel>`, etc.).
- UI Kit Library (`src/`)
- External Dependencies: React, TypeScript, Sendbird JS SDK, LameJS.
- Core Context Layer: `SendBirdProvider` → context value includes SDK instance, connection handlers.
- Module Layer: for each feature (Channel, GroupChannel, OpenChannel, etc.):
– React Context Provider
– Hooks for fetching data, sending messages, handling events
– Internal state (dux)
– Composition of `ui/` components
- UI Layer: generic UI components (Button, Avatar, Modal, etc.) consumed by modules.
- Development & Build Tools
- Vite Dev Server (`apps/testing`) and Storybook
- RollupJS build pipeline
- Plop.js scaffolding for new components
- Yarn Berry workspaces and SDK integrations
- CI/CD Pipelines
- GitHub Actions / CircleCI: lint → test → coverage → storybook deploy → npm publish

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer Application
    ConsumerApp["Consumer Application"]:::consumer
    ConsumerApp -->|"imports & uses"| UIKitLibrary

    %% UI Kit Library Layer
    subgraph "UI Kit Library" 
        direction TB
        subgraph "Core Context Layer"
            direction TB
            SendBirdProvider["SendBirdProvider"]:::core
            SendbirdContext["SendbirdContext"]:::core
        end
        PubSub["PubSub Module"]:::core
        subgraph "SDK Event Handlers"
            direction TB
            ConnectionHandler["ConnectionHandler"]:::core
            GroupChannelHandler["GroupChannelHandler"]:::core
            OpenChannelHandler["OpenChannelHandler"]:::core
            SessionHandler["SessionHandler"]:::core
            UserEventHandler["UserEventHandler"]:::core
        end
        subgraph "Feature Modules"
            direction TB
            ChannelModule["Channel Module"]:::module
            ChannelListModule["ChannelList Module"]:::module
            ChannelSettingsModule["ChannelSettings Module"]:::module
            MessageSearchModule["MessageSearch Module"]:::module
            OpenChannelModule["OpenChannel Module"]:::module
            GroupChannelModule["GroupChannel Module"]:::module
            ThreadModule["Thread Module"]:::module
        end
        UIComponents["UI Component Layer"]:::ui
        UtilsHooks["Hooks & Utils"]:::util
    end

    %% External SDK & Services
    SDK["Sendbird JS SDK & LameJS"]:::sdk
    ChatServer["Sendbird Chat Server"]:::server

    %% Runtime Flows
    UIKitLibrary -->|"initializes SDK"| SDK
    SDK -->|"WebSocket/REST"| ChatServer
    UIKitLibrary -->|"renders UI components"| UIComponents
    UIKitLibrary -->|"uses utils/hooks"| UtilsHooks

    %% Development Tools
    subgraph "Development & Build Tools"
        direction TB
        Vite["Vite Dev Server"]:::devtools
        Storybook["Storybook"]:::devtools
        Rollup["RollupJS Build"]:::devtools
        Plop["Plop.js Templates"]:::devtools
    end
    Vite -.->|"local import"| UIKitLibrary
    Storybook -.->|"visualize components"| UIKitLibrary
    Rollup -.->|"bundles for npm"| UIKitLibrary
    Plop -.->|"scaffold code"| UIKitLibrary

    %% CI/CD Pipelines
    subgraph "CI/CD Pipelines"
        direction TB
        CI["GitHub Actions / CircleCI"]:::cicd
        Tests["Jest & Playwright"]:::cicd
        Publish["npm Publish"]:::cicd
    end
    CI -.->|"runs lint, test, deploy"| UIKitLibrary
    CI -.->|"publishes"| Publish

    %% Click Events
    click SendBirdProvider "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/Sendbird/context/SendbirdProvider.tsx"
    click SendbirdContext "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/Sendbird/context/SendbirdContext.tsx"
    click PubSub "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/pubSub/index.ts"
    click ConnectionHandler "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/handlers/ConnectionHandler.ts"
    click GroupChannelHandler "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/handlers/GroupChannelHandler.ts"
    click OpenChannelHandler "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/handlers/OpenChannelHandler.ts"
    click SessionHandler "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/handlers/SessionHandler.ts"
    click UserEventHandler "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/lib/handlers/UserEventHandler.ts"
    click ChannelModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/Channel/index.tsx"
    click ChannelModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/Channel/context/ChannelProvider.tsx"
    click ChannelListModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/ChannelList/index.tsx"
    click ChannelListModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/ChannelList/context/ChannelListProvider.tsx"
    click ChannelSettingsModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/ChannelSettings/index.tsx"
    click ChannelSettingsModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/ChannelSettings/context/ChannelSettingsProvider.tsx"
    click MessageSearchModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/MessageSearch/index.tsx"
    click MessageSearchModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/MessageSearch/context/MessageSearchProvider.tsx"
    click OpenChannelModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/OpenChannel/index.tsx"
    click OpenChannelModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/OpenChannel/context/OpenChannelProvider.tsx"
    click GroupChannelModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/GroupChannel/index.tsx"
    click GroupChannelModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/GroupChannel/context/GroupChannelProvider.tsx"
    click ThreadModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/Thread/index.tsx"
    click ThreadModule "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/modules/Thread/context/ThreadProvider.tsx"
    click UIComponents "https://github.com/sendbird/sendbird-uikit-react/tree/main/src/ui"
    click UtilsHooks "https://github.com/sendbird/sendbird-uikit-react/tree/main/src/hooks"
    click UtilsHooks "https://github.com/sendbird/sendbird-uikit-react/blob/main/src/utils/index.ts"
    click Storybook "https://github.com/sendbird/sendbird-uikit-react/tree/main/src/stories"
    click Vite "https://github.com/sendbird/sendbird-uikit-react/tree/main/apps/testing/src"
    click Storybook "https://github.com/sendbird/sendbird-uikit-react/tree/main/apps/visual-test/src"
    click Rollup "https://github.com/sendbird/sendbird-uikit-react/blob/main/rollup.config.mjs"
    click Rollup "https://github.com/sendbird/sendbird-uikit-react/blob/main/rollup.module-exports.mjs"
    click Plop "https://github.com/sendbird/sendbird-uikit-react/tree/main/plop-templates/ui"
    click Plop "https://github.com/sendbird/sendbird-uikit-react/tree/main/plop-templates/reducer"

    %% Styles
    classDef consumer fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#afa,stroke:#2d2,stroke-width:1px
    classDef module fill:#cff,stroke:#06c,stroke-width:1px
    classDef ui fill:#fcf,stroke:#c0c,stroke-width:1px
    classDef util fill:#ffeb99,stroke:#d4af37,stroke-width:1px
    classDef sdk fill:#fdd,stroke:#d22,stroke-width:1px
    classDef server fill:#f88,stroke:#800,stroke-width:2px
    classDef devtools fill:#add8e6,stroke:#0000ff,stroke-width:1px,stroke-dasharray: 5 5
    classDef cicd fill:#d3d3d3,stroke:#555,stroke-width:1px,stroke-dasharray: 2 2
```
