# rocketchat/rocket.chat.reactnative architecture

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

- Interactive diagram: https://gitdiagram.com/rocketchat/rocket.chat.reactnative
- Repository: https://github.com/rocketchat/rocket.chat.reactnative

## Overview

##### And separate the major layers/components

a. User Interface (Presentation) Layer
- This includes the React Native components (found under the “app” directory in subfolders such as containers, views, and components), Storybook configuration for showcasing UI components (.storybook), i18n localization files (app/i18n), and theming.

b. Business Logic / State Management Layer
- The project makes extensive use of Redux (reducers, actions inside “app/actions” and “app/reducers”), sagas (under “app/sagas”), and also makes use of custom hooks (in app/lib/hooks).
- Centralized state store, asynchronous operations and event handling as “State Management & Business Logic.”

c. Services & Data Handling / API Communication
- Under app/lib and app/methods, you have API services, methods for sending messages, encryption utilities, database models/services and schemes.
- Components like “REST API & SDK,” “Encryption Module,” and “Database & Local Storage” (covering the models, schemas, and migrations).

d. Native Integrations
- The separate directories “android” and “ios” show that there are platform-specific codes and native integrations.
- Native modules, third‑party integrations (Crashlytics, Fabric, SSL pinning modules, etc.), and fastlane configurations.
- Components as “Android Native Code” and “iOS Native Code” with links to the React Native bridge if needed.

e. Testing & Quality Assurance
- The __mocks__ directory, e2e tests, CircleCI workflows (.circleci and .github/workflows) and jest configurations form the testing and CI/CD layer.
- This part as “Testing (Unit, E2E) & CI/CD.”

##### Connections and data flow

- That the business logic (reducers/sagas) call methods in the services layer to perform API calls, encryption, or file operations.
- That the services layer communicates with external Rocket.Chat servers (for message and user data) and the native layers when additional system-level functionality is needed.
- That testing suites and CI/CD pipelines are set up to validate changes across UI, business logic, and service layers.

##### Architectural Patterns & Frameworks

- Use of the Flux/Redux pattern across actions, reducers, and sagas.
- Modular organization of “containers” versus “components” which indicates separation of presentation and business logic.
- Areas where dependency injection and abstraction are applied (e.g., in lib/services and lib/methods), and how native modules integrate (bridging functionality between JavaScript and native code).

##### Technologies and Frameworks

- React Native as the main UI framework with storybook for demos.
- Redux for state management, with sagas handling asynchronous flows.
- Custom hooks (in lib/hooks) to encapsulate behaviors.
- Encryption tools and database interfaces for offline and local storage features.
- Native mobile modules written in Kotlin/Java (android) and Swift/Objective-C (ios).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% User Interface (Presentation) Layer
    subgraph "User Interface (Presentation) Layer"
        UI_Containers["UI Containers"]:::ui
        UI_Views["UI Views"]:::ui
        UI_Components["UI Components"]:::ui
        UI_i18n["i18n Localization"]:::ui
    end

    %% Business Logic & State Management Layer
    subgraph "State Management & Business Logic"
        RL_Actions["Redux Actions"]:::logic
        RL_Reducers["Redux Reducers"]:::logic
        RL_Sagas["Redux Sagas"]:::logic
        RL_Hooks["Custom Hooks"]:::logic
    end

    %% Services & Data Handling / API Communication
    subgraph "Services & Data Handling"
        S_API["API Services"]:::services
        S_Methods["Message & File Methods"]:::services
        S_Encryption["Encryption Module"]:::services
        S_Database["Database & Local Storage"]:::services
    end

    %% Native Integrations
    subgraph "Native Integrations"
        N_Android["Android Native Code"]:::native
        N_iOS["iOS Native Code"]:::native
    end

    %% External Integration
    EX_Server["Rocket.Chat Server"]:::external

    %% Testing & CI/CD
    subgraph "Testing & CI/CD"
        T_Mocks["Mocks"]:::testing
        T_CircleCI["CircleCI Configurations"]:::testing
        T_Github["Github Workflows"]:::testing
        T_E2E["E2E Tests"]:::testing
    end

    %% Connections from UI Layer to Business Logic
    UI_Containers -->|"triggers"| RL_Actions
    UI_Views -->|"triggers"| RL_Actions
    UI_Components -->|"triggers"| RL_Actions
    UI_i18n -->|"localizes"| RL_Actions

    %% Business Logic connections
    RL_Actions -->|"initiates"| RL_Sagas
    RL_Actions -->|"updates"| RL_Reducers
    RL_Sagas -->|"calls_API"| S_API
    RL_Sagas -->|"performs_ops"| S_Methods
    RL_Sagas -->|"encrypts"| S_Encryption
    RL_Sagas -->|"stores_data"| S_Database
    %% Custom hooks support the business logic (dotted line to indicate support)
    RL_Hooks ---|"supports"| RL_Actions

    %% Services Layer calls to External Server & Native Integrations
    S_API -->|"REST_call"| EX_Server
    S_Methods -->|"bridges_to"| N_Android
    S_Methods -->|"bridges_to"| N_iOS

    %% Testing & CI/CD applies to all layers (dashed connections)
    UI_Containers ---|"tested_by"| T_Mocks
    UI_Views ---|"tested_by"| T_Mocks
    RL_Actions ---|"CI_CD"| T_CircleCI
    RL_Sagas ---|"CI_CD"| T_Github
    S_API ---|"CI_CD"| T_E2E

    %% Click Events for UI Layer
    click UI_Containers "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/containers"
    click UI_Views "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/views"
    click UI_Components "https://github.com/rocketchat/rocket.chat.reactnative/blob/develop/.storybook"
    click UI_i18n "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/i18n"

    %% Click Events for Business Logic & State Management Layer
    click RL_Actions "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/actions"
    click RL_Reducers "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/reducers"
    click RL_Sagas "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/sagas"
    click RL_Hooks "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/lib/hooks"

    %% Click Events for Services & Data Handling
    click S_API "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/lib/services"
    click S_Methods "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/lib/methods"
    click S_Encryption "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/lib/encryption"
    click S_Database "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/app/lib/database"

    %% Click Events for Native Integrations
    click N_Android "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/android"
    click N_iOS "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/ios"

    %% Click Events for Testing & CI/CD
    click T_Mocks "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/__mocks__"
    click T_CircleCI "https://github.com/rocketchat/rocket.chat.reactnative/blob/develop/.circleci"
    click T_Github "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/.github/workflows"
    click T_E2E "https://github.com/rocketchat/rocket.chat.reactnative/tree/develop/e2e"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef logic fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef services fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef native fill:#9370DB,stroke:#000,stroke-width:1px;
    classDef testing fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
