# konstanius/native_video_utils architecture

> Architecture diagram of the GitHub repository konstanius/native_video_utils, 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/konstanius/native_video_utils
- Repository: https://github.com/konstanius/native_video_utils

## Overview

##### Project Type and Purpose
- This is a Flutter plugin designed to offer native video manipulation utilities by bypassing FFmpeg-Kit. Its functionality relies on native APIs (Android’s MediaMuxer and iOS’s AVFoundation) to trim and rotate videos, with plans to add additional features.
- The plugin abstracts native functionality behind a Dart interface so that Flutter apps can perform video editing operations with lower overhead.

##### Identifying Main Components
a. Flutter Layer (Dart Code):
- Located primarily in the top-level lib directory (files like native_video_utils.dart, native_video_utils_method_channel.dart, and native_video_utils_platform_interface.dart) that provide the public API for the plugin.
- Error handling is achieved via custom exceptions defined in lib/exceptions.dart and others.
b. Platform-Specific Implementations:
- Android:
- The Android-specific code is in the android/ directory. For example, NativeVideoUtilsPlugin.java and VideoUtils.java manage the native operations using Android APIs.
- Test files under android/src/test show how these functionalities are verified.
- iOS:
- The iOS-specific code is found in the ios/ directory, with NativeVideoUtilsPlugin.swift and VideoUtils.swift that interface with Apple’s AVFoundation.
- Also, a podspec (native_video_utils.podspec) shows this package’s distribution for iOS.
c. Example Application:
- The example/ directory provides a full Flutter sample that demonstrates how to integrate and test the plugin. This include the example Flutter UI (example/lib/main.dart) and respective platform integration in its android and ios subdirectories.
d. Testing and Integration:
- There’s an integration_test directory within the example that contains Flutter integration tests, solidifying the end-to-end system interaction.

##### Relationships and Interactions
- The Flutter (Dart) API serves as the front-facing interface that Flutter developers interact with. When an operation (like trimming or rotating a video) is invoked, it calls through a method channel.
- The Method Channel bridges the Dart code with the native layers (both Android and iOS).
- In the native layers:
- For Android, the Java classes implement the video functionality using native libraries such as MediaMuxer.
- For iOS, Swift classes use AVFoundation to perform video manipulation.
- Once the native operation is completed, results (or errors) flow back through the method channel to the Dart layer.

##### Architectural Patterns and Design Principles
- The plugin design leverages a Platform Interface pattern where the common Dart API delegates processing to middleware (Method Channels) that interact with platform-specific implementations.
- It also emphasizes low dependency and lightweight design by avoiding bulky libraries (as emphasized in the README).
- The separation of concerns is clear: the core plugin API in Dart is isolated from native implementations, which follow the idioms and best practices of their respective platforms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flutter Layer
    subgraph "Flutter Layer"
        ExampleApp["Example Flutter App"]:::flutter
        FlutterAPI["Flutter Plugin API"]:::flutter
        MethodChannel["Method Channel"]:::method
    end

    %% Native Layer
    subgraph "Native Layer"
        AndroidNative["Android Native Implementation"]:::android
        iOSNative["iOS Native Implementation"]:::ios
        MediaMuxer["MediaMuxer (Android)"]:::external
        AVFoundation["AVFoundation (iOS)"]:::external
        iOSPodspec["iOS Distribution (Podspec)"]:::ios
    end

    %% Testing Layer
    subgraph "Testing"
        AndroidTest["Android Testing"]:::android
        IntegrationTest["Integration Testing"]:::flutter
    end

    %% Connections between Flutter Layer and Native Layer
    ExampleApp -->|"invokes"| FlutterAPI
    FlutterAPI -->|"via"| MethodChannel
    MethodChannel -->|"channel"| AndroidNative
    MethodChannel -->|"channel"| iOSNative

    %% Native implementations using native libraries
    AndroidNative -->|"uses"| MediaMuxer
    iOSNative -->|"uses"| AVFoundation
    iOSPodspec -.->|"describes"| iOSNative

    %% Error handling feedback from native to Dart
    AndroidNative -.->|"errors"| FlutterAPI
    iOSNative -.->|"errors"| FlutterAPI

    %% Testing connections
    AndroidTest -->|"tests"| AndroidNative
    IntegrationTest -->|"integration"| ExampleApp

    %% Click Events for Flutter Plugin API files
    click FlutterAPI "https://github.com/konstanius/native_video_utils/blob/master/lib/native_video_utils.dart"
    click FlutterAPI "https://github.com/konstanius/native_video_utils/blob/master/lib/native_video_utils_method_channel.dart"
    click FlutterAPI "https://github.com/konstanius/native_video_utils/blob/master/lib/native_video_utils_platform_interface.dart"
    click FlutterAPI "https://github.com/konstanius/native_video_utils/blob/master/lib/exceptions.dart"
    click FlutterAPI "https://github.com/konstanius/native_video_utils/blob/master/lib/enums.dart"

    %% Click Events for Android Native Implementation files
    click AndroidNative "https://github.com/konstanius/native_video_utils/blob/master/android/src/main/java/me/konstanius/native_video_utils/NativeVideoUtilsPlugin.java"
    click AndroidNative "https://github.com/konstanius/native_video_utils/blob/master/android/src/main/java/me/konstanius/native_video_utils/VideoUtils.java"

    %% Click Event for Android Testing
    click AndroidTest "https://github.com/konstanius/native_video_utils/blob/master/android/src/test/java/me/konstanius/native_video_utils/NativeVideoUtilsPluginTest.java"

    %% Click Events for iOS Native Implementation files
    click iOSNative "https://github.com/konstanius/native_video_utils/blob/master/ios/Classes/NativeVideoUtilsPlugin.swift"
    click iOSNative "https://github.com/konstanius/native_video_utils/blob/master/ios/Classes/VideoUtils.swift"

    %% Click Event for iOS Distribution podspec
    click iOSPodspec "https://github.com/konstanius/native_video_utils/blob/master/ios/native_video_utils.podspec"

    %% Click Event for Example Flutter App
    click ExampleApp "https://github.com/konstanius/native_video_utils/blob/master/example/lib/main.dart"

    %% Click Event for Integration Testing
    click IntegrationTest "https://github.com/konstanius/native_video_utils/blob/master/example/integration_test/plugin_integration_test.dart"

    %% Styles
    classDef flutter fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef android fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef ios fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef method fill:#F5CBA7,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#F5EEF8,stroke:#6C3483,stroke-width:2px;
```
