# yogendrashelke/native-cookies architecture

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

- Interactive diagram: https://gitdiagram.com/yogendrashelke/native-cookies
- Repository: https://github.com/yogendrashelke/native-cookies

## Overview

##### Project Type and Purpose
- This is a React Native “Native Module” library called **native-cookies**.
- Purpose: Expose a cross-platform JavaScript API for cookie management (get, set, clear) by bridging into Android and iOS native cookie storage.

##### File-Structure Analysis
- Top-level:
- src/index.js – JavaScript entry point exporting the Cookies API.
- android/ – Android native module (Kotlin classes, Gradle build).
- ios/ – iOS native module (Objective-C/Swift bindings, .podspec).
- example/ – A full React Native app demonstrating usage (both Android and iOS).
- .circleci/config.yml – CI pipeline.
- babel.config.js, tsconfig.json, package.json – tooling and packaging.

##### Key Insights from README
- JS API calls `Cookies.get`, `Cookies.set`, `Cookies.clear`, `Cookies.clearAll`.
- For iOS: requires CocoaPods integration.
- The library is published to npm under “native-cookies”.

##### Main Components
a. **Consumer App** (example/ or any RN app)
- JS layer imports `native-cookies`
- Metro bundler / React Native runtime
b. **JavaScript Module**
- src/index.js exposes Promise‐based API
- Babel/Javascript toolchain
c. **React Native Bridge**
- JS ↔ Native boundary
- automatically generated via NativeModule registry
d. **Android Native Module**
- NativeCookiesModule.kt / NativeCookiesPackage.kt
- Uses Android’s `android.webkit.CookieManager`
- Gradle build & package config
e. **iOS Native Module**
- NativeCookies.h / NativeCookies.m
- CocoaPods (*.podspec)
- Uses `NSHTTPCookieStorage`
f. **Platform Cookie Storage**
- Android WebView cookie store
- iOS NSHTTPCookieStorage
g. **CI Pipeline** (CircleCI)
- Lint, test, build steps

##### Interactions and Data Flow
- Branch: Bridge → Android Native Module → Android CookieManager
Bridge → iOS Native Module → NSHTTPCookieStorage
- Responses flow back along the same path (native → bridge → JS → app)
- CI pipeline triggers builds/tests on push

##### Architectural Patterns & Design Principles
- **Bridge Pattern**: JS API decoupled from platform implementations
- **Module Separation**: Single-responsibility modules for Android and iOS
- **Platform-agnostic API**: Common JS interface for both platforms
- **Example App** as a “consumer” micro-service to validate integration

##### Relevant Technologies
- JavaScript / React Native
- Kotlin (Android), Objective-C / Swift (iOS)
- Gradle (Android), CocoaPods (iOS)
- Metro bundler, Babel
- CircleCI for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer App
    subgraph "Consumer App" 
        direction TB
        ConsumerApp["Example App"]:::js
    end

    %% JavaScript Module
    subgraph "JavaScript Layer" 
        direction TB
        JSModule["src/index.js\n(JS API)"]:::js
    end

    %% React Native Bridge
    subgraph "React Native Bridge" 
        direction TB
        Bridge["RN Bridge\n(NativeModule)"]:::js
    end

    %% Native Modules
    subgraph "Native Modules"
        direction TB
        subgraph "Android Native Module"
            direction TB
            AndroidModule["NativeCookiesModule.kt\n& Package.kt"]:::android
            AndroidStorage["android.webkit.CookieManager"]:::android_storage
        end
        subgraph "iOS Native Module"
            direction TB
            IOSModule["NativeCookies.h/m"]:::ios
            IOSStorage["NSHTTPCookieStorage"]:::ios_storage
        end
    end

    %% External Services
    CI["CircleCI Pipeline"]:::external
    NpmRegistry["npm Registry"]:::external
    CocoaPodsRegistry["CocoaPods Registry"]:::external

    %% Connections
    ConsumerApp -->|"import native-cookies"| JSModule
    JSModule -->|"calls Cookies.get/set/clear"| Bridge
    Bridge -->|"Android side"| AndroidModule
    AndroidModule -->|reads/writes| AndroidStorage
    Bridge -->|"iOS side"| IOSModule
    IOSModule -->|reads/writes| IOSStorage
    JSModule -->|"publish"| NpmRegistry
    Bridge -->|"podspec"| CocoaPodsRegistry
    CI -->|"build & test on push"| JSModule

    %% Click Events
    click ConsumerApp "https://github.com/yogendrashelke/native-cookies/tree/master/example/"
    click JSModule "https://github.com/yogendrashelke/native-cookies/blob/master/src/index.js"
    click Bridge "https://github.com/yogendrashelke/native-cookies/blob/master/native-cookies.podspec"
    click Bridge "https://github.com/yogendrashelke/native-cookies/blob/master/android/build.gradle"
    click AndroidModule "https://github.com/yogendrashelke/native-cookies/blob/master/android/src/main/java/com/nativecookies/NativeCookiesModule.kt"
    click AndroidModule "https://github.com/yogendrashelke/native-cookies/blob/master/android/src/main/java/com/nativecookies/NativeCookiesPackage.kt"
    click AndroidModule "https://github.com/yogendrashelke/native-cookies/blob/master/android/gradle.properties"
    click IOSModule "https://github.com/yogendrashelke/native-cookies/blob/master/ios/NativeCookies.h"
    click IOSModule "https://github.com/yogendrashelke/native-cookies/blob/master/ios/NativeCookies.m"
    click IOSModule "https://github.com/yogendrashelke/native-cookies/tree/master/ios/NativeCookies.xcodeproj/"
    click IOSModule "https://github.com/yogendrashelke/native-cookies/tree/master/example/ios/Podfile"
    click CI "https://github.com/yogendrashelke/native-cookies/blob/master/.circleci/config.yml"

    %% Styles
    classDef js fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef android fill:#D5F5E3,stroke:#333,stroke-width:1px
    classDef ios fill:#FCF3CF,stroke:#333,stroke-width:1px
    classDef android_storage fill:#ABEBC6,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef ios_storage fill:#F9E79F,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#E5E7E9,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
