# thenifemi/petshop architecture

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

- Interactive diagram: https://gitdiagram.com/thenifemi/petshop
- Repository: https://github.com/thenifemi/petshop

## Overview

##### Main components
- Flutter Mobile Application (Frontend)
- Built using Flutter and organized under the “lib” directory.
- Contains multiple layers: models (data and notifiers), services (e.g., authentication, product service, push notifications, user management), screens (login, registration, home, product details, checkout, etc.), widgets, and utilities.
- Uses Provider architecture for state management.

- Platform-Specific Projects:
- Android: All native Android files under the “android” directory.
- iOS: The “ios” directory with native iOS configurations.

- Backend Services (Cloud & External APIs):
- Firebase Authentication: Used for user authentication (FirebaseAuth).
- Firebase Cloud Firestore: Acts as the main database.
- Firebase Cloud Functions: Located in the “functions” folder; used for backend logic.
- Google Places API: For location reading service.
- External storage for images: Store images (fetched from Amazon).

##### Detail the relationships and data flow
- The Flutter app (client) communicates directly with Firebase for authentication and database operations.
- The provider notifiers and services in the “lib/model” layer wrap these Firebase and external API interactions to update the UI accordingly.
- The mobile UI (widgets and screens) uses the provider pattern to reflect state changes coming from backend service calls.
- Cloud Functions provide backend logic and may interact with Firestore and other external services.
- Native platform configurations for Android and iOS contain integration points (e.g., google-services.json for Android, GoogleService-Info.plist for iOS) to bridge Flutter with native functionalities.

##### Architectural patterns and design principles
- Provider Architecture: Central to state management, with each “notifier” representing a slice of the app’s state.
- Clean separation of concerns: Models (data and services) are separated from UI (screens and widgets) and configuration.
- Use of third-party services (Firebase, Google Places API, Amazon imaging) is prominently integrated within service layers.
- Modular design with clear separation between UI, business logic (services), and data models.

##### Relevant technologies and frameworks
- Flutter (Dart language) for building the UI.
- Firebase (FirebaseAuth, Cloud Firestore, Cloud Functions) for backend services.
- Provider package for state management.
- Google Places API for location data.
- Native configurations for Android and iOS to handle platform-specific features.

##### Elements
- UI Components: Screens and Widgets.
- State Management: Providers/Notifiers.
- Business Logic/Services: Authentication service, Products service, Push notifications service, etc.
- Data Models: Classes defined for Products, Orders, User Data, etc.

- Backend Components:
- Firebase Auth and Firestore as cloud services.
- Cloud Functions (depicted as an independent service that interacts with Firestore and possibly triggers notifications).

- External APIs & Services:
- Google Places API for location.
- Amazon (or external storage) for images.

- Data and event flow from the Flutter UI to the Providers and then to the Firebase backend.
- Communication from Firebase Cloud Functions to Firestore and possibly to the mobile client.
- Integration flows for external APIs (e.g., location or image fetching).

- Rectangles for system components.
- Ovals or circles for data stores (such as Firebase Firestore).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    A["Flutter Mobile Application"]:::frontend
    subgraph "Frontend Layers"
        B["UI Components - Screens"]:::ui
        C["UI Components - Widgets"]:::ui
        D["State Management (Provider)"]:::state
        F["Data Models"]:::data
        subgraph "Business Logic / Services"
            E1["Authentication Service"]:::service
            E2["Product Service"]:::service
            E3["Push Notification Service"]:::service
            E4["User Management Service"]:::service
        end
    end

    %% Platform-specific projects
    subgraph "Platform Projects"
        G["Android Project"]:::platform
        H["iOS Project"]:::platform
        I["Android Firebase Config"]:::config
        J["iOS Firebase Config"]:::config
    end

    %% Backend and External Services
    subgraph "Backend Services"
        K["Firebase Authentication"]:::backend
        L["Cloud Firestore"]:::backend
        M["Cloud Functions"]:::backend
        N["Google Places API"]:::external
        O["Amazon Imaging"]:::external
        P["Firebase Project Config"]:::config
    end

    %% Connections within Frontend
    A --> B
    A --> C
    A --> D
    A --> F
    D --> E1
    D --> E2
    D --> E3
    D --> E4

    %% Connections between Business Logic and Backend
    E1 -->|"authenticates"| K
    E1 -->|"accesses"| L
    E2 -->|"fetchesProducts"| L
    E2 -->|"readsLocation"| N
    E2 -->|"fetchesImages"| O
    E3 -->|"sendsPush"| L
    E4 -->|"managesUsers"| L

    %% Cloud Functions updating Providers and Firestore
    M -->|"updatesState"| D
    M -->|"writesData"| L

    %% Firebase Project Config supplying Firebase services
    P --> K
    P --> L
    P --> M

    %% Platform Projects integration
    A --> G
    A --> H
    G --> I
    H --> J

    %% Click Events for Frontend components
    click A "https://github.com/thenifemi/petshop/tree/master/lib/"
    click B "https://github.com/thenifemi/petshop/tree/master/lib/screens/"
    click C "https://github.com/thenifemi/petshop/tree/master/lib/widgets/"
    click D "https://github.com/thenifemi/petshop/tree/master/lib/model/notifiers/"
    click F "https://github.com/thenifemi/petshop/tree/master/lib/model/data/"
    
    %% Click Events for Business Logic / Services
    click E1 "https://github.com/thenifemi/petshop/blob/master/lib/model/services/auth_service.dart"
    click E2 "https://github.com/thenifemi/petshop/blob/master/lib/model/services/Product_service.dart"
    click E3 "https://github.com/thenifemi/petshop/blob/master/lib/model/services/pushNotification_service.dart"
    click E4 "https://github.com/thenifemi/petshop/blob/master/lib/model/services/user_management.dart"
    
    %% Click Events for Platform Projects
    click G "https://github.com/thenifemi/petshop/tree/master/android/"
    click H "https://github.com/thenifemi/petshop/tree/master/ios/"
    click I "https://github.com/thenifemi/petshop/blob/master/android/app/src/main/AndroidManifest.xml"
    click J "https://github.com/thenifemi/petshop/blob/master/ios/Runner/GoogleService-Info.plist"
    
    %% Click Events for Backend Services
    click M "https://github.com/thenifemi/petshop/tree/master/functions/"
    click P "https://github.com/thenifemi/petshop/blob/master/.firebaserc"

    %% Styling classes
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef ui fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef state fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef data fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef service fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef platform fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef config fill:#F08080,stroke:#000,stroke-width:2px;
```
