How fast4x/rimusic works
The RiMusic project is a large-scale, multiplatform (Android, desktop, and common shared code) music streaming app built in Kotlin using modern frameworks (Jetpack Compose for UI, Kotlin Multiplatform) and a modular design that integrates many extensions. Its purpose is to stream music from YouTube Music (and alternate sources via its extension modules) while providing features like background playback, audio visualization, offline caching/downloads, playlist management, and multilingual support.
Main Components
• Platforms & UI Layers:
• Android (“androidMain” module) and Desktop (“desktopMain” module).
• Common UI code is contained in “composeApp”, “commonMain” and specific modules for persistence and reordering.
• UI components (screens, navigation components, themed widgets, etc.) found in packages such as ui/screens, ui/components, and styling.
• Core Business & Shared Logic:
• The shared “commonMain” code for components like the MusicDatabase and business logic within it/fast4x/rimusic.
• Data models, utility functions, and common APIs that abstract away platform differences.
• Data Persistence & Cache:
• Modules like “compose-persist” deal with state retention of UI components.
• Database schemas and MusicDatabase definition with its entities in both “composeApp/schemas” and “commonMain/kotlin/database”.
• Media Playback & Player Engine:
• Separate player modules under packages such as “service”, “player”, “player/component” and even native implementations for Android and desktop.
• Integration with libraries for audio visualizer effects and handling playback state.
• Network & External Integrations:
• Extensions for environment, invidious, kugou, lrclib, piped and ktor-client-brotli that handle API requests, translation, fetching lyrics and other metadata.
• Each extension often contains its own request, models, and utility submodules.
• Build & Deployment Components:
• Gradle scripts, Gradle wrapper, CI/CD configurations (GitHub workflows and GitLab CI) that manage building for Android and desktop.
• Distribution files and packaging scripts for various platforms.
Relationships and Data Flow
• The shared common code under “commonMain” supplies business logic shared among Android, desktop, and even testing modules.
• The UI layer calls into business logic (e.g., using MVVM or similar patterns) to update state from the MusicDatabase and playback services.
• The media engine (player service) interacts with lower-level audio frameworks, passing controls from UI components like sliders and buttons.
• Network modules (under extensions such as environment or invidious) fetch data (streaming links, metadata, lyrics) which then feed into the common models and are used by the UI.
• Offline caching and persistence strategies (from compose-persist and local database modules) are used to enable offline play and quick startup.
• External services such as YouTube Music, KuGou, and LrcLib are abstracted behind the extension modules so that the core logic remains platform independent.
Architectural Patterns and Design Principles
• Modularization and separation of concerns: Different modules (UI, player, database, network) are separated clearly, easing maintenance and evolution.
• Multiplatform architecture: A significant portion of the code resides in “commonMain” so that platform-specific implementations in “androidMain” and “desktopMain” only provide the necessary adaptations.
• Extension-driven design: Many functionalities (environment, lyrics translation, media metadata fetching) are implemented as independent extensions so that they can be updated or swapped without impacting the core.
• Clear layering: The system is layered into presentation (UI), application logic (business services, state management), and data (persistence, caching, external API interactions).
Relevant Technologies and Frameworks
• Programming and Build Tools: Kotlin, Kotlin Multiplatform, Gradle with Kotlin DSL.
• UI Framework: Jetpack Compose (for Android and Desktop) – note usage of Compose-specific modules such as “compose-persist” and “compose-reordering”.
• Data Persistence: Custom MusicDatabase with schema definitions and support for offline caching.
• Network and API Libraries: Ktor (and additional plugins like ktor-client-brotli), as well as custom network wrappers in extension modules.
• Multimedia and Playback: Custom implementations for audio playback, integration with Android’s media system, and desktop alternatives.
• Clear labels for each component, such as “UI – Android”, “UI – Desktop”, “Common Business Logic”, “MusicDatabase”, “Player Service”, “Network/Extensions”, “External APIs”.
• From the UI into the ViewModel/Controller layer.
• From those controllers to the MusicDatabase and network layers.