# braze-inc/braze-react-native-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/braze-inc/braze-react-native-sdk
- Repository: https://github.com/braze-inc/braze-react-native-sdk

## Overview

##### Main Components
- JavaScript (React Native) Layer:
– Components and modules in the “src” directory (e.g., src/braze.js, src/helpers.js, models, and UI components) form the core of the JavaScript SDK interface.
– The “index.js” and “index.d.ts” are entry points and expose the public API of the SDK.
- Native Bridge Modules:
– iOS Side: Look at “ios”, “BrazeProject/ios”, and the separate “iOS/BrazeReactBridge” directory. They contain Objective-C/Swift files, Podfiles, and project configurations indicating how the bridge is implemented to interact with the native Braze iOS SDK.
– Android Side: Explore “android” and “BrazeProject/android” directories, including both “newarch” and “oldarch” folders. These include Kotlin/Java source files that implement the React Native bridge for Android.
- Sample App / Integration Projects:
– The “BrazeProject” folder contains a sample application demonstrating integration of the React Native SDK with native modules (via manual linking and Cocoapods for iOS).
- Configuration and Build Tools:
– Files like package.json, tsconfig.json, babel.config.js, and build.gradle scripts indicate the tooling and build process.
– The use of ESLint, Prettier, and Jest (with __tests__ directories) shows the inclusion of coding standards and testing infrastructure.
- External SDK Dependencies:
– Documentation in the README points to integration with the native Braze SDKs for Android and iOS, indicating that the bridge ultimately connects to these native libraries for marketing automation functionalities.

##### Relationships and Interactions
- Data/Control Flow between Layers:
– In the iOS part, show communication from React Native to the iOS Bridging components (AppDelegate, BrazeReactDelegate, etc.) and further to the underlying Braze iOS SDK.
– Similarly, on Android, represent the call flow from React Native through ReactBridge implementations in both “newarch” and “oldarch” folders towards the Braze native SDK components.
- Integration in Sample App:
– In the BrazeProject sample directory, denote its role as a consumer of the SDK; it integrates the JavaScript SDK with native linking (for both manual and Pod-managed integration on iOS).
- Testing and Utility Components:
– Indicate that test files (found in __tests__ directories) are used to validate both the JavaScript layer and possibly interactions with the native code.

##### Architectural Patterns and Design Principles
- React Native Bridge Pattern:
– Clearly represent the separation between the JavaScript layer and Native Modules.
- Modular Design:
– Show how the SDK is modular (different directories for src, bridge implementations, and sample integration) to allow extensibility and easier maintenance.
- Configuration-centric Approach:
– Include visual elements for build scripts and configuration management (Gradle for Android, Podfile for iOS, npm scripts for the JS side).

##### Elements
- Clear Labels for Each Component:
– “JS SDK” (with subcomponents like “src/braze.js”, “models”, “UI components”)
– “React Native Bridge – iOS” (with subcomponents like “Podfile”, “AppDelegate”, “BrazeReactDelegate”)
– “React Native Bridge – Android” (with subcomponents from “newarch” and “oldarch” folders)
– “Sample App (BrazeProject)”
– “Build & Config Tools” (e.g., Gradle, npm, Babel)
– “Testing Infrastructure” (Jest based test suites)
▪ Native iOS modules (e.g., green)
▪ Native Android modules (e.g., orange)
- Integration With External Services (Optional):

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Infrastructure Subgraphs
    subgraph "Infrastructure"
        subgraph "Build & Config Tools"
            bc1("package.json"):::config
            bc2("tsconfig.json"):::config
            bc3("babel.config.js"):::config
            pod("Podfile"):::config
            gradleApp("build.gradle (BrazeProject/android/app)"):::config
            gradle("build.gradle (android)"):::config
        end
        subgraph "Testing Infrastructure"
            test1("__tests__ (root)"):::test
            test2("__tests__ (BrazeProject)"):::test
        end
    end

    %% Application Layers Subgraph
    subgraph "Application Layers"
        sa("Sample App (BrazeProject)"):::sample
        js("JS SDK (src)"):::js

        subgraph "Native Bridges"
            subgraph "React Native Bridge - iOS"
                iosA("BrazeReactBridge"):::ios
                iosB("Braze Integration (Project)"):::ios
            end
            subgraph "React Native Bridge - Android"
                andMain("React Native Bridge (Main)"):::android
                andNew("React Native Bridge NewArch"):::android
                andOld("React Native Bridge OldArch"):::android
            end
        end

        bs("Braze Native SDK Services"):::external
    end

    %% Relationships
    sa -->|"uses"| js
    js -->|"calls"| iosA
    js -->|"calls"| andMain
    js -->|"calls"| andNew
    js -->|"calls"| andOld
    iosA -->|"includes"| iosB
    iosA -->|"bridges"| bs
    andMain -->|"bridges"| bs
    andNew -->|"bridges"| bs
    andOld -->|"bridges"| bs

    %% Click Events for Application Layers
    click js "https://github.com/braze-inc/braze-react-native-sdk/tree/master/src/"
    click iosA "https://github.com/braze-inc/braze-react-native-sdk/tree/master/iOS/BrazeReactBridge/"
    click iosB "https://github.com/braze-inc/braze-react-native-sdk/tree/master/BrazeProject/ios/"
    click andMain "https://github.com/braze-inc/braze-react-native-sdk/tree/master/android/src/main/java/com/braze/reactbridge/"
    click andNew "https://github.com/braze-inc/braze-react-native-sdk/tree/master/android/src/newarch/com/braze/reactbridge/"
    click andOld "https://github.com/braze-inc/braze-react-native-sdk/tree/master/android/src/oldarch/com/braze/reactbridge/"
    click sa "https://github.com/braze-inc/braze-react-native-sdk/tree/master/BrazeProject/"

    %% Click Events for Build & Config Tools
    click bc1 "https://github.com/braze-inc/braze-react-native-sdk/blob/master/package.json"
    click bc2 "https://github.com/braze-inc/braze-react-native-sdk/blob/master/tsconfig.json"
    click bc3 "https://github.com/braze-inc/braze-react-native-sdk/blob/master/babel.config.js"
    click pod "https://github.com/braze-inc/braze-react-native-sdk/tree/master/BrazeProject/ios/Podfile"
    click gradleApp "https://github.com/braze-inc/braze-react-native-sdk/blob/master/BrazeProject/android/app/build.gradle"
    click gradle "https://github.com/braze-inc/braze-react-native-sdk/blob/master/android/build.gradle"

    %% Click Events for Testing Infrastructure
    click test1 "https://github.com/braze-inc/braze-react-native-sdk/tree/master/__tests__/"
    click test2 "https://github.com/braze-inc/braze-react-native-sdk/tree/master/BrazeProject/__tests__/"

    %% Class Definitions for Colours
    classDef js fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef ios fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef android fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef sample fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef test fill:#e0e0e0,stroke:#000,stroke-width:2px;
    classDef external fill:#ffb6c1,stroke:#000,stroke-width:2px;
```
