# okta/okta-react-native architecture

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

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

## Overview

##### Main Components
- React Native Layer: Represent the JavaScript modules and APIs (e.g., createConfig, signIn, signOut, getAccessToken, etc.) that expose authentication functionality to the consumer.
- Native Modules: Separate native implementations for iOS and Android:
- Android: Shown in the “android” directory (with Java classes such as OktaSdkBridgeModule.java, HttpClientImpl.java, etc.) that directly wrap the Okta OIDC Android SDK.
- iOS: Found in the “ios” directory, including bridging header files and Swift/Objective-C classes (e.g., OktaSdkBridge.swift, ReactNativeOktaSdkBridge.m) that interface with the Okta OIDC iOS SDK.
- External Dependencies: Include the external Okta OIDC libraries (for both Android and iOS) as well as any other dependency (for example, the Okta AuthJS integration for custom sign-in) that the library is built on.
- Testing and CI/CD: The “e2e”, “test”, and “.github” directories indicate end-to-end tests (with sample React Native applications and native integration tests) and workflows. It is useful to show how these tests interact with the main components.
- Build and Configuration Components: Include the “scripts”, “.circleci”, “.github/workflows”, etc. to indicate how the library is built, tested, and maintained.

##### Relationships and Data Flows
- How a React Native app calls the exposed authentication API (e.g., createConfig, signIn) in the JavaScript layer.
- For the native modules, illustrate separate flows:
- On Android, how the native module forwards authentication requests to the Okta OIDC Android SDK (with dependencies on build files like Gradle) and then relays responses back to JavaScript.
- On iOS, how the bridging components interact with the Okta OIDC iOS Framework using CocoaPods and exposes responses back through the React Native bridge.
- Network communication component: show that once authentication is initiated, native modules interact with external Okta authentication servers via the OAuth 2.0 Authorization Code Flow with PKCE, then return tokens and user info.

##### Architectural Patterns and Technologies
- Client-Bridge-Native pattern: The layered architecture which cleanly separates front-end (React Native) from the native SDK implementations.
- Use of event-driven patterns: The library uses event emitters to signal signInSuccess, signOutSuccess, onError, and onCancelled events.
- Dependency Management: Gradle for Android, CocoaPods for iOS, and package.json for JavaScript dependencies.
- Testing: End-to-end (e2e) test applications simulate full flows, while unit and integration tests (located in “test” and “ios/Tests”) ensure quality.
- CI/CD: The presence of circleci and GitHub workflows indicates continuous integration pipelines that automates build, lint, and test steps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% React Native Layer
    subgraph "React Native Layer"
        RN["React Native API Module\n(Exposes createConfig, signIn, signOut, token retrieval)"]:::react
    end

    %% Native Modules
    subgraph "Native Modules"
        Android["Android Native Module\n(OktaSdkBridgeModule, HttpClientImpl, etc.)"]:::android
        IOS["iOS Native Module\n(OktaSdkBridge, bridging headers, etc.)"]:::ios
    end

    %% External Dependencies & Authentication
    subgraph "External Dependencies & Authentication"
        AndroidSDK["Okta OIDC Android SDK"]:::external
        iOSSDK["Okta OIDC iOS SDK"]:::external
        Okta["Okta Authentication Server\n(OAuth 2.0 with PKCE)"]:::external
    end

    %% Testing and CI/CD
    subgraph "Testing and CI/CD"
        E2E["End-to-End Tests"]:::ci
        UT["Unit/Integration Tests"]:::ci
        CICD["CircleCI Pipelines"]:::ci
        GH["GitHub Workflows"]:::ci
    end

    %% Build & Dev Tools
    subgraph "Build & Dev Tools"
        Build["Build & Configuration Tools"]:::build
        Gradle["Gradle Configuration"]:::build
        Pod["iOS Pod Setup"]:::build
    end

    %% Data Flows - React Native to Native
    RN -->|"bridge call"| Android
    RN -->|"bridge call"| IOS

    %% Native Modules to External Authentication
    Android -->|"initiates OAuth flow"| Okta
    IOS -->|"initiates OAuth flow"| Okta

    %% Native Modules depend on their respective SDKs
    Android ---|"depends on"| AndroidSDK
    IOS ---|"depends on"| iOSSDK

    %% Build & Dev Tools supporting Native Modules
    Build -->|"build scripts"| Android
    Build -->|"build scripts"| IOS
    Build -->|"manages Android deps"| Gradle
    Build -->|"manages iOS deps"| Pod

    %% Testing and CI/CD interactions
    E2E -->|"simulate app usage"| RN
    UT -->|"test JS & Native modules"| RN
    CICD -->|"triggers builds"| Build
    CICD -->|"runs tests"| E2E
    GH -->|"runs tests"| UT

    %% Click Events
    click RN "https://github.com/okta/okta-react-native/blob/master/index.js"
    click Android "https://github.com/okta/okta-react-native/tree/master/android/src/main/java/com/oktareactnative"
    click IOS "https://github.com/okta/okta-react-native/tree/master/ios/OktaSdkBridge"
    click Gradle "https://github.com/okta/okta-react-native/blob/master/android/build.gradle"
    click Pod "https://github.com/okta/okta-react-native/tree/master/ios/Podfile"
    click E2E "https://github.com/okta/okta-react-native/tree/master/e2e"
    click UT "https://github.com/okta/okta-react-native/tree/master/test"
    click CICD "https://github.com/okta/okta-react-native/blob/master/.circleci"
    click GH "https://github.com/okta/okta-react-native/blob/master/.github"
    click Build "https://github.com/okta/okta-react-native/tree/master/scripts"

    %% Styles
    classDef react fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef android fill:#ABEBC6,stroke:#117864,stroke-width:2px;
    classDef ios fill:#F9E79F,stroke:#9A7D0A,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef ci fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef build fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
```
