# bizz84/flutter_ship_app architecture

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

- Interactive diagram: https://gitdiagram.com/bizz84/flutter_ship_app
- Repository: https://github.com/bizz84/flutter_ship_app

## Overview

##### Project Type & Purpose
- This is a Flutter-based companion mobile and web application designed as part of a course on “Flutter in production.”
- The purpose is to demonstrate production-level practices such as handling multiple flavors (dev, stg, prod), integrating Firebase (for analytics and remote config), Sentry, Mixpanel, and proper error reporting along with components for in-app reviews and forced updates.
- The project showcases a full-stack client application that spans multiple deployment targets (Android, iOS, and Web) with clear environment configurations.

##### Analyzing the File Structure
- Top-level directories include:
- Android, iOS, and Web: Containing platform-specific configurations, assets, and build settings.
- lib: The core source code, subdivided into folders like src (containing subdirectories for presentation, data, domain, and monitoring), app_routes, and environment configurations.
- Assets and maestro: Additional assets and scripts (for screenshots, for instance).
- The flavor-specific files (e.g., main_dev.dart, main_stg.dart, main_prod.dart) and environment directories (lib/env) indicate support for separate configurations.
- Integration points for external services are evident through the usage of Firebase, Sentry, Mixpanel, and a local SQLite database via Drift.

A. Application Layers:
- Presentation Layer:
- Represented by the UI components/screens within lib/src/presentation (apps list screen, create/edit screens, settings, etc.).

- Domain Layer:
- Contains business logic and domain models (see lib/src/domain like app, epic, task).

- Data Layer:
- Includes local database management using Drift (lib/src/data), API clients, and remote configuration.
- Separate modules for database CRUD operations, connection handling (native, web, unsupported), and external APIs (like gist_client) should be noted here.

- Monitoring & Analytics:
- This module encompasses ab_testing, analytics clients (Firebase Analytics, Mixpanel, custom logger interceptors), and error logging (Sentry integration).
- It shows how errors and usage statistics are collected and transmitted.

- Utility & Configuration:
- Mechanism that loads .env files and uses flutterfire-config.

B. Platform-Specific Components:
- Mobile Platforms:
- Web Platform:
- Web folder which includes the Drift web worker, manifests, and index.html to indicate the web target.

C. External Services & Integrations:
- Firebase:
- Firebase analytics and remote config integration.
- Sentry & Mixpanel:
- As external monitoring and analytics services.
- That configuration for these is provided through environment variables (.env files).
- App Store / In-App Review:
- Identifiers for store configuration and integration of packages such as force_update_helper and in_app_review.

D. Flavors and Environment Configuration:
- That these configurations affect everything from Firebase and API endpoints to Sentry/Mixpanel keys.

E. Build and CI/CD Pipeline:
- Fastlane (for iOS/Android) and any automated tasks (like screenshot scripts in the maestro directory).

##### Relationships & Data Flow
- From user interaction in the Presentation layer to the Domain layer for business logic processing.
- From the Domain to the Data layer where local storage (Drift) and API calls reside.
- From the Data layer to external services (Firebase, Sentry, Mixpanel) via analytics and error reporting components.
- That environment configuration (.env and flavor files) affects all modules by providing configuration keys.
- Clearly label interactions such as “User Actions”, “Business Logic Processing”, “Data Persistence”, “Remote Config Fetch”, “Analytics Logging”, and “Error Reporting”.

