# medora0/fruit_hub architecture

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

- Interactive diagram: https://gitdiagram.com/medora0/fruit_hub
- Repository: https://github.com/medora0/fruit_hub

## Overview

##### Project Type & Purpose
- A cross-platform (Android, iOS, Web, Desktop) e-commerce mobile app built in Flutter.
- Clean-architecture layers with BLoC/Cubit state management.
- Backend services entirely serverless: Firebase (Auth, Firestore) + PayPal integration.

##### High-Level Architecture Components
A. Presentation Layer (Client UI)
– Flutter Widgets & Views (lib/features/…/presentation/views)
– Cubits (lib/core/cubits + lib/features/…/presentation/cubits)
– Routes (on_generate_routes)
– Entry point: main.dart
B. Domain Layer
– Entities (lib/core/entities + lib/features/…/domain/entities)
– Repository Interfaces (lib/core/repos/*.dart + lib/features/…/domain/repository)
C. Data Layer
– Repository Implementations (lib/core/repos/*_impl.dart + lib/features/…/data/repository/*.dart)
– Data Models (lib/core/models, lib/features/…/data/models)
D. Infrastructure / Core Services
– FirebaseAuthService, FirestoreService (lib/core/services)
– SharedPreferencesSingleton, DatabaseService
– get_it Service Locator (GetItService)
E. External Systems
– Firebase Authentication
– Firestore Database
– PayPal REST API
– Social Auth Providers (Google, Facebook, Apple)

##### Component Interactions & Data Flow
1. User taps UI widget → triggers Cubit event.
2. Cubit calls Domain-level repository interface.
3. Repository implementation uses Core Service (FirebaseAuthService, FirestoreService, SharedPreferences).
4. Core Service issues HTTP/SDK calls to external systems (Firebase, PayPal).
5. Responses travel back up: Service → Repo → Cubit → UI.

##### Architectural Patterns & Principles
- Clean Architecture: strict separation of Presentation / Domain / Data / Infrastructure.
- BLoC Pattern with Cubit for state management.
- Dependency Injection via get_it.
- Feature-based module organization.
- Layered reusable “core” for shared code.

##### Technologies & Frameworks
– Flutter & Dart (UI)
– BLoC/Cubit (State)
– Firebase SDK (Auth, Firestore)
– SharedPreferences (Local storage)
– PayPal REST API (Payments)
– get_it (Service locator / DI)
– Clean Architecture

##### Essential Elements
- Annotation of external dependencies (Firebase, PayPal)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Device/Browser
    Device["Device/Browser 📱💻"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Main["main.dart"]:::presentation
        Routes["on_generate_routes.dart"]:::presentation
        GlobalCubit["ProductsCubit"]:::presentation
        AuthCubit["LoginCubit"]:::presentation
        AuthView["LoginView"]:::presentation
        CheckoutCubit["AddOrderCubit"]:::presentation
        CheckoutView["CheckoutViews"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        CoreEntity["ProductEntity"]:::domain
        CoreRepoIntf["ProductRepo (interface)"]:::domain
        AuthEntity["UserEntity"]:::domain
        AuthRepoIntf["AuthRepo (interface)"]:::domain
        PayPalEntity["PayPalPaymentEntity"]:::domain
        CartRepoIntf["CartRepo (interface)"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        CoreModel["ProductModel"]:::data
        CoreRepoImpl["ProductRepoImpl"]:::data
        AuthModel["UserModel"]:::data
        AuthRepoImpl["AuthRepoImpl"]:::data
        OrderModel["OrderModel"]:::data
        CartRepoImpl["CartRepoImpl"]:::data
    end

    %% Core Services
    subgraph "Core Services"
        direction TB
        FirebaseAuthService["FirebaseAuthService"]:::core
        FirestoreService["FirestoreService"]:::core
        SharedPrefs["SharedPreferencesSingleton"]:::core
        DBService["DatabaseService"]:::core
        ServiceLocator["GetItService"]:::core
        BLoCObserver["CustomBlocObserver"]:::core
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        FirebaseAuthExt["Firebase Auth"]:::external
        FirestoreExt["Firestore DB"]:::external
        PayPalExt["PayPal REST API"]:::external
        SocialAuth["Google/Facebook/Apple"]:::external
    end

    %% Connections
    Device -->|"launches"| Main
    Main -->|"configures routes"| Routes
    Routes -->|"navigates to view"| AuthView
    Routes -->|"navigates to view"| CheckoutView
    Routes -->|"navigates to view"| GlobalCubit
    AuthView -->|"triggers event"| AuthCubit
    CheckoutView -->|"triggers event"| CheckoutCubit
    GlobalCubit -->|"triggers event"| GlobalCubit
    AuthCubit -->|"calls authRepo.authenticateUser()"| AuthRepoIntf
    CheckoutCubit -->|"calls cartRepo.addOrder() / paypalRepo.processPayment()"| CartRepoIntf
    GlobalCubit -->|"calls productRepo.fetchProducts()"| CoreRepoIntf

    CoreRepoIntf -->|"implemented by"| CoreRepoImpl
    AuthRepoIntf -->|"implemented by"| AuthRepoImpl
    CartRepoIntf -->|"implemented by"| CartRepoImpl

    CoreRepoImpl -->|"uses"| FirebaseAuthService
    AuthRepoImpl -->|"uses"| FirebaseAuthService
    CartRepoImpl -->|"uses"| FirestoreService
    CheckoutCubit -->|"calls PayPal API"| PayPalExt

    FirebaseAuthService -->|"SDK calls"| FirebaseAuthExt
    FirestoreService -->|"SDK calls"| FirestoreExt
    SharedPrefs -->|"local storage"| DBService

    ServiceLocator -->|"injects into"| AuthCubit
    ServiceLocator -->|"injects into"| GlobalCubit
    ServiceLocator -->|"injects into"| CheckoutCubit
    ServiceLocator -->|"provides"| FirebaseAuthService
    ServiceLocator -->|"provides"| FirestoreService

    %% Click Events
    click Main "https://github.com/medora0/fruit_hub/blob/main/lib/main.dart"
    click Routes "https://github.com/medora0/fruit_hub/blob/main/lib/core/helper_functions/on_generate_routes.dart"
    click GlobalCubit "https://github.com/medora0/fruit_hub/blob/main/lib/core/cubits/products_cubit/products_cubit.dart"
    click AuthCubit "https://github.com/medora0/fruit_hub/blob/main/lib/features/authentication/presentation/cubits/login_cubit/login_cubit.dart"
    click AuthView "https://github.com/medora0/fruit_hub/blob/main/lib/features/authentication/presentation/views/login_view.dart"
    click CheckoutCubit "https://github.com/medora0/fruit_hub/blob/main/lib/features/checkout/manager/add_order_cubit/add_order_cubit.dart"
    click CheckoutView "https://github.com/medora0/fruit_hub/blob/main/lib/features/checkout/presentation/views/checkout_views.dart"
    click CoreEntity "https://github.com/medora0/fruit_hub/blob/main/lib/core/entites/product_entity.dart"
    click CoreRepoIntf "https://github.com/medora0/fruit_hub/blob/main/lib/core/repos/products_repo/product_repo.dart"
    click AuthEntity "https://github.com/medora0/fruit_hub/blob/main/lib/features/authentication/domain/entites/user_entity.dart"
    click AuthRepoIntf "https://github.com/medora0/fruit_hub/blob/main/lib/features/authentication/domain/repository/auth_repo.dart"
    click PayPalEntity "https://github.com/medora0/fruit_hub/blob/main/lib/features/checkout/domain/entities/paypal_payment_entity/paypal_payment_entity.dart"
    click CartRepoIntf "https://github.com/medora0/fruit_hub/blob/main/lib/features/home/domain/repository/cart_repo.dart"
    click CoreModel "https://github.com/medora0/fruit_hub/blob/main/lib/core/models/product_model.dart"
    click CoreRepoImpl "https://github.com/medora0/fruit_hub/blob/main/lib/core/repos/products_repo/product_repo_impl.dart"
    click AuthModel "https://github.com/medora0/fruit_hub/blob/main/lib/features/authentication/data/models/user_model.dart"
    click AuthRepoImpl "https://github.com/medora0/fruit_hub/blob/main/lib/features/authentication/data/repository/auth_repo_impl.dart"
    click OrderModel "https://github.com/medora0/fruit_hub/blob/main/lib/features/checkout/data/models/order_model.dart"
    click CartRepoImpl "https://github.com/medora0/fruit_hub/blob/main/lib/features/home/data/repository/cart_repo_impl.dart"
    click FirebaseAuthService "https://github.com/medora0/fruit_hub/blob/main/lib/core/services/firebase_auth_service.dart"
    click FirestoreService "https://github.com/medora0/fruit_hub/blob/main/lib/core/services/firestore_service.dart"
    click SharedPrefs "https://github.com/medora0/fruit_hub/blob/main/lib/core/services/shared_preferences_singleton.dart"
    click ServiceLocator "https://github.com/medora0/fruit_hub/blob/main/lib/core/services/get_it_service.dart"
    click DBService "https://github.com/medora0/fruit_hub/blob/main/lib/core/services/database_service.dart"
    click BLoCObserver "https://github.com/medora0/fruit_hub/blob/main/lib/core/services/custom_bloc_observer.dart"

    %% Styles
    classDef presentation fill:#D6EAF8,stroke:#21618C,color:#1B4F72
    classDef domain fill:#D5F5E3,stroke:#196F3D,color:#145A32
    classDef data fill:#FAD7A0,stroke:#B9770E,color:#87481D
    classDef core fill:#E8DAEF,stroke:#7D3C98,color:#512E5F
    classDef external fill:#F5B7B1,stroke:#C0392B,color:#78281F
```
