# datatype123/sendbird_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/datatype123/sendbird_chatbot
- Repository: https://github.com/datatype123/sendbird_chatbot

## Overview

##### Main Components
- Frontend (Mobile App): Located in the project’s root (e.g., App.tsx, index.ts) along with UI-related directories (“components” and “ui”). These hold the screens for login/signup, chat interface, channel management, and user profiles.
- Native Android Layer: Shown by the “android” directory that contains the native Android project files (build.gradle, AndroidManifest.xml, Kotlin files for MainActivity and MainApplication). This represents the platform-specific integration layer for Android builds.
- State Management: The “redux” directory illustrates that the application uses Redux for managing global state (e.g., user authentication state, chat conversations).
- API/Services Layer: The “services” directory contains various modules (apiAccount.js, apiLogin.js, etc.) that manage interactions with the BotPress API and other backend services.
- Database Integration: Although not heavily detailed in the file tree, the “database” folder (with insertDB.js) and the README mention “Realm” which is used as the mobile database.
- Configuration & Setup: Files like config.tsx, babel.config.js, tsconfig.json, and app.json are crucial to the app’s configuration. Additionally, external configuration for BotPress integration is echoed within the README.

##### Relationships and Interactions Between Components
- Data from API responses then flows back and updates the Redux store, which in turn updates the UI’s presentation.
- The mobile database (Realm) interacts with the app to store local data persistently (e.g., offline chat data). Show a bi-directional link between local storage (database) and the frontend logic.
- The native Android layer interacts with the React Native app (via the Java/Kotlin bridge) to handle platform-specific functions.

##### Architectural Patterns and Design Principles
- Separation of Concerns: UI (presentation), state management (Redux), and service/API calls are organized into different directories.
- Modular Design: The project is segregated into clear functional modules—authentication, chat interface, channel management, and user profile updates.
- Client-Service Integration: The API services layer clearly abstracts the external BotPress APIs and handles backend integration, promoting loose coupling between the frontend and backend services.
- Platform-Specific Abstraction: The “android” directory provides a native wrapper for handling low-level Android functionalities alongside React Native.

##### Relevant Technologies
- Frontend Framework: React Native.
- Chatbot Service: BotPress and BotPress AI.
- State Management: Redux (via “redux” folder).
- Mobile Database: Realm as mentioned in the README.
- Platform: Android (with native code in Kotlin) along with cross-platform setup via React Native.
- Supporting Configuration: Babel, TypeScript, and typical configuration files (tsconfig.json, app.json, etc.).

##### Elements
- Squares for UI screens.
- Circles/ovals for modules like APIs and services.

- Top tier: User interactions with various screens.
- Middle tier: Redux state management and API services.
- Bottom tier: External backend systems (BotPress, AI modules, etc.) and local database.
- Expand with secondary layers to detail the native Android integration and configuration files if necessary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actor
    U("User"):::actor

    %% React Native Frontend Subgraph
    subgraph "React Native Frontend"
        A("App.tsx"):::frontend
        I("index.ts"):::frontend
        C("Components"):::frontend
        UI("UI"):::frontend
    end

    %% State Management
    R("Redux Store"):::redux

    %% API Services Subgraph
    subgraph "API Services"
        A1("apiAccount.js"):::api
        A2("apiConversations.js"):::api
        A3("apiGetMessage.js"):::api
        A4("apiLogin.js"):::api
        A5("apiSendMessage.js"):::api
        A6("apiService.js"):::api
        A7("apiSignup.js"):::api
    end

    %% External BotPress API
    BP("BotPress API"):::external

    %% Native Android Layer
    NA("Native Android Layer"):::native

    %% Local Database
    DB("Realm Mobile Database"):::db

    %% Configuration & Setup Subgraph
    subgraph "Configuration & Setup"
        Conf("config.tsx"):::config
        Babel("babel.config.js"):::config
        Ts("tsconfig.json"):::config
        AppJson("app.json"):::config
    end

    %% Connections
    U -->|"starts"| A
    %% Frontend interactions
    A -->|"initializes"| I
    I -->|"renders"| C
    C -->|"builds"| UI
    UI -->|"dispatches"| R
    R -->|"updates"| UI

    %% API flow from UI
    UI -->|"API_Call"| A4
    A4 -->|"forward"| A6
    A6 -->|"calls"| BP
    BP -->|"response"| A6
    A6 -->|"updates"| R

    %% Native Android integration
    UI ---|"NativeBridge"| NA

    %% Local Database synchronization
    UI <==>|"DataSync"| DB

    %% Configuration influencing Frontend
    Conf ---|"configures"| A
    Babel ---|"configures"| A
    Ts ---|"configures"| A
    AppJson ---|"configures"| A

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef redux fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef api fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef native fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef db fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef config fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef actor fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef external fill:#FFFFFF,stroke:#000,stroke-dasharray: 5,5;

    %% Click Events for Frontend
    click A "https://github.com/datatype123/sendbird_chatbot/blob/main/App.tsx"
    click I "https://github.com/datatype123/sendbird_chatbot/blob/main/index.ts"
    click C "https://github.com/datatype123/sendbird_chatbot/tree/main/components/"
    click UI "https://github.com/datatype123/sendbird_chatbot/tree/main/ui/"

    %% Click Event for Redux
    click R "https://github.com/datatype123/sendbird_chatbot/tree/main/redux/"

    %% Click Events for API Services
    click A1 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiAccount.js"
    click A2 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiConversations.js"
    click A3 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiGetMessage.js"
    click A4 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiLogin.js"
    click A5 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiSendMessage.js"
    click A6 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiService.js"
    click A7 "https://github.com/datatype123/sendbird_chatbot/blob/main/services/apiSignup.js"

    %% Click Event for Native Android Layer
    click NA "https://github.com/datatype123/sendbird_chatbot/tree/main/android/"

    %% Click Event for Local Database
    click DB "https://github.com/datatype123/sendbird_chatbot/blob/main/database/insertDB.js"

    %% Click Events for Configuration & Setup
    click Conf "https://github.com/datatype123/sendbird_chatbot/blob/main/config.tsx"
    click Babel "https://github.com/datatype123/sendbird_chatbot/blob/main/babel.config.js"
    click Ts "https://github.com/datatype123/sendbird_chatbot/blob/main/tsconfig.json"
    click AppJson "https://github.com/datatype123/sendbird_chatbot/blob/main/app.json"
```