##### Final Recommendations
- Be as detailed as possible in integrating every major aspect of the codebase: from UI components to data management, environment controls, and external integrations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level Entry Points
    User("User"):::internal
    subgraph "Flavors and Environment Configuration"
        MainDev("Main Dev"):::flavor
        MainStg("Main Stg"):::flavor
        MainProd("Main Prod"):::flavor
        EnvFiles("Env Files"):::flavor
    end

    %% Internal Application Layers
    subgraph "Application Layers"
        subgraph "Presentation Layer"
            PL_Screens("Screens (lib/src/presentation)"):::internal
            PL_Common("Common Widgets (lib/src/common_widgets)"):::internal
        end
        Domain("Domain Layer (Business Logic - lib/src/domain)"):::internal
        Data("Data Layer (lib/src/data)"):::internal
        Monitoring("Monitoring & Analytics (lib/src/monitoring)"):::internal
        Utils("Utils (lib/src/utils)"):::internal
    end

    %% External Services Group
    subgraph "External Services & Integrations"
        Firebase("Firebase"):::external
        Sentry("Sentry"):::external
        Mixpanel("Mixpanel"):::external
        InApp("In-App Review"):::external
    end

    %% Platform Specific Components
    subgraph "Platform Components"
        Android("Android Platform"):::platform
        iOS("iOS Platform"):::platform
        Web("Web Platform"):::platform
    end

    %% CI/CD and Build Scripts
    subgraph "CI/CD & Build Scripts"
        CICD("GitHub Workflows"):::build
        Makefile_Node("Makefile"):::build
        Android_Fastlane("Android Fastlane"):::build
        iOS_Fastlane("iOS Fastlane"):::build
    end

    %% Connections for Entry Points
    MainDev -->|"entrypoint"| User
    MainStg -->|"entrypoint"| User
    MainProd -->|"entrypoint"| User
    EnvFiles -->|"loads config"| Utils

    %% User Interaction Flow
    User -->|"triggers"| PL_Screens
    PL_Screens -->|"userActions"| Domain
    PL_Common --> Domain

    Domain -->|"processes"| Data
    Data -->|"persists data"| Monitoring
    Monitoring -->|"logs/analytics"| Firebase
    Monitoring -->|"logs/analytics"| Sentry
    Monitoring -->|"logs/analytics"| Mixpanel
    Monitoring -->|"triggers review"| InApp

    %% Configuration influence across layers
    Utils ---|"configures"| Domain
    Utils ---|"configures"| Data
    Utils ---|"configures"| Monitoring

    %% CI/CD flow to Platforms
    CICD --> Android
    CICD --> iOS
    CICD --> Web
    Makefile_Node --> Android
    Makefile_Node --> iOS
    Makefile_Node --> Web
    Android_Fastlane --> Android
    iOS_Fastlane --> iOS

    %% Class Definitions (Colours)
    classDef internal fill:#CDE6FF,stroke:#1F6FAA,stroke-width:2px;
    classDef platform fill:#CFFFD3,stroke:#2E8B57,stroke-width:2px;
    classDef external fill:#FFD1DC,stroke:#FF69B4,stroke-width:2px;
    classDef build fill:#FFF2CC,stroke:#D4AC0D,stroke-width:2px;
    classDef flavor fill:#E6CCFF,stroke:#8A2BE2,stroke-width:2px;

    %% Click Events for Component Mapping
    click PL_Screens "https://github.com/bizz84/flutter_ship_app/tree/main/lib/src/presentation"
    click PL_Common "https://github.com/bizz84/flutter_ship_app/tree/main/lib/src/common_widgets"
    click Domain "https://github.com/bizz84/flutter_ship_app/tree/main/lib/src/domain"
    click Data "https://github.com/bizz84/flutter_ship_app/tree/main/lib/src/data"
    click Monitoring "https://github.com/bizz84/flutter_ship_app/tree/main/lib/src/monitoring"
    click Utils "https://github.com/bizz84/flutter_ship_app/tree/main/lib/src/utils"
    click EnvFiles "https://github.com/bizz84/flutter_ship_app/tree/main/lib/env"
    click MainDev "https://github.com/bizz84/flutter_ship_app/blob/main/lib/main_dev.dart"
    click MainStg "https://github.com/bizz84/flutter_ship_app/blob/main/lib/main_stg.dart"
    click MainProd "https://github.com/bizz84/flutter_ship_app/blob/main/lib/main_prod.dart"
    click Android "https://github.com/bizz84/flutter_ship_app/tree/main/android"
    click iOS "https://github.com/bizz84/flutter_ship_app/tree/main/ios"
    click Web "https://github.com/bizz84/flutter_ship_app/tree/main/web"
    click CICD "https://github.com/bizz84/flutter_ship_app/tree/main/.github/workflows"
    click Makefile_Node "https://github.com/bizz84/flutter_ship_app/tree/main/Makefile"
    click Android_Fastlane "https://github.com/bizz84/flutter_ship_app/tree/main/android/fastlane"
    click iOS_Fastlane "https://github.com/bizz84/flutter_ship_app/tree/main/ios/fastlane"
```
