# formidablelabs/react-native-app-auth architecture

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

- Interactive diagram: https://gitdiagram.com/formidablelabs/react-native-app-auth
- Repository: https://github.com/formidablelabs/react-native-app-auth

## Overview

##### Main Components to Highlight
- React Native JavaScript Layer: This is the public-facing API that developers use in their React Native apps.
- Bridge Module (React Native App Auth Package): Located under packages/react-native-app-auth, this component serves as the bridge between JavaScript and native code.
- Native Modules for iOS: The “ios” folder inside the packages/react-native-app-auth directory contains the native iOS implementation that wraps the AppAuth-iOS SDK.
- Native Modules for Android: Similarly, the “android” folder in the same package contains the native Android implementation that wraps the AppAuth-Android SDK.
- Demo/Example Apps: Found under examples/demo, these apps (with subdirectories for iOS and Android) demonstrate integration and provide a reference for usage.
- Documentation and Developer Guides: Under docs, this section provides comprehensive guides, configuration examples, and provider-specific documentation.

##### Relationships and Interactions
- From a usage perspective, the React Native application (consumer) calls the JavaScript API exposed by the bridge.
- The bridge delegates authentication requests from the JS layer to the native modules.
- The iOS and Android native modules then call into their respective AppAuth native SDKs to perform the OAuth2 / OpenID Connect flows.
- After successfully authenticating, the results (tokens, errors, etc.) propagate back through the native layer, into the bridge module, and then back to the JS layer.
- The examples and test code validate these data flows and interactions, ensuring that configurations (such as redirect URLs, PKCE handling, etc.) are correctly set up.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The architecture cleanly separates Android and iOS logic from the shared JavaScript logic.
- Bridging Pattern: Implements a bridge that allows interoperability between React Native’s JS environment and native implementations.
- Modular Design: With a clear packages directory, the project is designed for easy extension/maintenance and is built with a plugin-like architecture for supporting multiple providers.
- Documentation Driven Development: The docs folder contains Docusaurus-based documentation, which is a key part of the project ecosystem.

##### Relevant Technologies and Frameworks
- React Native: The core platform.
- AppAuth-iOS and AppAuth-Android: The native authentication SDKs.
- OAuth 2.0 and OpenID Connect standards.
- Native build systems such as Xcode for iOS and Gradle for Android.
- The build and testing tools include ESLint, Prettier, Jest, and others which support code health and consistency.

##### Detail
- Major configuration and build tools briefly if space permits (for instance, mention that there are Gradle build scripts for Android and Pod configurations for iOS in the respective native modules).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["React Native Application (JS Layer)"]:::jsLayer
    B["React Native App Auth API"]:::api
    X["Type Definitions"]:::api
    C["Bridge Module"]:::bridge
    D["Native Module - iOS"]:::native
    E["AppAuth-iOS SDK"]:::sdk
    F["Native Module - Android"]:::native
    G["AppAuth-Android SDK"]:::sdk
    H["Demo/Example Apps"]:::demo
    I["Documentation & Developer Guides"]:::docs

    %% Main Authentication Flow
    A -->|"calls"| B
    B -->|"implements"| C
    B -->|"providesTypes"| X
    C -->|"delegates-to"| D
    C -->|"delegates-to"| F
    D -->|"calls"| E
    F -->|"calls"| G
    E -->|"returns"| D
    G -->|"returns"| F
    D -->|"passesResult"| C
    F -->|"passesResult"| C
    C -->|"returnsResult"| B
    B -->|"returnsResult"| A

    %% Supporting Components
    A -->|"integratesWith"| H
    A -->|"refersTo"| I

    %% Click Events
    click B "https://github.com/formidablelabs/react-native-app-auth/blob/main/packages/react-native-app-auth/index.js"
    click X "https://github.com/formidablelabs/react-native-app-auth/blob/main/packages/react-native-app-auth/index.d.ts"
    click C "https://github.com/formidablelabs/react-native-app-auth/tree/main/packages/react-native-app-auth"
    click D "https://github.com/formidablelabs/react-native-app-auth/tree/main/packages/react-native-app-auth/ios"
    click F "https://github.com/formidablelabs/react-native-app-auth/tree/main/packages/react-native-app-auth/android"
    click H "https://github.com/formidablelabs/react-native-app-auth/tree/main/examples/demo"
    click I "https://github.com/formidablelabs/react-native-app-auth/tree/main/docs"

    %% Styles
    classDef jsLayer fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#E0FFFF,stroke:#000,stroke-width:2px;
    classDef bridge fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef native fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef sdk fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef demo fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef docs fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
