# shaqian/flutter_realtime_detection architecture

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

- Interactive diagram: https://gitdiagram.com/shaqian/flutter_realtime_detection
- Repository: https://github.com/shaqian/flutter_realtime_detection

## Overview

##### Project Type and Purpose
- The project is a mobile application built with Flutter, targeting both Android and iOS platforms.
- Its core purpose is real-time object detection and related computer vision tasks processed locally on the device.
- It integrates with device cameras and uses TensorFlow Lite models (stored in the assets directory) to perform ML inference.

##### File Structure
- Top-level directories include:
- “android” and “ios”: These contain platform-specific native configurations and build files (e.g., AndroidManifest.xml, Xcode project files) to support Flutter’s compilation and deployment.
- “lib”: This is the heart of the Flutter application and includes key Dart files such as main.dart, camera.dart, home.dart, and models.dart.
- “assets”: Holds pre-trained ML models and their associated label files.
- “test”: Contains tests (e.g., widget_test.dart) for ensuring functionality.
- The presence of configuration files (pubspec.yaml, Gradle files, Podfile) indicates that dependencies (camera and tflite plugins) and asset management are configured through these scripts.

##### Extract Key Architectural Insights from the README
- The README explicitly mentions using the camera and TFLite plugins.
- It details the three main ML functionalities: Image Classification (MobileNet), Object Detection (SSD MobileNet and Yolov2 Tiny), and Pose Estimation (PoseNet).

##### Components
a. Main Components:
- Flutter Application (UI Layer): Contains widgets, pages, and routing logic found in files like main.dart and home.dart.
- Camera Module: Represented in camera.dart, this module interfaces with the device’s camera using the camera plugin.
- ML Processing Module: Utilizes the TFLite plugin to load TensorFlow Lite models stored in assets. This module processes captured image frames.
- Model Repository: Assets directory containing different pre-trained models and their metadata.
- Testing and Auxiliary Components: Although not central to the design, the existence of a “test” directory implies unit and widget tests.

b. Relationships & Interactions:
- The Flutter UI initiates requests (via UI interactions) to the camera module to capture images.
- Captured image data is passed to the ML Processing Module through the TFLite plugin.
- The ML Processing module loads the appropriate model (classification, detection, or pose estimation) from the assets repository.
- Processed results (detected objects, classified images, or pose outputs) are returned to the UI for display and further interaction.
- Underlying native layers (Android/iOS) facilitate camera access and optimized ML processing on-device.

c. Architectural Patterns and Principles:
- Separation of concerns: Clear separation between UI, data acquisition (camera), and ML processing.
- Cross-platform development: Using Flutter to write once and deploy natively on Android and iOS.
- Modular design: With distinct modules/files for camera operations, model management, and UI functionality.
- Real-time processing: Designed to handle continuous data streams (camera feed) and process them using optimized ML inference.

d. Relevant Technologies:
- Flutter for UI and cross-platform application logic.
- TFLite plugin for on-device ML inference.
- Camera plugin for capturing device camera input.
- TensorFlow Lite models for image classification, object detection, and pose estimation.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Flutter Application Layer
    subgraph "Flutter Application Layer"
        FlutterUI("Flutter UI"):::ui
        CameraModule("Camera Module"):::camera
        MLModule("ML Processing Module"):::ml
    end

    %% Native Platforms
    subgraph "Native Platforms"
        AndroidNative("Android Native Layer"):::native
        iOSNative("iOS Native Layer"):::native
    end

    %% External Repository and Testing
    ModelRepo("Model Repository"):::repo
    subgraph "Testing & Auxiliary"
        Testing("Testing Suite"):::test
    end

    %% Relationships within Flutter Application Layer
    FlutterUI -->|"captures"| CameraModule
    CameraModule -->|"feeds_image"| MLModule
    MLModule -->|"returns_results"| FlutterUI
    MLModule -->|"loads_models"| ModelRepo

    %% Interactions with Native Layers
    FlutterUI -->|"access_native"| AndroidNative
    FlutterUI -->|"access_native"| iOSNative
    CameraModule -->|"utilizes_native"| AndroidNative
    CameraModule -->|"utilizes_native"| iOSNative

    %% Testing Relationships
    Testing -->|"tests_UI"| FlutterUI
    Testing -->|"tests_modules"| CameraModule
    Testing -->|"tests_modules"| MLModule

    %% Click Events
    click FlutterUI "https://github.com/shaqian/flutter_realtime_detection/blob/master/lib/main.dart"
    click CameraModule "https://github.com/shaqian/flutter_realtime_detection/blob/master/lib/camera.dart"
    click MLModule "https://github.com/shaqian/flutter_realtime_detection/blob/master/lib/models.dart"
    click ModelRepo "https://github.com/shaqian/flutter_realtime_detection/tree/master/assets/"
    click AndroidNative "https://github.com/shaqian/flutter_realtime_detection/tree/master/android/"
    click iOSNative "https://github.com/shaqian/flutter_realtime_detection/tree/master/ios/"
    click Testing "https://github.com/shaqian/flutter_realtime_detection/tree/master/test/"

    %% Styling
    classDef ui fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef camera fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef ml fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef native fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef repo fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef test fill:#E0FFFF,stroke:#000,stroke-width:2px;
```
