# datadog/dd-sdk-reactnative architecture

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

- Interactive diagram: https://gitdiagram.com/datadog/dd-sdk-reactnative
- Repository: https://github.com/datadog/dd-sdk-reactnative

## Overview

##### Project Type and Purpose
- This is a monorepo for an open-source React Native SDK maintained by Datadog.
- It contains multiple platform-specific and JS/TS packages (core monitoring, codepush, Apollo Client integration, navigation instrumentation, session replay, WebView instrumentation, internal testing tools).
- It uses Yarn Plug’n’Play (v3+), Lerna for package orchestration, and includes example apps demonstrating usage.

##### File Structure Analysis
- Top-level:
– package.json, lerna.json, .yarnrc.yml, Yarn Plug’n’Play files, Makefile, CI configs (.github/workflows, .gitlab-ci.yml).
– docs/, CONTRIBUTING.md, LICENSE, troubleshooting, version-update scripts.
– example-apps: example/ and example-new-architecture/ showing React Native apps consuming the SDK.
- packages/: each subfolder is an independently versioned package with:
– a JS/TS layer (src/, __tests__),
– native Android code (android/src/newarch & oldarch),
– native iOS code (ios/Sources & Tests),
– package.json, CI/test configs.
- Build & release: custom Gradle scripts, CocoaPods podspecs, Babel configs, TypeScript configs for each package.

##### Core Components
a. Monorepo Orchestrator
– Yarn v3 Plug’n’Play & Lerna
– CI/CD pipelines (GitHub Actions, GitLab CI)
1. core
2. codepush
3. internal-testing-tools
4. react-native-apollo-client
5. react-native-navigation
6. react-native-session-replay
7. react-native-webview
8. react-navigation
c. Example Applications
– example (classic RN app)
– example-new-architecture (TurboModules / New Architecture RN app)
d. Native Layers within each package
– Android (Kotlin modules: newarch vs oldarch)
– iOS (Swift/Obj-C sources, Podspecs)
e. JS/TS Bridge Layer
– React Native NativeModules proxies in TypeScript
– Instrumentation (DD-Rum, DD-Logs, DD-Trace event mappers)

##### Interactions & Data Flows
- Developer invokes Yarn/Lerna → installs all packages → links native modules into RN project.
- Example apps import NPM modules → JS/TS layer calls NativeModules → bridges into Android/iOS SDK wrappers → forwards data to Datadog backend.
- CI job: runs tests per package (jest, unit tests for Android & iOS) → builds artifacts → publishes to npm/CocoaPods/Maven.

##### Architectural Patterns & Principles
- Monorepo modularity: each concern is isolated as a package.
- Layered architecture per package:
– Presentation/JS layer (TypeScript)
– Bridge layer (React Native NativeModules)
– Native SDK wrapper layer (Kotlin / Swift + instrumentation)
- Platform abstraction: newarch vs oldarch modules for Android, versioned code for multiple RN versions.
- Strong test coverage: unit tests in JS, Android, iOS.

