# zoontek/react-native-permissions architecture

> Architecture diagram of the GitHub repository zoontek/react-native-permissions, 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/zoontek/react-native-permissions
- Repository: https://github.com/zoontek/react-native-permissions

## Overview

The react-native-permissions project is a cross‐platform library that provides a unified API to handle device permissions for React Native applications. Its purpose is to abstract away the different permission flows and platform-specific behaviors on iOS, Android, and Windows, allowing developers to check, request, and manage permissions consistently across these platforms.

##### Main Components
- Core JS/TypeScript Layer: Located in the “src” folder, this layer provides the main API (e.g., methods like check, request, checkNotifications, etc.) and defines types, results, and permission contracts.
- Native Bridge Layer: This is the integration point between React Native’s JavaScript and the platform-specific native code. The native modules (for instance, in “android”, “ios”, and “windows” directories) are implemented using Kotlin/Java (Android), Objective-C/Swift (iOS), and C++/C#/IDL (Windows) respectively.
- Platform-Specific Handlers:
– In the “ios” folder, several subdirectories exist, each handling a different permission (e.g., Camera, Contacts, Location, etc.).
– In the “android” folder, similar implementations reside with separate classes and modules (with architectures like “oldarch” and “newarch”).
– In the “windows” folder, you have the native implementation with a Visual Studio solution, C++ source files, and code generation.
- Example Application: The “example” folder demonstrates how an app integrates and uses the library. This folder includes sample projects for Android, iOS, and Windows, showing complete integration with Gradle, Xcode, and Visual Studio.
- Configuration and Build Tools: Various configuration files (e.g., package.json, .eslintrc.js, Podspec, Gradle files, NuGet.config) indicate the project’s integration with multiple build systems, package managers, and CI/CD pipelines.

##### Relationships and Data Flow
- The JavaScript API (core layer in “src”) acts as the entry point, receiving calls from the React Native app code.
- These API calls funnel through the native bridge (provided by React Native’s linking mechanism) into platform-specific native modules.
- Each platform module handles interactions with the native operating system’s permission APIs (e.g., iOS calls to CoreLocation or Camera APIs, Android calls to manifest-declared permissions, and Windows calls to system settings).

##### Architectural Patterns and Design Principles
- Abstraction Layer: The library cleanly separates the cross-platform logic (JS/TS code) from platform-specific implementations.
- Modular Design: Each permission (e.g., Camera, Contacts, Location) is implemented as its own module in the native directories. This modularity is also evident in the separation of “oldarch” and “newarch” code for Android.
- Extensibility: The README and project structure suggest that the module is designed to be easily extended with additional permissions or custom behaviors on each platform.
- Integration with Build Tools: Multiple configuration and build scripts (Gradle for Android, Podspec & Podfile for iOS, solution files for Windows) indicate clear integration with platform-specific build systems.

##### Relevant Technologies and Frameworks
- React Native: The base framework for cross-platform apps.
- JavaScript/TypeScript: Used in the “src” folder for the core API.
- Android Development Tools: Kotlin/Java source files, Gradle build system.
- iOS Development Tools: Xcode, Podspecs, Objective-C/Swift source files.
- Windows Development Tools: Visual Studio, C++ (or C++/CX/WinRT), and NuGet package configuration.
- Code quality and testing tools: ESLint, Prettier, GitHub workflows, and Jest configuration (as seen in the README and associated configuration files).

