# cunarist/rinf architecture

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

- Interactive diagram: https://gitdiagram.com/cunarist/rinf
- Repository: https://github.com/cunarist/rinf

## Overview

##### Main Components

a) Flutter Layer (GUI):
- Flutter widgets and UI components
- Platform-specific implementations (iOS, Android, Web, Desktop)
- Dart interface code (lib/src/interface.dart)

b) Bridge Layer:
- FFI Communication channel
- Message passing system (using Protobuf)
- Platform-specific bridges (interface_os.dart, interface_web.dart)

c) Rust Layer (Business Logic):
- Core Rust implementation (rust_crate/)
- Native functionality
- Multi-threading capabilities

##### Key Relationships to Highlight

a) Communication Flow:
- Bidirectional message passing between Flutter and Rust
- Signal streams for state updates
- Error handling pathways

b) Build System Integration:
- Cargokit integration
- Platform-specific build processes
- Native compilation workflow

**[Flutter UI Layer]**

- ▼
**[Dart Interface Layer]**
- Platform-specific implementations
- Message handling
- ▼
**[FFI Bridge Layer]**
- Protobuf serialization
- Channel management
- ▼
**[Rust Core Layer]**
- Business logic
- Native functionality

##### Important Elements

a) Platform Support:
- Supported platforms (iOS, Android, Web, Windows, macOS, Linux)
- Platform-specific bridges

b) Build Pipeline:
- Cargokit integration
- Native compilation process
- Platform-specific build tools

c) Message System:
- Protobuf schema handling
- Signal streams
- Error propagation

##### Implementation Details

- Version compatibility indicators
- Build artifact flow

##### Additional Notes

- Keep the main communication channels prominent
- Separation of concerns between UI and business logic
- How the framework handles cross-platform compatibility
- Important file locations and configuration points

- Simple integration
- High performance
- Cross-platform support
- Developer-friendly tooling
- Clean architecture separation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Flutter
        UI[Flutter UI Components]
        DartInterface[Dart Interface]:::dart
        PlatformImpl[Platform Implementations]:::dart
    end

    subgraph Bridge
        FFI[FFI Communication]:::bridge
        Proto[Protobuf Messages]:::bridge
        InterfaceOS[OS Interface]:::bridge
        InterfaceWeb[Web Interface]:::bridge
    end

    subgraph Rust
        CoreImpl[Core Implementation]:::rust
        NativeFuncs[Native Functionality]:::rust
        ErrorHandling[Error Handling]:::rust
        Shutdown[Shutdown Management]:::rust
    end

    subgraph BuildSystem
        Cargokit[Cargokit]:::build
        CMake[CMake Integration]:::build
        Gradle[Gradle Plugin]:::build
    end

    subgraph Platforms
        direction TB
        iOS[iOS]:::platform
        Android[Android]:::platform
        Web[Web]:::platform
        Windows[Windows]:::platform
        MacOS[macOS]:::platform
        Linux[Linux]:::platform
    end

    UI --> DartInterface
    DartInterface --> PlatformImpl
    PlatformImpl --> FFI
    FFI --> Proto
    Proto --> InterfaceOS
    Proto --> InterfaceWeb
    InterfaceOS --> CoreImpl
    InterfaceWeb --> CoreImpl
    CoreImpl --> NativeFuncs
    CoreImpl --> ErrorHandling
    CoreImpl --> Shutdown

    Cargokit --> CMake
    Cargokit --> Gradle
    Cargokit --> CoreImpl

    PlatformImpl --> Platforms

    %% Click Events
    click DartInterface "https://github.com/cunarist/rinf/blob/main/flutter_package/lib/src/interface.dart"
    click InterfaceOS "https://github.com/cunarist/rinf/blob/main/flutter_package/lib/src/interface_os.dart"
    click InterfaceWeb "https://github.com/cunarist/rinf/blob/main/flutter_package/lib/src/interface_web.dart"
    click CoreImpl "https://github.com/cunarist/rinf/blob/main/rust_crate/src/lib.rs"
    click ErrorHandling "https://github.com/cunarist/rinf/blob/main/rust_crate/src/error.rs"
    click Shutdown "https://github.com/cunarist/rinf/blob/main/rust_crate/src/shutdown.rs"
    click Proto "https://github.com/cunarist/rinf/tree/main/flutter_package/example/messages"
    click Cargokit "https://github.com/cunarist/rinf/tree/main/flutter_package/cargokit"
    click CMake "https://github.com/cunarist/rinf/blob/main/flutter_package/cargokit/cmake/cargokit.cmake"
    click Gradle "https://github.com/cunarist/rinf/blob/main/flutter_package/cargokit/gradle/plugin.gradle"

    %% Styling
    classDef dart fill:#40C4FF,stroke:#0091EA,color:white
    classDef bridge fill:#FF9800,stroke:#F57C00,color:white
    classDef rust fill:#4CAF50,stroke:#388E3C,color:white
    classDef build fill:#9E9E9E,stroke:#616161,color:white
    classDef platform fill:#7E57C2,stroke:#5E35B1,color:white

    %% Legend
    subgraph Legend
        L1[Flutter/Dart]:::dart
        L2[Bridge/FFI]:::bridge
        L3[Rust]:::rust
        L4[Build System]:::build
        L5[Platforms]:::platform
    end
```