##### Essential Elements to Capture
- Monorepo root & tooling (Yarn Plug’n’Play, Lerna, CI).
- Core package and integration packages with both JS and native sub-layers.
- Example apps as consumers.
- Bridge interaction path: JS → NativeModules → Android/iOS wrappers.
- Testing pipelines attached to each module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Monorepo Orchestrator
    subgraph "Monorepo Orchestrator"
        direction TB
        OrchestratorTools["Yarn Plug’n’Play & Lerna"]:::orchestrator
        CI["CI/CD Pipelines"]:::orchestrator
        OrchestratorTools -->|"orchestrate packages"| CI
    end

    %% CI click events
    click OrchestratorTools "https://github.com/datadog/dd-sdk-reactnative/blob/develop//.yarnrc.yml"
    click OrchestratorTools "https://github.com/datadog/dd-sdk-reactnative/tree/develop//.yarn/"
    click OrchestratorTools "https://github.com/datadog/dd-sdk-reactnative/blob/develop//lerna.json"
    click CI "https://github.com/datadog/dd-sdk-reactnative/tree/develop//.github/workflows/"
    click CI "https://github.com/datadog/dd-sdk-reactnative/blob/develop//.gitlab-ci.yml"
    click OrchestratorTools "https://github.com/datadog/dd-sdk-reactnative/blob/develop//package.json"

    %% Packages Core
    subgraph "Core Package" 
        direction TB
        CoreJS["JS/TS Layer"]:::js
        CoreBridge["Bridge Layer"]:::bridge
        CoreAndroid["Android Native"]:::android
        CoreiOS["iOS Native"]:::ios
        CoreJS -->|"NativeModules.invoke"| CoreBridge
        CoreBridge --> CoreAndroid
        CoreBridge --> CoreiOS
    end
    click CoreJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/core/src/"
    click CoreAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/core/android/src/oldarch/"
    click CoreAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/core/android/src/newarch/"
    click CoreiOS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/core/ios/Sources/"
    click CoreiOS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/core/DatadogSDKReactNative.podspec"

    %% CodePush
    subgraph "CodePush Integration"
        direction TB
        CPJS["JS/TS Layer"]:::js
        CPBridge["Bridge Layer"]:::bridge
        CPJS --> CPBridge
    end
    click CPJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/codepush/src/"
    click CPJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/codepush/src/__tests__/"
    click CPJS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/codepush/package.json"

    %% Internal Testing Tools
    subgraph "Internal Testing Tools"
        direction TB
        ITJS["JS/TS Layer"]:::js
        ITBridge["Bridge Layer"]:::bridge
        ITAndroid["Android Native"]:::android
        ITiOS["iOS Native"]:::ios
        ITJS --> ITBridge
        ITBridge --> ITAndroid
        ITBridge --> ITiOS
    end
    click ITJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/internal-testing-tools/src/"
    click ITAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/internal-testing-tools/android/src/oldarch/"
    click ITAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/internal-testing-tools/android/src/newarch/"
    click ITiOS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/internal-testing-tools/ios/Sources/"
    click ITiOS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/internal-testing-tools/DatadogInternalTesting.podspec"

    %% Integrations Swimlane
    subgraph "Integrations"
        direction TB
        subgraph "Apollo Client"
            RNACJS["JS/TS Layer"]:::js
            RNACBridge["Bridge Layer"]:::bridge
            RNACJS --> RNACBridge
        end
        subgraph "React-Native Navigation"
            RNNavJS["JS/TS Layer"]:::js
            RNNavBridge["Bridge Layer"]:::bridge
            RNNavJS --> RNNavBridge
        end
        subgraph "React Navigation"
            RNavJS["JS/TS Layer"]:::js
            RNavBridge["Bridge Layer"]:::bridge
            RNavJS --> RNavBridge
        end
        subgraph "Session Replay"
            SRJS["JS/TS Layer"]:::js
            SRBridge["Bridge Layer"]:::bridge
            SRAndroid["Android Native"]:::android
            SRiOS["iOS Native"]:::ios
            SRJS --> SRBridge
            SRBridge --> SRAndroid
            SRBridge --> SRiOS
        end
        subgraph "WebView"
            WVJS["JS/TS Layer"]:::js
            WVBridge["Bridge Layer"]:::bridge
            WVAndroid["Android Native"]:::android
            WViOS["iOS Native"]:::ios
            WVJS --> WVBridge
            WVBridge --> WVAndroid
            WVBridge --> WViOS
        end
    end
    click RNACJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-apollo-client/src/"
    click RNACJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-apollo-client/src/__tests__/"
    click RNACJS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/react-native-apollo-client/package.json"
    click RNNavJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-navigation/src/"
    click RNNavJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-navigation/src/__tests__/"
    click RNNavJS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/react-native-navigation/package.json"
    click RNavJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-navigation/src/"
    click RNavJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-navigation/src/__tests__/"
    click RNavJS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/react-navigation/package.json"
    click SRJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-session-replay/src/"
    click SRAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-session-replay/android/src/oldarch/"
    click SRAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-session-replay/android/src/newarch/"
    click SRiOS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-session-replay/ios/Sources/"
    click SRiOS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/react-native-session-replay/DatadogSDKReactNativeSessionReplay.podspec"
    click WVJS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-webview/src/"
    click WVAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-webview/android/src/oldarch/"
    click WVAndroid "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-webview/android/src/newarch/"
    click WViOS "https://github.com/datadog/dd-sdk-reactnative/tree/develop//packages/react-native-webview/ios/Sources/"
    click WViOS "https://github.com/datadog/dd-sdk-reactnative/blob/develop//packages/react-native-webview/DatadogSDKReactNativeWebView.podspec"

    %% Example Apps
    subgraph "Example Applications"
        direction TB
        ClassicApp["Classic RN App"]:::example
        NewArchApp["New Architecture RN App"]:::example
    end
    click ClassicApp "https://github.com/datadog/dd-sdk-reactnative/tree/develop//example/"
    click NewArchApp "https://github.com/datadog/dd-sdk-reactnative/tree/develop//example-new-architecture/"

    %% Flows
    OrchestratorTools -->|"yarn install"| CoreJS
    OrchestratorTools -->|"yarn install"| CPJS
    OrchestratorTools -->|"yarn install"| ITJS
    OrchestratorTools -->|"yarn install"| RNACJS
    OrchestratorTools -->|"yarn install"| RNNavJS
    OrchestratorTools -->|"yarn install"| RNavJS
    OrchestratorTools -->|"yarn install"| SRJS
    OrchestratorTools -->|"yarn install"| WVJS

    CoreBridge -->|"npm link"| ClassicApp
    CPBridge -->|"npm link"| ClassicApp
    ITBridge -->|"npm link"| ClassicApp
    RNACBridge -->|"npm link"| ClassicApp
    RNNavBridge -->|"npm link"| ClassicApp
    RNavBridge -->|"npm link"| ClassicApp
    SRBridge -->|"npm link"| ClassicApp
    WVBridge -->|"npm link"| ClassicApp

    CoreBridge -->|"npm link"| NewArchApp
    CPBridge --> NewArchApp
    ITBridge --> NewArchApp
    RNACBridge --> NewArchApp
    RNNavBridge --> NewArchApp
    RNavBridge --> NewArchApp
    SRBridge --> NewArchApp
    WVBridge --> NewArchApp

    ClassicApp -->|"HTTP ingest"| Datadog["Datadog Backend"]:::external
    NewArchApp -->|"HTTP ingest"| Datadog

    CI -->|"test & build"| CoreJS
    CI --> CPJS
    CI --> ITJS
    CI --> RNACJS
    CI --> RNNavJS
    CI --> RNavJS
    CI --> SRJS
    CI --> WVJS

    %% Legend and Styles
    classDef orchestrator fill:#cccccc,stroke:#666,stroke-width:1px;
    classDef js fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef bridge fill:#87cefa,stroke:#000,stroke-width:1px;
    classDef android fill:#98fb98,stroke:#000,stroke-width:1px;
    classDef ios fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef example fill:#ffff99,stroke:#000,stroke-width:1px;
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px;
```
