# losses/rune architecture

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

- Interactive diagram: https://gitdiagram.com/losses/rune
- Repository: https://github.com/losses/rune

## Overview

##### Main System Components

a) Frontend Layer (Flutter UI)
- Main UI components from the /lib directory
- Features: Player Interface, Library Management, Analysis View
- Responsive design system that handles different platforms

b) Native Bridge Layer
- Native/hub component that bridges Flutter and Rust
- Message passing system (using the protocol definitions in /messages)

c) Core Backend Layer (Rust)
- Database Management (/database)
- Audio Analysis Engine (/analysis)
- Playback System (/playback)
- Metadata Management (/metadata)
- Scrobbling Service (/scrobbling)

##### Key Interactions to Highlight

- Audio file processing path: Metadata → Analysis → Database
- Playback path: Database → Playback Engine → UI
- Analysis flow: Audio Input → FFT Analysis → Feature Extraction
- Mix generation: Database → Analysis Engine → Recommendation System

##### Specific Component Details

Database Layer:
- Tables structure from /migration
- Relationships between media files, metadata, and analysis results

Analysis Engine:
- CPU/GPU analyzers from /analysis/src/analyzer
- FFT processing pipeline
- WGPU acceleration system

Playback System:
- Controller/player architecture
- Real-time FFT visualization pipeline
- Platform-specific output handlers

##### Cross-Platform Architecture

- Platform-specific implementations (Windows, macOS, Linux, iOS, Android)
- Shared core components
- Platform-specific bridges

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px
    classDef bridge fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef database fill:#F0E68C,stroke:#333,stroke-width:2px

    subgraph Frontend
        UI[Main UI Components]:::frontend
        Player[Player Interface]:::frontend
        Library[Library Management]:::frontend
        Settings[Settings Interface]:::frontend
    end

    subgraph Bridge
        NativeBridge[Native Bridge]:::bridge
        Protocol[Protocol Definitions]:::bridge
        PlatformBridge[Platform Bridges]:::bridge
    end

    subgraph Backend
        subgraph CoreServices
            DB[(Database Management)]:::database
            Analysis[Audio Analysis Engine]:::backend
            Playback[Playback System]:::backend
            Metadata[Metadata Management]:::backend
            Scrobbling[Scrobbling Service]:::backend
        end

        subgraph AnalysisComponents
            CoreAnalyzer[Core Analyzer]:::backend
            FFTProcess[FFT Processing]:::backend
            GPUAccel[GPU Acceleration]:::backend
        end

        subgraph MediaManagement
            Lyrics[Lyric Processing]:::backend
            TagEdit[Tag Editing]:::backend
            CoverArt[Cover Art Management]:::backend
        end

        subgraph Platforms
            Windows[Windows]:::backend
            MacOS[macOS]:::backend
            Linux[Linux]:::backend
            IOS[iOS]:::backend
            Android[Android]:::backend
        end
    end

    %% Connections
    UI --> NativeBridge
    Player --> NativeBridge
    Library --> NativeBridge
    Settings --> NativeBridge

    NativeBridge --> Protocol
    Protocol --> PlatformBridge
    PlatformBridge --> CoreServices

    Metadata --> Analysis
    Analysis --> DB
    DB --> Playback
    Playback --> UI

    Analysis --> CoreAnalyzer
    CoreAnalyzer --> FFTProcess
    CoreAnalyzer --> GPUAccel

    DB --> MediaManagement
    Scrobbling --> External[External Services]:::external

    %% Click Events
    click UI "https://github.com/losses/rune/tree/master/lib/widgets"
    click Player "https://github.com/losses/rune/tree/master/lib/widgets/playback_controller"
    click Library "https://github.com/losses/rune/tree/master/lib/screens/library_home"
    click Settings "https://github.com/losses/rune/tree/master/lib/screens/settings_home"
    click NativeBridge "https://github.com/losses/rune/tree/master/native/hub"
    click Protocol "https://github.com/losses/rune/tree/master/messages"
    click PlatformBridge "https://github.com/losses/rune/tree/master/native/hub/apple-bridge-library"
    click DB "https://github.com/losses/rune/tree/master/database"
    click Analysis "https://github.com/losses/rune/tree/master/analysis"
    click Playback "https://github.com/losses/rune/tree/master/playback"
    click Metadata "https://github.com/losses/rune/tree/master/metadata"
    click Scrobbling "https://github.com/losses/rune/tree/master/scrobbling"
    click CoreAnalyzer "https://github.com/losses/rune/tree/master/analysis/src/analyzer"
    click FFTProcess "https://github.com/losses/rune/tree/master/analysis/src/wgpu_fft"
    click GPUAccel "https://github.com/losses/rune/blob/master/analysis/src/analyzer/gpu_sub_analyzer.rs"
    click CoverArt "https://github.com/losses/rune/blob/master/database/src/actions/cover_art.rs"
    click Windows "https://github.com/losses/rune/tree/master/windows"
    click MacOS "https://github.com/losses/rune/tree/master/macos"
    click Linux "https://github.com/losses/rune/tree/master/linux"
    click IOS "https://github.com/losses/rune/tree/master/ios"
    click Android "https://github.com/losses/rune/tree/master/android"
    click Lyrics "https://github.com/losses/rune/tree/master/lyric"
    click TagEdit "https://github.com/losses/rune/tree/master/tag-editor"
```
