# faridsafi/react-native-gifted-chat architecture

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

- Interactive diagram: https://gitdiagram.com/faridsafi/react-native-gifted-chat
- Repository: https://github.com/faridsafi/react-native-gifted-chat

## Overview

##### Project Type & Purpose
- This is an open-source React Native & Web UI component library (“react-native-gifted-chat”).
- Its sole purpose is to provide a comprehensive, customizable chat interface (message list, bubbles, composer, quick replies, typing indicator, etc.).
- It ships as a single NPM package with an example/demo Expo app under `example/`.

##### High-Level File Structure
– Root
- Config & metadata: `.eslintrc.cjs`, `babel.config.cjs`, `jest.config.cjs`, `tsconfig.json`, CI/workflow files, `README.md`, `LICENSE`
– src/
- Entry: `index.ts` exports `GiftedChat`, subcomponents & hooks
- Components folder-style:
– `GiftedChat/`, `MessageContainer/`, `Bubble/`, `Day/`, `TypingIndicator/`
– Leaf components: `Avatar.tsx`, `Composer.tsx`, `InputToolbar.tsx`, `Send.tsx`, `QuickReplies.tsx`, etc.
- Shared logic: `hooks/`, `utils.ts`, `logging.ts`, `styles.ts`, `types.ts`
- Tests under `src/__tests__`
– example/
- A full Expo demo app illustrating default & custom UIs
- Sub-examples: “example-expo”, “example-gifted-chat”, “example-slack-message”

##### Core Architectural Patterns
- React component composition – GiftedChat is a wrapper that orchestrates child components
- Context API (`GiftedChatContext`) to share theme, settings, layout info
- Hooks for lifecycle & layout (`useUpdateLayoutEffect`)
- FlatList for virtualization in `MessageContainer`
- Pure UI – no built-in backend; consumers wire up `onSend` to their chat server

##### Main System Components & Relationships

[Host App]
- Renders <GiftedChat …/>
- Passes in `messages[]`, `user` object, `onSend()` callback
- Optionally handles `onLoadEarlier`, `onQuickReply` to drive business logic / API calls

↓ data flow

[GiftedChat Module]
- Wraps:
– MessageContainer
– InputToolbar
– Footer / TypingIndicator
– QuickReplies (if enabled)
– Custom View slots (e.g. `renderBubble`, `renderFooter`)

- Manages layout via `onLayout` events & Context

↕ composition

┌─────────────────────────────────────────────────┐
│  MessageContainer (FlatList)                   │
│   ├─ Day / DayAnimated                         │
│   ├─ MessageItem → Bubble → (Text, Image, Video) │
│   └─ SystemMessage                             │
└─────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────┐
│  InputToolbar                                  │
│   ├─ Composer (TextInput)                      │
│   ├─ Actions (attach buttons)                  │
│   ├─ Send (button)                             │
│   └─ AccessoryBar (optional)                   │
└─────────────────────────────────────────────────┘

↕ context/hooks

[Shared Utils & Hooks]
- useUpdateLayoutEffect
- message ID generation (uuid)
- logging
- styles & constants

↓ external integration

[External Chat API / Server]
- e.g. GetStream.io, Firebase, custom WebSocket
- Host App’s `onSend` / `onLoadEarlier` calls out here
- New messages fed back into `messages[]` prop

