How ondc-official/ondc-mobile-buyer-app works
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