# adaptyteam/adaptysdk-react-native architecture

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

- Interactive diagram: https://gitdiagram.com/adaptyteam/adaptysdk-react-native
- Repository: https://github.com/adaptyteam/adaptysdk-react-native

## Overview

##### Project Type and Purpose
- This is an **open-source React Native SDK** (“react-native-adapty”) for in-app purchase and subscription management.
- It provides a **JavaScript/TypeScript API**, **native bridges** (Android & iOS), **UI components** for paywalls, and integrates with the **Adapty backend** to handle A/B testing, analytics, and purchase events without server coding.

##### File-Structure Analysis
- **Root**: config files (`.eslintrc.js`, `babel.config.js`, TypeScript configs, CI scripts).
- **src/**: core TS library
- `index.ts` exports public API
- `bridge.ts` → RN bridge to native modules (NativeModules/TurboModules)
- `coders/` → Data-Mapper layer (maps raw JSON ↔ TS models)
- `native-request-handler/` → unified request dispatcher for platform calls
- `ui/` → JS wrapper for native UI (OnboardingView), view controller & emitter
- `logger/` → structured logging context & scopes
- `types/` → shared type definitions
- **android/**: Android native module code
- `AdaptyReactModule.kt`, `AdaptyOnboardingViewManager.kt`
- Gradle build scripts & manifest
- **ios/**: iOS native module code
- Obj-C/Swift bridge files (`RNAdapty.m`, `AdaptyOnboardingWrapperView.swift`, bridging header)
- Xcode project & Podspec
- **scripts/**: packaging, version bumping, linking, cleaning
- **examples/**: two sample apps (bare RN + Expo) showcasing integration

##### README Insights
- Highlights **compatibility** with RN New Architecture (TurboModules) & legacy bridge
- Emphasizes **no-server** integration, real-time analytics, UI paywalls, A/B tests
- Points to **examples/** for usage reference

a. Main Components
- **App Code (Consumer)**: Your React Native app imports `react-native-adapty`.
- **JS/TS Layer**:
– *Public API* (`src/index.ts`)
– *Data Mapper* (`src/coders`)
– *Bridge* (`src/bridge.ts`)
– *Logger* (`src/logger`)
- **Native Modules**:
– Android (`android/src/.../AdaptyReactModule.kt`, view manager)
– iOS (`ios/RNAdapty.*`, `AdaptyOnboardingWrapperView.*`)
- **Native Adapty SDK**: platform SDKs for purchase handling & networking
- **Adapty Backend**: REST/WebSocket endpoints for paywalls, analytics, user profiles
- **UI Component**:
– *JS Wrapper* (`src/ui/AdaptyOnboardingView.tsx`)
– *Native View Managers* (Android/iOS)
- **Build & Release**: TS compiler, Podspec (iOS), Gradle & Maven (Android), npm packaging

b. Relationships & Interactions
1. **App Code** calls → **JS/TS Public API**
2. Public API delegates → **Bridge**
3. Bridge invokes → **Native Module** (via NativeModules or TurboModule)
4. Native Module interacts → **Native Adapty SDK** for purchases, paywall configs, analytics
5. Native SDK communicates → **Adapty Backend** over HTTPS/WebSockets
6. Responses flow back → native → bridge → JS → coders convert → API returns to app
7. **UI Events** (purchase button tapped) propagate from **Native View** → emitter → JS handler

c. Architectural Patterns & Principles
- **Layered Architecture**: clear separation between JS logic, bridge, native code, and external services
- **Bridge Pattern**: cross‐language communication (JS ↔ Native)
- **Data Mapper**: `coders/` modules translate raw JSON to rich TS models
- **Publisher/Subscriber**: UI emitter & logger scopes for events and diagnostics
- **Modularization**: separate folders for coders, UI, types, and native‐request handling

d. Key Technologies & Frameworks
- React Native (legacy bridge & TurboModules)
- Kotlin/Java for Android module
- Swift/Objective-C for iOS module
- TypeScript for core library
- Gradle, CocoaPods, npm for build & distribution
- Jest for tests (`jest.config.cjs`, tests in `src/coders`)

##### Diagrammatic Elements
- Blue = JavaScript/TypeScript layers
- Green = Native modules (Android/iOS)
- Orange = External Adapty backend
- Gray = Build tooling & scripts
- Rounded rectangles for code modules
- Parallelograms for UI components

## Diagram (Mermaid)

```mermaid
flowchart TD
    App["Consumer App"]:::external

    subgraph "JS/TS Layer"
        API["Public API"]:::jsLayer
        DataMapper["Data Mapper\n(src/coders)"]:::jsLayer
        Bridge["JS ↔ Native Bridge"]:::jsLayer
        NativeRequest["Native Request Handler"]:::jsLayer
        Logger["Logger Module"]:::jsLayer
        Types["Shared Types"]:::jsLayer
        UI["UI Components"]:::jsLayer
    end

    subgraph "Native Modules"
        Android["Android Module"]:::native
        iOS["iOS Module"]:::native
    end

    NativeSDK["Native Adapty SDK"]:::native
    AdaptyBackend[(Adapty Backend\nREST/WebSocket)]:::backend
    Build["Build & Release Tooling"]:::tooling

    App -->|"import/init"| API
    API -->|"calls"| DataMapper
    API -->|"delegates to"| Bridge
    API -->|"logs via"| Logger
    API -->|"uses types from"| Types

    Bridge -->|"RPC JSON payload"| Android
    Bridge -->|"RPC JSON payload"| iOS
    Bridge -->|"dispatch via"| NativeRequest

    Android -->|"invoke SDK"| NativeSDK
    iOS -->|"invoke SDK"| NativeSDK

    NativeSDK -->|"HTTPS/WebSocket"| AdaptyBackend
    AdaptyBackend -->|"response"| NativeSDK

    NativeSDK -->|"event callback"| Bridge
    Bridge -->|"returns JSON"| DataMapper
    DataMapper -->|"mapped models"| API
    API -->|"returns data"| App

    Android -->|"UI Events"| UI
    iOS -->|"UI Events"| UI
    UI -->|"emits events"| API

    Build -.-> API
    Build -.-> Android
    Build -.-> iOS

    click API "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/src/index.ts"
    click Bridge "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/src/bridge.ts"
    click DataMapper "https://github.com/adaptyteam/adaptysdk-react-native/tree/master/src/coders/"
    click NativeRequest "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/src/native-request-handler/index.ts"
    click NativeRequest "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/src/native-request-handler/native-request-handler.ts"
    click Logger "https://github.com/adaptyteam/adaptysdk-react-native/tree/master/src/logger/"
    click Types "https://github.com/adaptyteam/adaptysdk-react-native/tree/master/src/types/"
    click UI "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/src/ui/index.tsx"
    click Android "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/android/src/main/kotlin/com/adapty/react/AdaptyReactModule.kt"
    click iOS "https://github.com/adaptyteam/adaptysdk-react-native/blob/master/ios/RNAdapty.m"

    classDef jsLayer fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef native fill:#90EE90,stroke:#000,stroke-width:1px
    classDef backend fill:#FFA500,stroke:#000,stroke-width:1px
    classDef tooling fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000,stroke-width:1px
```
