# luongcuong244/image_downloader architecture

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

## Overview

This project is a Flutter plugin designed to handle image (and movie) downloads on both Android and iOS. Its primary purpose is to provide a unified API from Dart that leverages platform-native functionality to download files from the Internet and save them—retaining essential metadata like Exif and GPS information—to either the mobile device’s photo library (iOS) or a specified directory (Android). In addition, the project includes an example app showing how to utilize the plugin on both platforms.

##### Main Components
- Flutter/Dart Layer: Represented by the Dart API in the “lib” folder and the example project under “example/lib”. This layer is where client code interacts with the plugin’s functions such as downloadImage(), findPath(), open(), etc.
- Plugin Bridge (Platform Channel): This abstraction connects the Dart code to the native implementations. Although it isn’t a separate folder by name, it is an implied layer using Flutter’s platform channel mechanism.
- Android Native Implementation: Found in the “android” folder (especially under “android/src/main/kotlin/com/ko2ic/imagedownloader”), this contains native Kotlin classes like ImageDownloaderPlugin.kt and FileProvider.kt, as well as Android-specific configurations (e.g., AndroidManifest.xml, Gradle files, and XML resource for provider_paths.xml in the example project). This layer interacts with Android OS services—file systems, external storage directories, and permissions.
- iOS Native Implementation: Contained in the “ios” folder (and additionally in “example/ios”), with Objective-C/Swift code in “ios/Classes” (e.g., ImageDownloaderPlugin.h/.m, SwiftImageDownloaderPlugin.swift). This part handles interactions with iOS-specific APIs such as the Photo Library and preview functionality (using UIDocumentInteractionController).
- Underlying OS Services: These are the native platform services which include:
- On Android: File storage, permission management, and Intent-based file preview.
- On iOS: Photo Library access, metadata handling, and file preview implementations.

##### Relationships and Interactions
- The Platform Channel then dispatches these requests to their respective native implementations.
- On Android, the native layer communicates directly with Android’s system services (e.g., downloads, file storage, file provider for sharing files).
- On iOS, the native layer interfaces with system-level components like the Photo Library and UIDocumentInteractionController for previewing files.
- The example application illustrates usage of the plugin, so you might want to add a separate “Example App” component that consumes the plugin’s API.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Notice how the Flutter plugin cleanly separates cross-platform (Dart) logic from platform-specific implementations.
- Plugin Architecture: Utilizes Flutter’s platform channels to bridge between Dart and native code.
- Modularity and Extensibility: With separate directories for each platform (android and ios), it’s easy to update or extend the native logic independently.
- Configuration and Platform-Specific Customizations: The configuration files (e.g., AndroidManifest.xml, Gradle build files, iOS Info.plist) highlight how the plugin is configured for each platform regarding permissions and provider details.

##### Relevant Technologies and Frameworks
- Flutter and Dart: Core for the cross-platform API.
- Kotlin for Android: Used for the native part of the plugin.
- Swift/Objective-C for iOS: Used in the iOS native implementation.
- Android FileProvider: Critical for enabling file sharing and preview on Android.
- iOS UIDocumentInteractionController: For preview functionality within iOS.
- Gradle and Xcode: For build and project management of native components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Dart API (lib/)"]:::flutter
    B["Example Application"]:::flutter
    C["Platform Channel"]:::channel

    A -->|"calls"| C
    B -->|"uses"| A

    subgraph "Android Native Implementation (Kotlin)"
        direction TB
        D1["ImageDownloaderPlugin.kt"]:::nativeAndroid
        D2["FileProvider.kt"]:::nativeAndroid
        D3["AndroidManifest.xml"]:::nativeAndroid
        D4["provider_paths.xml"]:::nativeAndroid
    end

    subgraph "iOS Native Implementation (Objective-C/Swift)"
        direction TB
        I1["ImageDownloaderPlugin.h"]:::nativeiOS
        I2["ImageDownloaderPlugin.m"]:::nativeiOS
        I3["SwiftImageDownloaderPlugin.swift"]:::nativeiOS
        I4["MetaDataUtils.swift"]:::nativeiOS
        I5["Info.plist"]:::nativeiOS
        I6["image_downloader.podspec"]:::nativeiOS
    end

    FA["Android OS Services (FileSystem,Permissions,FileProvider)"]:::os
    FB["iOS OS Services (PhotoLibrary,UIDocumentInteractionController)"]:::os

    C -->|"routes to"| D1
    C -->|"routes to"| I1

    D1 -->|"invokes"| FA
    I1 -->|"invokes"| FB

    classDef flutter fill:#f4f4f9,stroke:#333,stroke-width:2px;
    classDef channel fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef nativeAndroid fill:#d0f0c0,stroke:#333,stroke-width:2px;
    classDef nativeiOS fill:#c0dff0,stroke:#333,stroke-width:2px;
    classDef os fill:#ffd1dc,stroke:#333,stroke-width:2px;

    click A "https://github.com/luongcuong244/image_downloader/blob/master/lib/image_downloader.dart"
    click B "https://github.com/luongcuong244/image_downloader/blob/master/example/lib/main.dart"
    click D1 "https://github.com/luongcuong244/image_downloader/blob/master/android/src/main/kotlin/com/ko2ic/imagedownloader/ImageDownloaderPlugin.kt"
    click D2 "https://github.com/luongcuong244/image_downloader/blob/master/android/src/main/kotlin/com/ko2ic/imagedownloader/FileProvider.kt"
    click D3 "https://github.com/luongcuong244/image_downloader/blob/master/android/src/main/AndroidManifest.xml"
    click D4 "https://github.com/luongcuong244/image_downloader/blob/master/example/android/app/src/main/res/xml/provider_paths.xml"
    click I1 "https://github.com/luongcuong244/image_downloader/blob/master/ios/Classes/ImageDownloaderPlugin.h"
    click I2 "https://github.com/luongcuong244/image_downloader/blob/master/ios/Classes/ImageDownloaderPlugin.m"
    click I3 "https://github.com/luongcuong244/image_downloader/blob/master/ios/Classes/SwiftImageDownloaderPlugin.swift"
    click I4 "https://github.com/luongcuong244/image_downloader/blob/master/ios/Classes/MetaDataUtils.swift"
    click I5 "https://github.com/luongcuong244/image_downloader/blob/master/example/ios/Runner/Info.plist"
    click I6 "https://github.com/luongcuong244/image_downloader/blob/master/ios/image_downloader.podspec"
```
