# boquila/boquilahub architecture

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

- Interactive diagram: https://gitdiagram.com/boquila/boquilahub
- Repository: https://github.com/boquila/boquilahub

## Overview

##### Project Type and Purpose
- This is a cross‐platform desktop and mobile application aimed at running AI models locally to monitor and protect nature. It leverages Flutter (with Dart) for the user interface across multiple platforms (Android, iOS, Windows, Linux, macOS) and uses Rust for high-performance processing pipelines (including computer vision, image/video processing, and potentially camera feed processing).
- The README emphasizes its capability to process image/video files and delegate processing via Web APIs when needed, detailing support for an array of hardware acceleration runtimes (CUDA, TensorRT, etc.). This makes it both a full-stack and hybrid system where UI and processing are tightly integrated.

##### Analyzing the File Structure
- Top-level directories indicate the multi-platform nature:
- “android”, “ios”, “linux”, “macos”, “windows”: Platform-specific code and configuration files for building and running the Flutter application.
- “lib”: Contains the Dart-based application code (main.dart, processing.dart, etc.) which is responsible for the UI and possibly some business logic.
- “rust”: Contains the Rust code which implements the core AI model handling, processing pipelines, and APIs to interface with native libraries (and includes multiple API modules like “inference”, “preprocessing”, “postprocessing”, etc.).
- “rust_builder” and related subdirectories: Likely a set of tooling scripts and build tools that help build or integrate the Rust components.
- Other directories like “assets”, “integration_test”, “test_driver”, “web”: Support auxiliary functions, integration tests, and web support.
- The presence of configuration files (e.g., gradle files, CMakeLists.txt) and the flutter_rust_bridge configuration indicate an architecture that bridges Flutter (Dart) with Rust code for robust, native performance in computational pipelines.

##### Key Components & Relationships
- Frontend (Flutter/Dart):
- This represents the user interface (UI) and control logic. It resides mostly in the “lib” directory.
- It is responsible for user interactions, choosing AI models, and initiating processing (for images, videos, or camera feeds).
- Platform-Specific Shells:
- Each of the “android”, “ios”, “linux”, “macos”, “windows” folders contains configurations and wrappers required to run the Flutter application on that platform.
- Rust Processing Pipeline (Backend):
- Code hosted under the “rust” directory contains multiple modules (API abstraction, image/processing modules, and platform-specific configurations) that perform the heavy lifting of AI inference and data processing. This is where the AI models are applied.
- Flutter-Rust Bridge:
- The integration between Flutter (the UI layer) and Rust (the processing layer) is achieved via the flutter_rust_bridge. This bridge is a critical link, facilitating asynchronous data and command exchange between the two.
- External Models and Binaries:
- Hardware/Acceleration Backends:
- The README lists several supported runtimes (CUDA, TensorRT, OpenVINO, etc.), so consider representing these as potential backends that the Rust pipeline can delegate computation to based on hardware availability.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The project clearly separates UI concerns (Flutter/Dart) from processing (Rust), with a well-defined bridging layer.
- Cross-Platform Architecture:
- Each platform has its dedicated folder for platform-specific wrappers, which clearly decouples the common cross-platform logic from native adaptations.
- Modularity in the Rust Pipeline:
- The “rust/src/api” folder contains modules for distinct parts of the processing (e.g., preprocessing, inference, postprocessing), highlighting a modular design that allows for further expansion.
- Extensibility:
- The architecture is designed to allow plugging in different AI execution providers (such as CUDA, TensorRT, etc.) as new modules or by extending current processing capabilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platform-Specific Shells
    subgraph "Platform-Specific Shells"
        ANDR("Android"):::platform
        IOS("iOS"):::platform
        LNX("Linux"):::platform
        MAC("macOS"):::platform
        WIN("Windows"):::platform
    end

    %% Frontend (Flutter/Dart UI)
    subgraph "Frontend (Flutter/Dart)"
        UI_Main("Main UI"):::frontend
        UI_Proc("Processing UI"):::frontend
        UI_Select("AI Selection UI"):::frontend
    end

    %% Flutter-Rust Bridge and its components
    BRIDGE("Flutter-Rust Bridge"):::bridge
    subgraph "Flutter-Rust Bridge Components"
        BridgeConfig("Bridge Config"):::bridge
        BridgeTooling("Bridge Tooling"):::bridge
    end
    BRIDGE --- BridgeConfig
    BRIDGE --- BridgeTooling

    %% Rust Processing Pipeline with API Modules
    subgraph "Rust Processing Pipeline"
        RP("Core Processing"):::backend
        subgraph "API Modules"
            Inference("Inference Module"):::backend
            Preprocessing("Preprocessing Module"):::backend
            Postprocessing("Postprocessing Module"):::backend
        end
    end

    %% Hardware Acceleration and External Models/Binaries
    Hardware("Hardware Acceleration"):::hardware
    External("External Models/Binaries"):::external

    %% Data Flow Connections
    UI_Main -->|"triggers"| BRIDGE
    UI_Proc -->|"triggers"| BRIDGE
    UI_Select -->|"triggers"| BRIDGE

    BRIDGE -->|"calls"| RP
    RP -->|"uses"| Inference
    RP -->|"uses"| Preprocessing
    RP -->|"uses"| Postprocessing

    RP -->|"delegates"| Hardware
    RP -->|"loads"| External

    BRIDGE -->|"results"| UI_Main
    BRIDGE -->|"results"| UI_Proc
    BRIDGE -->|"results"| UI_Select

    %% Platform-specific Wrappers are linked to the Frontend
    ANDR ---|"wraps"| UI_Main
    IOS ---|"wraps"| UI_Main
    LNX ---|"wraps"| UI_Main
    MAC ---|"wraps"| UI_Main
    WIN ---|"wraps"| UI_Main

    %% Click Events for Frontend
    click UI_Main "https://github.com/boquila/boquilahub/blob/main/lib/main.dart"
    click UI_Proc "https://github.com/boquila/boquilahub/blob/main/lib/processing.dart"
    click UI_Select "https://github.com/boquila/boquilahub/blob/main/lib/select_ai.dart"

    %% Click Events for Platform-Specific Shells
    click ANDR "https://github.com/boquila/boquilahub/tree/main/android"
    click IOS "https://github.com/boquila/boquilahub/tree/main/ios"
    click LNX "https://github.com/boquila/boquilahub/tree/main/linux"
    click MAC "https://github.com/boquila/boquilahub/tree/main/macos"
    click WIN "https://github.com/boquila/boquilahub/tree/main/windows"

    %% Click Events for Rust Processing Pipeline and API Modules
    click RP "https://github.com/boquila/boquilahub/tree/main/rust"
    click Inference "https://github.com/boquila/boquilahub/blob/main/rust/src/api/inference.rs"
    click Preprocessing "https://github.com/boquila/boquilahub/blob/main/rust/src/api/preprocessing.rs"
    click Postprocessing "https://github.com/boquila/boquilahub/blob/main/rust/src/api/postprocessing.rs"

    %% Click Events for Flutter-Rust Bridge Components
    click BridgeConfig "https://github.com/boquila/boquilahub/blob/main/flutter_rust_bridge.yaml"
    click BridgeTooling "https://github.com/boquila/boquilahub/tree/main/rust_builder"

    %% Click Event for Hardware/Acceleration Backends
    click Hardware "https://github.com/boquila/boquilahub/blob/main/lib/src/resources/hardware_dep.dart"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef bridge fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef platform fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef hardware fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#145A32,stroke-width:2px;
```
