# bizz84/flutter-firebase-masterclass architecture

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

- Interactive diagram: https://gitdiagram.com/bizz84/flutter-firebase-masterclass
- Repository: https://github.com/bizz84/flutter-firebase-masterclass

## Overview

##### Main components
- Frontend Flutter App: Represented by the "ecommerce_app/lib" directory. This includes multiple platforms (Android, iOS, macOS, Web) with their native subdirectories and the shared Dart code for business logic, UI, state management, and routing.
- Feature Modules: Within lib/src/features, each folder (e.g., authentication, cart, checkout, orders, products, reviews, and products_admin) should be modeled as separate components. Each of these modules is further divided into presentation, application layer, data layer, and domain entities.
- Backend Services:
- Firebase – This includes Firestore, Firebase Authentication, Firestore rules, and indexes (see ecommerce_app/firestore.indexes.json and firestore.rules).
- Firebase Cloud Functions – Found in the "ecommerce_app/functions" folder, these functions (admin.ts, index.ts, stripe.ts, etc.) offer server-side logic and integrations.
- External Integrations:
- Stripe – Integrated via an environment (.env) file and exposed through generated code (env.g.dart). This handles payment processing.
- Additional Firebase setup files (e.g., firebase_options.dart) that configure the app.
- Testing Infrastructure: Highlight the “test” folder that includes integration tests, unit tests for each feature, and golden tests.
- Deployment/CI: Indicate that GitHub workflows (in .github/workflows) are used to run tests and CI/CD pipelines.

##### Relationships and interactions
- The Flutter App (client) communicates with Firebase (authentication, database, cloud functions) using the Firebase SDK.
- Feature modules interact internally using controllers and services (e.g., for sign-in, product listings, cart management, checkout processing).
- Cloud Functions provide a layer between the client and external services like Stripe. For instance, when a checkout is initiated, the client calls a cloud function which in turn interacts with Stripe’s API.
- Data flows from user interactions in the frontend (e.g., add to cart, sign in) to updates in Firestore, and vice versa.
- Build-time generated files (using build_runner) facilitate dependency injection and ensure that generated *.g.dart files are synchronized with their respective modules.

##### Architectural Patterns and Design Principles
- Modular Architecture: Each feature (authentication, cart, etc.) is encapsulated into its own module with clear separation of concerns.
- Layered/DLL Architecture: Separating domain, data, application (business logic), and presentation layers leads to a more maintainable codebase.
- Cross-Platform Development: Emphasize that the frontend is a Flutter project targeting multiple platforms (Android, iOS, macOS, web).
- CI/CD Integration: The existence of .github workflows indicates automated testing and deployment practices.
- External Service Abstraction: Notice the provision for environment-specific configurations (via Envied for Stripe and flutterfire CLI for Firebase) that ensure secure and scalable integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        FL["Flutter Frontend"]:::client
    end

    %% Feature Modules
    subgraph "Feature Modules"
        FM1["Authentication"]:::feature
        FM2["Cart"]:::feature
        FM3["Checkout"]:::feature
        FM4["Orders"]:::feature
        FM5["Products"]:::feature
        FM6["Reviews"]:::feature
        FM7["Products Admin"]:::feature
    end

    %% Backend Services
    subgraph "Backend Services"
        FB1["Firebase Authentication"]:::backend
        FB2["Firestore Database"]:::backend
        FB3["Firestore Rules"]:::backend
        FB4["Firestore Indexes"]:::backend
        FB5["Firebase Cloud Functions"]:::backend
    end

    %% External Integrations
    subgraph "External Integrations"
        EX1["Stripe Payment Gateway"]:::external
    end

    %% DevOps & Testing
    subgraph "DevOps & Testing"
        DT1["Testing Infrastructure"]:::devops
        DT2["Deployment/CI"]:::devops
    end

    %% Connections from Client Layer to Feature Modules
    FL -->|"invokes"| FM1
    FL -->|"invokes"| FM2
    FL -->|"invokes"| FM3
    FL -->|"invokes"| FM4
    FL -->|"invokes"| FM5
    FL -->|"invokes"| FM6
    FL -->|"invokes"| FM7

    %% Connections from Client Layer to Backend Services
    FL -->|"authCalls"| FB1
    FL -->|"dataUpdates"| FB2
    FL -->|"serverCalls"| FB5

    %% Feature Module (Authentication) interacting with Firebase Authentication
    FM1 -->|"uses"| FB1

    %% Checkout module initiating cloud functions for payment
    FM3 -->|"initCheckout"| FB5

    %% Cloud Functions interacting with external Stripe gateway
    FB5 -->|"processPayment"| EX1

    %% DevOps pipeline relationship (symbolic)
    DT1 -->|"triggers"| DT2

    %% Click Events
    click FL "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib"
    click FM1 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/authentication"
    click FM2 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/cart"
    click FM3 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/checkout"
    click FM4 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/orders"
    click FM5 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/products"
    click FM6 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/reviews"
    click FM7 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/lib/src/features/products_admin"
    click FB3 "https://github.com/bizz84/flutter-firebase-masterclass/blob/main/ecommerce_app/firestore.rules"
    click FB4 "https://github.com/bizz84/flutter-firebase-masterclass/blob/main/ecommerce_app/firestore.indexes.json"
    click FB5 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/functions"
    click EX1 "https://github.com/bizz84/flutter-firebase-masterclass/blob/main/ecommerce_app/lib/env.dart"
    click EX1 "https://github.com/bizz84/flutter-firebase-masterclass/blob/main/ecommerce_app/lib/src/app_bootstrap_stripe.dart"
    click DT1 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/test"
    click DT2 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/.github/workflows"
    click DT2 "https://github.com/bizz84/flutter-firebase-masterclass/tree/main/ecommerce_app/.github/workflows"

    %% Styles
    classDef client fill:#F9E79F,stroke:#A67C00,stroke-width:2px;
    classDef feature fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    classDef backend fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef devops fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