##### Final Assembly
– iOS: Display a block for “iOS Native Modules” that further divides into multiple permission handlers (Camera, Contacts, etc.).
– Android: Show “Android Native Modules” with separate branches for “oldarch” and “newarch” implementations if needed.
– Windows: Show “Windows Native Module” and associated code generation elements.
- Annotation on each side to denote how platform-specific behaviors (such as permission statuses and manual linking instructions) are handled.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User/Application"]:::user
    B["React Native Permissions API (JS/TS)"]:::js
    C["Native Bridge"]:::bridge
    G["Example Application"]:::example

    %% High-Level Flow
    A -->|"Invokes"| B
    B -->|"Routes"| C
    A -->|"Integrates"| G
    B -->|"ConfiguredBy"| X["Configuration & Build Tools"]:::config

    %% Native Modules Subgraphs
    subgraph "Android Native Module"
        D["Android Native Module"]:::android
        D1["android/src/main"]:::androidSub
        D2["android/src/oldarch"]:::androidSub
        D3["android/src/newarch"]:::androidSub
        D --> D1
        D --> D2
        D --> D3
    end

    subgraph "iOS Native Module"
        E["iOS Native Module"]:::ios
        E1["Camera"]:::iosSub
        E2["Contacts"]:::iosSub
        E3["Location (Always)"]:::iosSub
        E --> E1
        E --> E2
        E --> E3
    end

    subgraph "Windows Native Module"
        F["Windows Native Module"]:::windows
        F1["RNPermissions (codegen)"]:::windowsSub
        F --> F1
    end

    %% Bridge Connections to Native Modules
    C --> D
    C --> E
    C --> F

    %% Configuration & Build Tools Subgraph
    subgraph "Configuration & Build Tools"
        X1["package.json"]:::config
        X2["RNPermissions.podspec"]:::config
        X3["android/build.gradle"]:::config
        X4["example/android/build.gradle"]:::config
        X5["example/ios/Podfile"]:::config
        X6["windows/RNPermissions.sln"]:::config
        X7["NuGet.config"]:::config
    end
    %% Show connection from JS layer to configuration artifacts
    B --- X1
    B --- X2
    B --- X3
    B --- X4
    B --- X5
    B --- X6
    B --- X7

    %% Click Events
    click B "https://github.com/zoontek/react-native-permissions/tree/master/src/"
    click D "https://github.com/zoontek/react-native-permissions/tree/master/android/"
    click D1 "https://github.com/zoontek/react-native-permissions/tree/master/android/src/main"
    click D2 "https://github.com/zoontek/react-native-permissions/tree/master/android/src/oldarch"
    click D3 "https://github.com/zoontek/react-native-permissions/tree/master/android/src/newarch"
    click E "https://github.com/zoontek/react-native-permissions/tree/master/ios/"
    click E1 "https://github.com/zoontek/react-native-permissions/tree/master/ios/Camera"
    click E2 "https://github.com/zoontek/react-native-permissions/tree/master/ios/Contacts"
    click E3 "https://github.com/zoontek/react-native-permissions/tree/master/ios/LocationAlways"
    click F "https://github.com/zoontek/react-native-permissions/tree/master/windows/"
    click F1 "https://github.com/zoontek/react-native-permissions/tree/master/windows/RNPermissions"
    click G "https://github.com/zoontek/react-native-permissions/tree/master/example/"
    click X1 "https://github.com/zoontek/react-native-permissions/blob/master/package.json"
    click X2 "https://github.com/zoontek/react-native-permissions/blob/master/RNPermissions.podspec"
    click X3 "https://github.com/zoontek/react-native-permissions/blob/master/android/build.gradle"
    click X4 "https://github.com/zoontek/react-native-permissions/blob/master/example/android/build.gradle"
    click X5 "https://github.com/zoontek/react-native-permissions/tree/master/example/ios/Podfile"
    click X6 "https://github.com/zoontek/react-native-permissions/blob/master/windows/RNPermissions.sln"
    click X7 "https://github.com/zoontek/react-native-permissions/blob/master/NuGet.config"

    %% Styles
    classDef user fill:#f4cccc,stroke:#e06666,stroke-width:2px;
    classDef js fill:#ffe599,stroke:#bf9000,stroke-width:2px;
    classDef bridge fill:#ead1dc,stroke:#c27ba0,stroke-width:2px;
    classDef android fill:#b6d7a8,stroke:#6aa84f,stroke-width:2px;
    classDef androidSub fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef ios fill:#c9daf8,stroke:#6d9eeb,stroke-width:2px;
    classDef iosSub fill:#d0e0f0,stroke:#6d9eeb,stroke-width:2px;
    classDef windows fill:#d9d2e9,stroke:#8e7cc3,stroke-width:2px;
    classDef windowsSub fill:#e6e0ec,stroke:#8e7cc3,stroke-width:2px;
    classDef example fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
    classDef config fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
```
