# abhirarecrew/open_file_plus architecture

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

- Interactive diagram: https://gitdiagram.com/abhirarecrew/open_file_plus
- Repository: https://github.com/abhirarecrew/open_file_plus

## Overview

##### Project Type and Purpose
- This is an open-source Flutter plugin (“open_file_plus”) that provides a unified API for opening files on multiple platforms (iOS, Android, Windows, macOS, Linux, and Web).
- It exposes a Dart API (openFilePlus) which under the hood dispatches calls to platform-specific implementations:
- Android: Intents via Java
- iOS: UIDocumentInteractionController via Objective-C
- Desktop (Windows, macOS, Linux): FFI bindings to native libraries
- Web: dart:html window.open

##### File Structure Analysis
- lib/
- open_file_plus.dart – public entrypoint
- src/common – shared classes (OpenResult, argument parsing)
- src/platform – platform interface and dispatch logic
- src/web – pure-Dart web implementation
- android/
- OpenFilePlusPlugin.java & FileProvider.java – Android plugin using MethodChannel
- filepaths.xml – FileProvider configuration
- ios/
- OpenFilePlusPlugin.h/m – iOS plugin using FlutterMethodChannel & UIDocumentInteractionController
- open_file_plus.podspec – CocoaPod spec
- pubspec.yaml – defines plugin, platform dependencies, versioning
- example/ – sample Flutter app demonstrating plugin usage on Android and iOS

##### README Insights
- Describes supported platforms and the underlying mechanisms (intent, DocumentInteraction, FFI, dart:html).
- Lists supported file‐type mappings and special Android/iOS permissions.

##### Main Components
a. Flutter App Layer (example or any client app)
- Calls OpenFile.open(path, …)
b. Plugin Core (Dart code)
- open_file_plus.dart (public API)
- src/common (OpenResult, argument parser)
- MethodChannel dispatcher (src/platform/open_file.dart)
c. Platform Implementations
- Android module (Java code in android/src)
- iOS module (Objective-C code in ios/Classes)
- Desktop FFI modules (C/C++ interop via dart:ffi in src/platform/{windows, macos, linux}.dart)
- Web module (dart:html in src/web/open_file.dart)
d. Native OS Services
- Android Intent Manager
- iOS UIDocumentInteractionController
- Desktop OS Shell (ShellExecute on Windows, open on macOS/Linux)
- Browser window.open on Web

##### Relationships & Data Flow
- Return flow: Native OS API → platform code → MethodChannel / FFI callback → Dart OpenResult → Flutter App UI.