- Host App → GiftedChat → (MessageContainer + InputToolbar + Footer) → External Chat API
- Detail all subcomponents, context providers, hooks, and utility modules
- Related components visually and call out extensibility slots

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Host App
    HostApp["Host App"]:::host
    click HostApp "https://github.com/faridsafi/react-native-gifted-chat/blob/master/example/App.tsx"

    %% Library UI Core
    subgraph "Library UI" 
        direction TB
        GiftedChat["GiftedChat\nModule"]:::lib
        click GiftedChat "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/GiftedChat/index.tsx"

        Context["GiftedChatContext"]:::util
        click Context "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/GiftedChatContext.ts"

        %% Message Container Subgraph
        subgraph "MessageContainer (FlatList)" 
            direction TB
            MC["MessageContainer"]:::lib
            click MC "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/index.tsx"
            DayAnim["DayAnimated"]:::lib
            click DayAnim "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/components/DayAnimated/index.tsx"
            Item["MessageItem"]:::lib
            click Item "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/components/Item/index.tsx"
        end

        %% Input Toolbar Subgraph
        subgraph "InputToolbar" 
            direction TB
            IT["InputToolbar"]:::lib
            click IT "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/InputToolbar.tsx"
            Comp["Composer"]:::lib
            click Comp "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Composer.tsx"
            Acts["Actions"]:::lib
            click Acts "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Actions.tsx"
            SendBtn["Send"]:::lib
            click SendBtn "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Send.tsx"
            Load["LoadEarlier"]:::lib
            click Load "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/LoadEarlier.tsx"
        end

        Quick["QuickReplies"]:::lib
        click Quick "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/QuickReplies.tsx"
        TI["TypingIndicator"]:::lib
        click TI "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/TypingIndicator/index.tsx"
    end

    %% Shared Utils & Hooks
    subgraph "Shared Utils & Hooks"
        direction TB
        Hook["useUpdateLayoutEffect"]:::util
        click Hook "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/hooks/useUpdateLayoutEffect.ts"
        Utils["utils"]:::util
        click Utils "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/utils.ts"
        Log["logging"]:::util
        click Log "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/logging.ts"
        StylesShared["styles"]:::util
        click StylesShared "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/styles.ts"
        TypesShared["types"]:::util
        click TypesShared "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/types.ts"
    end

    %% External Chat Service
    ChatService[(External Chat API)]:::ext

    %% Data Flow and Composition
    HostApp -->|"messages[], user, onSend"| GiftedChat
    GiftedChat -->|"composition"| MC
    GiftedChat -->|"composition"| IT
    GiftedChat -->|"composition"| Quick
    GiftedChat -->|"composition"| TI

    GiftedChat -.->|provides context| Context
    Context -.-> MC
    Context -.-> IT
    Context -.-> Quick
    Context -.-> TI

    MC --> DayAnim
    MC --> Item

    IT --> Comp
    IT --> Acts
    IT --> SendBtn
    IT --> Load

    GiftedChat -->|"onSend() → API"| ChatService
    HostApp -->|"onLoadEarlier() → API"| ChatService

    %% Utilities connections
    GiftedChat -.-> Hook
    MC -.-> Hook

    %% Styles & Types for Modules
    GiftedChat -.-> StylesGC["styles.ts"]:::util
    click StylesGC "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/GiftedChat/styles.ts"
    GiftedChat -.-> TypesGC["types.ts"]:::util
    click TypesGC "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/GiftedChat/types.ts"

    MC -.-> StylesMC["styles.ts"]:::util
    click StylesMC "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/styles.ts"
    MC -.-> TypesMC["types.ts"]:::util
    click TypesMC "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/types.ts"

    TI -.-> TIStyles["styles.ts"]:::util
    click TIStyles "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/TypingIndicator/styles.ts"
    TI -.-> TITypes["types.ts"]:::util
    click TITypes "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/TypingIndicator/types.ts"

    DayAnim -.-> DAStyles["styles.ts"]:::util
    click DAStyles "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/components/DayAnimated/styles.ts"
    DayAnim -.-> DATypes["types.ts"]:::util
    click DATypes "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/components/DayAnimated/types.ts"

    Item -.-> ItemTypes["types.ts"]:::util
    click ItemTypes "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageContainer/components/Item/types.ts"

    BubbleComp["Bubble"]:::lib
    click BubbleComp "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Bubble/index.tsx"
    BubbleComp -.-> BubbleStyles["styles.ts"]:::util
    click BubbleStyles "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Bubble/styles.ts"
    BubbleComp -.-> BubbleTypes["types.ts"]:::util
    click BubbleTypes "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Bubble/types.ts"

    DayComp["Day"]:::lib
    click DayComp "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Day/index.tsx"
    DayComp -.-> DayStyles["styles.ts"]:::util
    click DayStyles "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Day/styles.ts"
    DayComp -.-> DayTypes["types.ts"]:::util
    click DayTypes "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Day/types.ts"

    Avatar["Avatar"]:::lib
    click Avatar "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Avatar.tsx"
    GAvatar["GiftedAvatar"]:::lib
    click GAvatar "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/GiftedAvatar.tsx"

    SysMsg["SystemMessage"]:::lib
    click SysMsg "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/SystemMessage.tsx"
    MsgText["MessageText"]:::lib
    click MsgText "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageText.tsx"
    MsgImage["MessageImage"]:::lib
    click MsgImage "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageImage.tsx"
    MsgVideo["MessageVideo"]:::lib
    click MsgVideo "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageVideo.tsx"
    MsgAudio["MessageAudio"]:::lib
    click MsgAudio "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/MessageAudio.tsx"
    TimeStamp["Time"]:::lib
    click TimeStamp "https://github.com/faridsafi/react-native-gifted-chat/blob/master/src/Time.tsx"

    %% Class Definitions
    classDef host fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef lib fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef util fill:#f0f0f0,stroke:#333,stroke-width:1px;
    classDef ext fill:#ffe5cc,stroke:#333,stroke-width:1px;
```
