# ondc-official/ondc-mobile-buyer-app architecture

> Architecture diagram of the GitHub repository ondc-official/ondc-mobile-buyer-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ondc-official/ondc-mobile-buyer-app
- Repository: https://github.com/ondc-official/ondc-mobile-buyer-app

## Overview

##### Project Type and Purpose
- This is a React Native mobile client (“ONDC Saarthi”) for Android and iOS that serves as a buyer-facing reference application on the ONDC platform.
- It is organized as a cross-platform front-end, with native Android (Java/Gradle) and iOS (Objective-C/Swift/CocoaPods) wrappers around a TypeScript/React-Native codebase.

##### Top-Level Architecture & Components
- Presentation Layer (JavaScript/TypeScript):
– Entry point: index.js → App.tsx
– React components under src/components and feature modules under src/modules/…
– Navigation: src/navigation/AppNavigation.tsx (React Navigation)
- State Management:
– Redux Toolkit store (src/toolkit/store.js) with feature slices (auth, cart, categories, etc.)
– Hooks (src/hooks) for data fetching, business logic, device services
- Data Layer & APIs:
– src/utils/apiActions.ts orchestrates HTTP calls to ONDC network endpoints
– Environment‐specific config (.env.development, staging, preprod, production) injected at build time
– Local persistence: AsyncStorage (via src/utils/storage.ts) and file system (src/hooks/useFileSystem)
- Native Modules & Bridging:
– Android custom modules: SSLPinningFactory, RootCheckModule/Package
– iOS custom code in AppDelegate and native modules bridging to JS
– Firebase integration via google-services.json / GoogleService-Info.plist per environment
- External Services:
– ONDC network APIs (buyer services)
– Firebase (analytics, messaging, crashlytics)
– Device Services: Location (background fetch), Camera/QR, Audio recorder
– Map assets under src/assets/maps (likely to drive a map SDK)

##### Relationships & Data Flows
- User taps UI → React component dispatches Redux action → thunk in src/utils/apiActions makes HTTP call → server response → store updates → UI re-renders.
- React Native Bridge: JS side calls native modules (e.g., RootCheck, SSL pinning) for security checks.
- Environment Configuration: Build scripts (npm run ios:development, android:prod) select the proper .env file → Gradle/Xcode injects config → app connects to correct backend.
- Asset Flow: fonts & images bundled via Metro bundler → delivered to native apps → shown in UI.

##### Architectural Patterns & Design Principles
- Feature-based module separation (each feature under src/modules/<feature>)
- Unidirectional data flow via Redux (actions → reducers → store → view)
- Custom hooks encapsulate cross-cutting concerns (network error handling, formatting, location)
- Environment-driven builds (multiple Android flavors, iOS schemes)
- Native-JS boundary clearly delineated (only security, platform APIs exposed as modules)