##### Architectural Patterns & Principles
- Plugin Pattern: isolating platform code behind a Dart interface.
- Single Responsibility: common parsing logic separated from platform dispatch.
- Platform Abstraction: each target (Android, iOS, Desktop, Web) lives in its own directory.
- Asynchronous, future-based API returning OpenResult.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers top to bottom

    %% Flutter App Layer
    App["Flutter App"]:::dart
    click App "https://github.com/abhirarecrew/open_file_plus/blob/main/example/lib/main.dart"

    %% Plugin Core Layer
    subgraph "Plugin Core"
        API["open_file_plus.dart (Public API)"]:::dart
        Common["Common Utilities\n(open_result.dart, parse_args.dart)"]:::dart
        Dispatcher["Platform Dispatcher\n(open_file.dart)"]:::dart
    end
    click API "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/open_file_plus.dart"
    click Common "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/common/open_result.dart"
    click Common "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/common/parse_args.dart"
    click Dispatcher "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/platform/open_file.dart"

    %% Platform Implementations Layer
    subgraph "Platform Implementations"
        AndroidMod["Android Module"]:::native
        iOSMod["iOS Module"]:::native
        DesktopWin["Windows FFI"]:::native
        DesktopMac["macOS FFI"]:::native
        DesktopLinux["Linux FFI"]:::native
        WebMod["Web Module"]:::web
    end
    click AndroidMod "https://github.com/abhirarecrew/open_file_plus/blob/main/android/src/main/java/com/joutvhu/openfile/OpenFilePlusPlugin.java"
    click AndroidMod "https://github.com/abhirarecrew/open_file_plus/blob/main/android/src/main/java/com/joutvhu/openfile/FileProvider.java"
    click AndroidMod "https://github.com/abhirarecrew/open_file_plus/blob/main/android/src/main/res/xml/filepaths.xml"
    click AndroidMod "https://github.com/abhirarecrew/open_file_plus/blob/main/android/src/main/java/com/joutvhu/openfile/utils/JsonUtil.java"
    click AndroidMod "https://github.com/abhirarecrew/open_file_plus/blob/main/android/src/main/java/com/joutvhu/openfile/utils/MapUtil.java"
    click iOSMod "https://github.com/abhirarecrew/open_file_plus/blob/main/ios/Classes/OpenFilePlusPlugin.h"
    click iOSMod "https://github.com/abhirarecrew/open_file_plus/blob/main/ios/Classes/OpenFilePlusPlugin.m"
    click iOSMod "https://github.com/abhirarecrew/open_file_plus/blob/main/ios/open_file_plus.podspec"
    click DesktopWin "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/platform/windows.dart"
    click DesktopMac "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/platform/macos.dart"
    click DesktopLinux "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/platform/linux.dart"
    click WebMod "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/web/open_file.dart"
    click WebMod "https://github.com/abhirarecrew/open_file_plus/blob/main/lib/src/web/web.dart"

    %% Native OS Services Layer
    subgraph "Native OS Services"
        OSAndroid[(Android Intent Manager)]:::os
        OSiOS[(UIDocumentInteractionController)]:::os
        OSWin[(ShellExecute)]:::os
        OSMac[(open command)]:::os
        OSLinux[(xdg-open)]:::os
        Browser[(window.open)]:::os
    end

    %% Connections
    App -->|"open(path, type, uti)"| API
    API -->|"parse args"| Common
    API -->|"invoke platform"| Dispatcher

    Dispatcher -->|"MethodChannel.invokeMethod"| AndroidMod
    Dispatcher -->|"MethodChannel.invokeMethod"| iOSMod
    Dispatcher -->|"dart:ffi call"| DesktopWin
    Dispatcher -->|"dart:ffi call"| DesktopMac
    Dispatcher -->|"dart:ffi call"| DesktopLinux
    Dispatcher -->|"window.open()"| WebMod

    AndroidMod -->|"Android Intent"| OSAndroid
    iOSMod -->|"DocumentInteraction"| OSiOS
    DesktopWin -->|"ShellExecute API"| OSWin
    DesktopMac -->|"open cmd"| OSMac
    DesktopLinux -->|"xdg-open"| OSLinux
    WebMod -->|"browser window"| Browser

    OSAndroid -->|"result callback"| AndroidMod
    OSiOS -->|"result callback"| iOSMod
    OSWin -->|"FFI callback"| DesktopWin
    OSMac -->|"FFI callback"| DesktopMac
    OSLinux -->|"FFI callback"| DesktopLinux
    Browser -->|"Future<OpenResult>"| WebMod

    AndroidMod -->|"return OpenResult"| Dispatcher
    iOSMod -->|"return OpenResult"| Dispatcher
    DesktopWin -->|"return OpenResult"| Dispatcher
    DesktopMac -->|"return OpenResult"| Dispatcher
    DesktopLinux -->|"return OpenResult"| Dispatcher
    WebMod -->|"return OpenResult"| Dispatcher

    Dispatcher -->|"Future<OpenResult>"| API
    Common -->|"OpenResult object"| API
    API -->|"Future<OpenResult>"| App

    %% Styles
    classDef dart fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef native fill:#90EE90,stroke:#000,stroke-width:1px
    classDef os fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef web fill:#FFFF99,stroke:#000,stroke-width:1px
```
