# grandeclip/cutout_flutter architecture

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

- Interactive diagram: https://gitdiagram.com/grandeclip/cutout_flutter
- Repository: https://github.com/grandeclip/cutout_flutter

## Overview

##### Main Components

a. Flutter Layer
- Components:
- Cutout Plugin Interface
- Platform Interface
- Method Channel Implementation
- Model Handlers (SAM, U2Net)

b. Native Layer
- Components:
- C++ Implementation
- OpenCV Integration (v4.10.0)
- ONNXRuntime Integration (v1.15.1)

c. Platform-Specific Layer
- Split into:
- iOS Implementation
- Android Implementation

##### Component Relationships

a. Data Flow
- Image input flow from Flutter to Native layer
- Segmentation results flow back to Flutter
- Platform-specific communication through method channels

b. Model Integration
- Connections between:
- Model files (SAM, U2Net)
- ONNXRuntime executor
- OpenCV processing pipeline

##### Key Elements to Highlight

a. Core Processing Pipeline
- Image Input Handler
- Segmentation Model Processor
- Result Generator

b. Platform Bridge
- Method Channel Communication
- Native Code Binding
- Platform-Specific Implementations

##### Technical Details to Note

Annotations for:
- OpenCV version (4.10.0)
- ONNXRuntime version (1.15.1)
- Supported models (U2Net, SAM)
- Platform support (iOS, Android)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Flutter_Layer
        CPI["Cutout Plugin Interface"]:::flutter
        PI["Platform Interface"]:::flutter
        MC["Method Channel Implementation"]:::flutter
        subgraph Model_Handlers
            SAM_H["SAM Model Handler"]:::flutter
            U2NET_H["U2Net Model Handler"]:::flutter
        end
    end

    subgraph Native_Layer
        subgraph CPP_Implementation
            SAM_CPP["SAM C++ Implementation"]:::native
            U2NET_CPP["U2Net C++ Implementation"]:::native
        end
        OPENCV["OpenCV v4.10.0"]:::external
        ONNX["ONNXRuntime v1.15.1"]:::external
    end

    subgraph Platform_Layer
        IOS["iOS Implementation"]:::platform
        ANDROID["Android Implementation"]:::platform
    end

    subgraph Assets
        MODELS[("Model Files")]:::storage
    end

    %% Relationships
    CPI --> PI
    PI --> MC
    MC --> SAM_H
    MC --> U2NET_H
    SAM_H --> SAM_CPP
    U2NET_H --> U2NET_CPP
    SAM_CPP --> OPENCV
    U2NET_CPP --> OPENCV
    SAM_CPP --> ONNX
    U2NET_CPP --> ONNX
    SAM_CPP --> IOS
    SAM_CPP --> ANDROID
    U2NET_CPP --> IOS
    U2NET_CPP --> ANDROID
    MODELS --> SAM_CPP
    MODELS --> U2NET_CPP

    %% Click Events
    click CPI "https://github.com/grandeclip/cutout_flutter/blob/main/lib/cutout.dart"
    click PI "https://github.com/grandeclip/cutout_flutter/blob/main/lib/cutout_platform_interface.dart"
    click MC "https://github.com/grandeclip/cutout_flutter/blob/main/lib/cutout_method_channel.dart"
    click SAM_H "https://github.com/grandeclip/cutout_flutter/blob/main/lib/models/sam_model.dart"
    click U2NET_H "https://github.com/grandeclip/cutout_flutter/blob/main/lib/models/u2net_model.dart"
    click SAM_CPP "https://github.com/grandeclip/cutout_flutter/blob/main/ios/Classes/sam.cpp"
    click U2NET_CPP "https://github.com/grandeclip/cutout_flutter/blob/main/ios/Classes/u2net.cpp"
    click IOS "https://github.com/grandeclip/cutout_flutter/blob/main/ios/Classes/CutoutPlugin.swift"
    click ANDROID "https://github.com/grandeclip/cutout_flutter/blob/main/android/src/main/java/com/grandeclip/cutout/CutoutPlugin.java"
    click OPENCV "https://github.com/grandeclip/cutout_flutter/tree/main/include/opencv2/"
    click MODELS "https://github.com/grandeclip/cutout_flutter/tree/main/example/assets/models/"

    %% Styles
    classDef flutter fill:#3498db,stroke:#2980b9,color:white
    classDef native fill:#2ecc71,stroke:#27ae60,color:white
    classDef platform fill:#e67e22,stroke:#d35400,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef storage fill:#34495e,stroke:#2c3e50,color:white

    %% Legend
    subgraph Legend
        F[Flutter Components]:::flutter
        N[Native Components]:::native
        P[Platform Components]:::platform
        E[External Dependencies]:::external
        S[("Storage")]:::storage
    end
```
