Mobile App Module OnMart - E-Commerce Mobile Application Documentation Table of Contents Project Overview Features Technology Stack Project Architecture Getting Started Project Structure Development Guidelines API Integration State Management Navigation Component Library Styling and Theming Internationalization (i18n) Environment Configuration Testing Build and Deployment Common Issues and Troubleshooting Best Practices Project Overview OnMart is a full-featured React Native e-commerce mobile application that provides a comprehensive shopping experience for both customers and affiliate marketers. The app supports iOS and Android platforms and features a modern, responsive UI built with TypeScript. Key Capabilities Shopping Experience : Browse products, search, filter by categories, add to cart, and checkout User Management : Authentication, profile management, address management Order Management : Track orders, view order history, manage payments Social Features : Chat with sellers, product ratings and reviews Affiliate Program : Complete affiliate marketing system with dashboard, collection management, and payment tracking Wishlist : Save favorite products for later Vouchers : Apply discount vouchers and track voucher history Store Management : Browse stores and view store details Real-time Features : Socket.io integration for real-time updates Features Customer Features Product Discovery Homepage with featured products and categories Product search with autocomplete Category-based browsing Product filtering and sorting Store browsing Product Details High-quality product images with zoom Detailed product information Product variants (size, color, etc.) Product reviews and ratings Store information Related products Shopping Cart Add/remove products Update quantities Apply vouchers View total price with discounts Checkout Process Multiple address support Shipping method selection Payment method integration Order summary Order Management Order tracking Order history Order status updates Payment status User Account Profile management Address book Wishlist Notification preferences Account deletion Communication Chat with sellers Real-time messaging Order inquiries Affiliate Features Affiliate Dashboard Earnings overview Performance metrics Commission tracking Collection Management Create product collections Manage collection items Custom collection banners Link Generation Generate affiliate links Track link performance Payment Management Withdrawal requests Payment history Tax information Technology Stack Core Technologies React Native : 0.75.2 React : 18.3.1 TypeScript : 5.0.4 Node.js : >= 18 Key Libraries State Management Redux Toolkit : @reduxjs/toolkit ^2.2.7 React Redux : ^9.1.2 Redux Persist : ^6.0.0 Navigation React Navigation : ^6.1.18 Native Stack Navigator Bottom Tabs Navigator Drawer Navigator API & Data Apollo Client : ^3.5.6 (GraphQL) Axios : ^1.7.7 (REST API) Socket.io Client : ^4.8.1 (Real-time) UI Components React Native Reanimated : ^3.15.1 React Native Gesture Handler : ^2.18.1 React Native SVG : ^15.9.0 React Native Vector Icons : ^10.1.0 React Native Maps : 1.20.0 Gorhom Bottom Sheet : ^5 Media & Camera React Native Vision Camera : ^4.5.3 React Native Image Picker : ^7.1.2 React Native Image Resizer : ^3.0.11 React Native Video : ^6.7.0 Utilities Moment.js : ^2.30.1 i18next : ^23.14.0 React Native Toast Notifications : ^3.4.0 React Native Share : ^12.0.3 Project Architecture OnMart follows a modular architecture with clear separation of concerns: Architecture Layers ┌─────────────────────────────────────┐ │ Presentation Layer │ │ (Pages, Components, Styles) │ ├─────────────────────────────────────┤ │ Business Logic Layer │ │ (HOF, Hooks, Custom Logic) │ ├─────────────────────────────────────┤ │ State Management │ │ (Redux, Context, Persistence) │ ├─────────────────────────────────────┤ │ Service Layer │ │ (API Services, GraphQL) │ ├─────────────────────────────────────┤ │ Data Layer │ │ (REST API, GraphQL, WebSocket) │ └─────────────────────────────────────┘ Design Patterns Atomic Design : Component library organized as Atoms → Molecules → Organisms Higher-Order Functions (HOF) : Business logic separated from UI components Service Layer Pattern : Centralized API calls in service modules Container/Presentational Pattern : Separation of data handling and UI rendering Getting Started Prerequisites Before you begin, ensure you have the following installed: Node.js (>= 18.x) Yarn (3.6.4 - managed via packageManager) React Native CLI Xcode (for iOS development, macOS only) Android Studio (for Android development) CocoaPods (for iOS dependencies) Environment Setup Follow the React Native Environment Setup guide for your operating system. Installation Clone the repository git clone https://github.com/ondeliveroper/OnMart.git cd OnMart Install dependencies yarn install Install iOS dependencies (macOS only) cd ios pod install cd .. Configure environment # For development yarn dev # For production yarn prod This copies the appropriate .env.dev or .env.prod file to .env Running the Application Development Mode Start Metro bundler yarn start Run on iOS (in a new terminal) yarn ios Run on Android (in a new terminal) yarn android Production Build Android yarn android:build Output: android/app/build/outputs/apk/release/app-release.apk iOS Build through Xcode or use Fastlane (requires configuration) Project Structure OnMart/ ├── android/ # Android native code ├── ios/ # iOS native code ├── src/ # Application source code │ ├── api/ # API integration │ │ ├── services/ # Service modules │ │ ├── axios-instance.ts # Axios configuration │ │ ├── axios-request.ts # Request wrapper │ │ └── endpoints.ts # API endpoints │ ├── assets/ # Static assets (images, icons, fonts) │ ├── components/ # Reusable components │ │ ├── atoms/ # Basic UI elements │ │ ├── molecules/ # Composed components │ │ └── organisms/ # Complex components │ ├── contexts/ # React Context providers │ │ ├── theme.tsx # Theme context │ │ └── product-card-bottom-sheet/ # Bottom sheet context │ ├── graphql/ # GraphQL operations │ │ ├── queries/ # GraphQL queries │ │ └── mutations/ # GraphQL mutations │ ├── hooks/ # Custom React hooks │ ├── i18n/ # Internationalization │ │ ├── locales/ # Translation files │ │ └── index.ts # i18n configuration │ ├── navigation/ # Navigation configuration │ │ ├── app-navigator.tsx # Main navigator │ │ ├── root-navigation.tsx # Navigation root │ │ └── components/ # Navigation components │ ├── pages/ # Application screens │ │ ├── home/ │ │ ├── product-detail/ │ │ ├── cart/ │ │ ├── checkout/ │ │ ├── profile/ │ │ ├── affiliate-*/ # Affiliate pages │ │ └── ... │ ├── store/ # Redux store │ │ ├── actions/ # Action creators │ │ ├── reducers/ # Reducers │ │ ├── root-reducer.ts # Root reducer │ │ └── index.ts # Store configuration │ ├── types/ # TypeScript type definitions │ └── utils/ # Utility functions ├── __tests__/ # Test files ├── patches/ # Package patches ├── .env.dev # Development environment variables ├── .env.prod # Production environment variables ├── App.tsx # Application entry point ├── index.js # React Native entry point ├── package.json # Dependencies and scripts └── tsconfig.json # TypeScript configuration Key Directories Explained /src/api/services/ Contains service modules for API integration: auth-service.ts - Authentication endpoints product-service.ts - Product operations cart-service.ts - Shopping cart operations checkout-service.ts - Checkout process order-service.ts - Order management profile-services.ts - User profile operations wishlist-service.ts - Wishlist operations affiliate-service.ts - Affiliate program operations chat-service.ts - Chat functionality /src/components/ Follows Atomic Design methodology: Atoms : Button, Card, Container, TextInput, DatePicker, Dropdown, SkeletonLoader Molecules : BackButton, CartButton, Badge, Rating, SearchButton, PageInfo Organisms : Complex multi-component structures /src/pages/ Each page represents a screen in the app: Structure: page-name/page-name.tsx (UI) + page-name-hof.ts (logic) Components specific to a page are in page-name/components/ Styles are in page-name/style.ts /src/store/ Redux store configuration: actions : Action creators and action types reducers : State reducers (login, user, profile, counter, affiliate) Integrated with Redux Persist for state persistence Development Guidelines Code Organization Page Structure page-name/ ├── page-name.tsx # UI component ├── page-name-hof.ts # Business logic (Higher-Order Function) ├── style.ts # Styles └── components/ # Page-specific components ├── component-a.tsx └── component-b.tsx Component Structure import React from 'react'; import { View, Text } from 'react-native'; interface ComponentProps { // Props definition } const Component: React.FC = (props) => { // Component logic return ( {/* JSX */} ); }; export default Component; HOF Pattern const usePageHOF = () => { // State management // Business logic // API calls return { datas: { // Data to expose }, methods: { // Methods to expose } }; }; export default usePageHOF; Naming Conventions Files : kebab-case (e.g., product-detail.tsx ) Components : PascalCase (e.g., ProductCard ) Functions/Variables : camelCase (e.g., handleSubmit ) Constants : UPPER_SNAKE_CASE (e.g., API_BASE_URL ) Types/Interfaces : PascalCase (e.g., ProductType ) TypeScript Guidelines Always define types for props interface ButtonProps { title: string; onPress: () => void; disabled?: boolean; } Use type imports import type { ProductType } from '../types'; Avoid any type - use unknown if type is truly unknown Styling Guidelines Use theme for consistency const styles = createStyles(theme); Create reusable style functions export const createStyles = (theme: Theme) => StyleSheet.create({ container: { flex: 1, backgroundColor: theme.colors.background, }, }); Responsive design : Use percentages and flex for layouts API Integration REST API (Axios) Configuration API is configured in src/api/axios-instance.ts : Base URL from environment variables Request/response interceptors Authentication token injection Making API Calls Service modules in src/api/services/ provide type-safe API calls: // Example: Product Service import { getProductDetail } from '../api/services/product-service'; const fetchProduct = async (productId: string) => { try { const response = await getProductDetail(productId); // Handle response } catch (error) { // Handle error } }; Available Services AuthService : login, signup, logout, password reset ProductService : list products, product details, search CartService : add to cart, update cart, remove from cart CheckoutService : create order, payment processing OrderService : order history, order details, track order ProfileService : get/update profile, address management WishlistService : add/remove from wishlist AffiliateService : affiliate operations, commission tracking ChatService : send/receive messages GraphQL (Apollo Client) Configuration Apollo Client is configured in the app with: GraphQL endpoint Authentication headers File upload support (apollo-upload-client) Queries and Mutations Located in src/graphql/ : // Example Query import { useQuery } from '@apollo/client'; import { GET_PRODUCTS } from '../graphql/queries'; const { data, loading, error } = useQuery(GET_PRODUCTS, { variables: { categoryId: '123' } }); WebSocket (Socket.io) Real-time features use Socket.io: Chat messages Order status updates Notifications State Management Redux Store Structure { login: { isLoggedIn: boolean, token: string, // ... }, user: { userId: string, userInfo: UserType, // ... }, profile: { // User profile data }, counter: { cartCount: number, wishlistCount: number, notificationCount: number, }, affiliate: { // Affiliate program data } } Using Redux Accessing State import { useSelector } from 'react-redux'; const MyComponent = () => { const isLoggedIn = useSelector((state: RootState) => state.login.isLoggedIn); const cartCount = useSelector((state: RootState) => state.counter.cartCount); // Component logic }; Dispatching Actions import { useDispatch } from 'react-redux'; import { setUser } from '../store/actions'; const MyComponent = () => { const dispatch = useDispatch(); const handleLogin = (user: UserType) => { dispatch(setUser(user)); }; // Component logic }; Redux Persist State is automatically persisted to AsyncStorage. Configured in src/store/index.ts . Context API Used for: ThemeContext : Theme management PCBottomSheetProvider : Product card bottom sheet Navigation Navigation Structure Root Navigator ├── Auth Stack (if not logged in) │ ├── OnBoarding │ ├── Login │ ├── SignUp │ └── ForgotPassword └── Main App (if logged in) ├── Bottom Tab Navigator │ ├── Home Stack │ ├── Wishlist │ ├── Cart │ └── Profile └── Other Stacks ├── Product Detail Stack ├── Checkout Stack ├── Order Stack ├── Affiliate Stack └── Chat Stack Navigation Types Define navigation types in src/types/route.ts : export type RootStackParamList = { Home: undefined; ProductDetail: { productId: string }; // ... }; Navigating Between Screens import { useNavigation } from '@react-navigation/native'; const MyComponent = () => { const navigation = useNavigation(); const goToProduct = (productId: string) => { navigation.navigate('ProductDetail', { productId }); }; const goBack = () => { navigation.goBack(); }; }; Deep Linking Configure deep linking in react-native.config.js and navigation configuration for handling external links. Component Library Atomic Design Structure Atoms (Basic Building Blocks) Button import { Button } from '../../components';