How bagisto/opensource-ecommerce-mobile-app works
Project Type & Purpose
• This is a cross-platform mobile (and desktop/web) application built with Flutter.
• It serves as an e-commerce storefront for a Bagisto/Laravel backend, consuming a GraphQL API.
• Core features include product browsing, search (MLKit & ARCore), cart, orders, payments, user account management, push notifications (FCM), theming, localization, and offline support.
File Structure & Architectural Patterns
• Top-level “android”, “ios”, “web”, “linux”, “macos”, “windows”: platform-specific Flutter hosts.
• “lib/”: shared Dart code subdivided into:
• data_model/ — DTOs for GraphQL queries & mutations
• screens/ — UI by feature, each using the BLoC (business logic component) pattern
• services/ — network layer (api_client.dart, graph_ql.dart, mutation_query.dart)
• utils/ — helpers (navigation, localization, theme, preferences, connectivity)
• widgets/ — reusable UI components
• assets/: static resources (images, Lottie, localization JSON)
• pubspec.yaml: Flutter/Dart dependencies
README Insights
• Frontend only; backend API module lives in a separate Bagisto/Laravel repo.
• Uses GraphQL for real-time sync of products/categories/orders.
• Requires Firebase Cloud Messaging for push notifications.
• Integrates ARCore and MLKit for camera-based search features.
a. Main Components
1. Flutter Client
• UI Layer (screens/widgets)
• BLoC Layer (feature blocs, events, states, repositories)
• Data Model Layer (GraphQL DTOs)
• Service Layer (HTTP/GraphQL client, query builder)
• Utility Layer (preferences, localization, theming, network monitor)
2. Platform Hosts
• Android/iOS/Web/Desktop wrappers invoking the Flutter engine
• Native integrations: FCM, camera permissions, ARCore, MLKit
3. External Services
• Bagisto GraphQL API (Laravel)
• Firebase Cloud Messaging
• (Optionally) Analytics / Crash Reporting
4. Data Stores
• On-device: SharedPreferences for caching tokens, theme/lang
• Remote: MySQL (in Laravel), accessible via GraphQL
b. Relationships & Data Flow
• UI triggers user actions → BLoC Event
• BLoC processes logic → calls Service Layer
• Service Layer issues GraphQL HTTP request → remote Bagisto API
• API returns JSON → Data Model parses into Dart objects
• BLoC emits new State → UI rebuilds
• Push notifications flow from FCM → platform host → Flutter (via FCM plugin) → BLoC → UI
• AR/ML flows: UI invites camera plugin → ARCore/MLKit SDK → returns results → Service Layer (for search)
c. Architectural Patterns & Design Principles
• Presentation/Business/Data separation via BLoC
• Single source of truth in GraphQL backend
• Dependency inversion: BLoCs depend on abstract repositories
• Reusability: shared widgets and utils
• Platform-agnostic core in “lib/”, platform-specific in host folders
d. Key Technologies
• Flutter & Dart
• BLoC state management
• GraphQL (queries + mutations)
• HTTP client (graphql_base_model, mutation_query)
• Firebase Cloud Messaging
• ARCore, MLKit (camera, image processing)
• SharedPreferences