a. Main Components to include:
– Mobile Device (Android/iOS)
– Native Shells: Android (Java/Kotlin, Gradle) & iOS (Obj-C/Swift, Xcode)
– React Native Bridge
– JavaScript Layer:
- UI Components (src/components)
- Feature Modules (src/modules)
- Navigation (AppNavigation)
- State Store (Redux Toolkit)
- Hooks & Utilities (src/hooks, src/utils)
– External Services: ONDC Buyer API, Firebase, Map SDK, Device Sensors
– Build & Deployment: Metro bundler, Babel, Gradle, CocoaPods
b. Relationships & Interactions:
– Data flow from build scripts → environment config → compiled native apps.
c. Highlighted Patterns:
d. Key Technologies & Libraries:
– React Native, TypeScript, Redux Toolkit, React Navigation
– Android Gradle, ProGuard, keystores
– Xcode Schemes, CocoaPods
– Firebase, Watchman, Metro, Babel

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Build & Deployment Layer
  subgraph "Build & Deployment" 
    direction TB
    Scripts["Build Scripts (package.json, babel.config.js, metro.config.js)"]:::build
    Env["Environment Config (.env.*)"]:::build
    Scripts --> Env
  end

  %% Native Shells
  subgraph "Native Shells" 
    direction TB
    Android["Android Shell (Java/Kotlin, Gradle)"]:::native
    iOS["iOS Shell (Obj-C/Swift, Xcode)"]:::native
    Android -->|"injects env"| Env
    iOS -->|"injects env"| Env
  end

  %% React Native Bridge
  Bridge["React Native Bridge"]:::native

  Android --> Bridge
  iOS --> Bridge

  %% JavaScript Layer
  subgraph "JavaScript Layer"
    direction TB
    Entry["Entry Point\n/index.js → /App.tsx"]:::presentation
    Navigation["Navigation\nAppNavigation"]:::presentation
    UI["UI Components\nsrc/components"]:::presentation
    Modules["Feature Modules\nsrc/modules"]:::presentation
    Store["Redux Store\nsrc/toolkit/store.js"]:::business
    Slices["Feature Slices\nsrc/toolkit/reducer/*.js"]:::business
    Hooks["Custom Hooks\nsrc/hooks"]:::business
    Utils["API & Utils\nsrc/utils"]:::business
    Storage["Local Persistence\nsrc/utils/storage.ts"]:::business
    Assets["Assets\nsrc/assets"]:::business
    I18n["i18n\nsrc/i18n"]:::business

    Entry --> Navigation
    Navigation --> UI
    UI --> Modules
    Modules --> Store
    Store --> Slices
    Slices --> Utils
    Utils --> Storage
    Utils --> Hooks
    Utils --> Assets
    Utils --> I18n
  end

  Bridge --> Entry
  Utils -->|"HTTP calls"| ExternalAPI

  %% External Services
  subgraph "External Services"
    direction TB
    ExternalAPI["ONDC Buyer API"]:::external
    Firebase["Firebase"]:::external
    Maps["Map SDK"]:::external
    Sensors["Device Sensors"]:::external
  end

  Utils --> ExternalAPI
  Bridge --> ExternalAPI
  Bridge --> Firebase
  UI --> Maps
  Hooks --> Sensors

  %% Click Events
  click Scripts "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main/package.json"
  click Env "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main/.env.example"
  click Android "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//android/app/build.gradle"
  click iOS "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//ios/ONDCReferenceBuyerApp.xcodeproj"
  click Entry "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//index.js"
  click Entry "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//App.tsx"
  click UI "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main//src/components"
  click Modules "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main//src/modules"
  click Navigation "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/navigation/AppNavigation.tsx"
  click Store "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/store.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/auth.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/cart.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/categories.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/complaint.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/order.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/stores.js"
  click Slices "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/toolkit/reducer/address.js"
  click Hooks "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/hooks/useFileSystem.ts"
  click Hooks "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/hooks/useLocationBackgroundFetch.ts"
  click Hooks "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/hooks/useNetworkErrorHandling.js"
  click Utils "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/utils/apiActions.ts"
  click Storage "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/utils/storage.ts"
  click Utils "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/utils/utils.ts"
  click Assets "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main//src/assets/maps"
  click Assets "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main//src/assets"
  click iOS "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//ios/ONDCReferenceBuyerApp/AppDelegate.h"
  click iOS "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//ios/ONDCReferenceBuyerApp/AppDelegate.mm"
  click iOS "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main//ios/Podfile"
  click Env "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//babel.config.js"
  click I18n "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/i18n/index.ts"
  click I18n "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/i18n/en.json"
  click I18n "https://github.com/ondc-official/ondc-mobile-buyer-app/blob/main//src/i18n/hi.json"
  click ExternalAPI "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main/N/A"
  click Firebase "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main/N/A"
  click Maps "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main/N/A"
  click Sensors "https://github.com/ondc-official/ondc-mobile-buyer-app/tree/main/N/A"

  %% Styles
  classDef presentation fill:#D0E8FF,stroke:#0366d6,stroke-width:2px
  classDef business fill:#DFF5E1,stroke:#28a745,stroke-width:2px
  classDef native fill:#F0D9FF,stroke:#6f42c1,stroke-width:2px
  classDef external fill:#FFECCF,stroke:#cb2431,stroke-width:2px
  classDef build fill:#E2E2E2,stroke:#555555,stroke-width:2px
```
