# smrutiranjan-patra/wavetune architecture

> Architecture diagram of the GitHub repository smrutiranjan-patra/wavetune, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/smrutiranjan-patra/wavetune
- Repository: https://github.com/smrutiranjan-patra/wavetune

## Overview

1. **What this repo is**
   - WaveTune is an **Expo/React Native Android music player** built for local device media. The README makes it clear the project is optimized for **Expo Dev Client on Android**, so native modules and Android permissions matter to the architecture.

2. **App shell and navigation**
   - The `app/` directory uses **file-based routing** with a tab layout at `app/(tabs)/_layout.tsx`.
   - Primary surfaces are `home`, `search`, `playlist`, and `settings`, plus a nested `library` section with separate views for `songs`, `albums`, `artists`, `folders`, and `genres`.
   - `app/player.tsx` is a distinct full-screen playback route, while `components/MiniPlayer.tsx` suggests a persistent lightweight player UI across the tab experience.

3. **UI layer**
   - Reusable presentational components live in `components/`:
     - `Header`, `Button`, `SongCard`, `MiniPlayer`
   - These components are likely thin wrappers around store state and navigation actions; they should not own business logic.
   - `global.css`, `tailwind.config.js`, and `nativewind` typings indicate the UI is styled with **Tailwind/Nativ eWind** rather than platform-specific styling code.

4. **Global app composition**
   - `app/_layout.tsx` and `providers/AppProvider.tsx` are the main composition boundaries.
   - The provider layer likely wires together app-wide stores, permissions, player initialization, and any startup side effects before screens render.

5. **State management boundary**
   - `store/` holds the app’s client state:
     - `app.store.ts`
     - `library.store.ts`
     - `player.store.ts`
     - `settings.store.ts`
   - `store/handlers/` suggests a separation between raw state and state-transition logic.
   - In architecture terms, screens read from stores, while services and handlers update them.

6. **Device media ingestion pipeline**
   - `hooks/useMediaPermission.ts` and `services/library/permission.service.ts` / `services/scanner/permissions.ts` handle Android media access.
   - The flow is: **permission check → scan local media → extract metadata → normalize → persist/update state**.
   - This is the key boundary between the Android device and the app’s internal library model.

7. **Library scanning and normalization**
   - `services/library/scanner.service.ts`, `services/scanner/scanner.service.ts`, and `services/media.service.ts` indicate a scanning subsystem that reads device media and builds the app’s internal catalog.
   - `services/library/library.service.ts` likely orchestrates the full library refresh process.
   - `helpers/library/*` contains domain-specific helper transformations for songs, albums, artists, folders, and genres.

8. **Metadata processing**
   - `services/metadata/metadata.service.ts` and `services/metadata/parsers.ts` are responsible for interpreting track metadata.
   - `services/library/metadata.service.ts` connects metadata extraction to the library domain model.
   - This subsystem is important because it turns raw device files into searchable, browsable entities like tracks, albums, and artists.

9. **Persistence layer**
   - `services/database/` is a repository-style persistence boundary with:
     - `database.service.ts`
     - `songs.repository.ts`
     - `albums.repository.ts`
     - `artists.repository.ts`
   - This implies the app keeps a local indexed store for library entities rather than re-scanning on every screen render.
   - The repositories are the only layer that should know the storage format; services and UI consume higher-level models.

10. **Playback subsystem**
   - `services/player/` is a dedicated playback domain:
     - `player.service.ts`
     - `playback.service.ts`
     - `queue.service.ts`
     - `setup.service.ts`
     - `mapper.ts`
     - `player.types.ts`
     - `index.ts`
   - The architecture suggests a split between:
     - queue management,
     - playback control,
     - player initialization,
     - and data mapping from library entities into playable items.
   - `store/player.store.ts` likely mirrors the current track, queue, and playback status for the UI.

11. **Search and browse flows**
   - `services/search/search.service.ts` likely queries the persisted library rather than scanning files directly.
   - The library screens and search screen together form the main read path over the catalog:
     - browse by entity type in `library/*`
     - search by indexed metadata in `search.tsx`
   - This is a clear separation: **search/browse are consumers of the persisted library**, not of raw device media.

12. **Important runtime/infrastructure constraints**
   - The README shows this is meant to run in an **Android Dev Client** with Metro and ADB workflows.
   - Because the app depends on device media access and likely native playback/permission behavior, native changes require `expo prebuild --clean` and `expo run:android`.
   - That means the architecture has both a React Native UI/runtime layer and a device-integrated native boundary that affects deployment and iteration.

13. **How data likely moves through the system**
   - On startup, the provider/layout bootstraps app state and player setup.
   - After permissions are granted, the scanner reads device media, metadata is parsed, and entities are stored through database repositories.
   - Stores are updated with the library snapshot, which feeds the tab screens, search, and player UI.
   - When a song is selected, the player subsystem converts library items into queue entries and drives playback, while the mini-player and player screen reflect current playback state.

14. **Architecture summary for diagramming**
   - You can model the app as four main layers:
     - **UI/navigation** in `app/` and `components/`
     - **state orchestration** in `store/` and `providers/`
     - **domain services** for library, metadata, search, and playback
     - **device/native integration** for permissions, scanning, and playback
   - The most important boundary is between **Android device media access** and the **normalized local music library** that powers browsing, search, and playback.

Main entry points: [`services/player/player.service.ts`](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/player.service.ts) (Player service), [`store/library.store.ts`](https://github.com/smrutiranjan-patra/wavetune/blob/main/store/library.store.ts) (Library store), [`providers/AppProvider.tsx`](https://github.com/smrutiranjan-patra/wavetune/blob/main/providers/AppProvider.tsx) (App provider), [`services/database/database.service.ts`](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/database.service.ts) (Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI shell"]
  node_app_root["Root layout<br/>expo shell<br/>[_layout.tsx]"]
  node_tabs_layout["Tabs layout<br/>navigation<br/>[_layout.tsx]"]
  node_home_screen["Home<br/>screen<br/>[home.tsx]"]
  node_library_layout["Library layout<br/>navigation<br/>[_layout.tsx]"]
  node_player_screen["Player<br/>screen<br/>[player.tsx]"]
  node_mini_player["Mini player<br/>[MiniPlayer.tsx]"]
end

subgraph group_state["State"]
  node_app_provider["App provider<br/>composition<br/>[AppProvider.tsx]"]
  node_app_store[("App store<br/>state store<br/>[app.store.ts]")]
  node_library_store[("Library store<br/>state store<br/>[library.store.ts]")]
  node_player_store[("Player store<br/>state store<br/>[player.store.ts]")]
  node_library_handlers["Library handlers<br/>state actions"]
end

subgraph group_ingest["Ingestion"]
  node_media_permission_hook["Media permission<br/>hook"]
  node_scanner_permissions["Scanner permissions<br/>android permissions<br/>[permissions.ts]"]
  node_scanner_service["Scanner<br/>media scan<br/>[scanner.service.ts]"]
  node_media_service["Media source<br/>device media<br/>[media.service.ts]"]
  node_metadata_service["Metadata<br/>parsing"]
end

subgraph group_library["Library"]
  node_library_service["Library service<br/>orchestration<br/>[library.service.ts]"]
  node_library_scanner_service["Library scanner<br/>orchestration<br/>[scanner.service.ts]"]
  node_library_metadata_service["Library metadata<br/>mapping"]
  node_song_helpers["Song helpers<br/>normalization<br/>[songs.ts]"]
  node_search_service["Search<br/>query service<br/>[search.service.ts]"]
end

subgraph group_persistence["Persistence"]
  node_database_service[("Database<br/>local store")]
  node_songs_repo["Songs repo"]
  node_albums_repo["Albums repo"]
  node_artists_repo["Artists repo"]
end

subgraph group_playback["Playback"]
  node_player_service["Player service<br/>playback core<br/>[player.service.ts]"]
  node_queue_service["Queue<br/>[queue.service.ts]"]
  node_playback_service["Playback control<br/>transport"]
  node_setup_service["Player setup<br/>initialization<br/>[setup.service.ts]"]
  node_player_mapper["Player mapper<br/>mapping<br/>[mapper.ts]"]
end

node_app_root -->|"composes"| node_app_provider
node_app_root -->|"hosts"| node_tabs_layout
node_tabs_layout -->|"routes to"| node_home_screen
node_tabs_layout -->|"routes to"| node_library_layout
node_app_root -->|"routes to"| node_player_screen
node_home_screen -->|"uses"| node_mini_player
node_player_screen -->|"reads"| node_player_store
node_mini_player -->|"reads"| node_player_store
node_app_provider -->|"initializes"| node_app_store
node_app_provider -->|"requests"| node_media_permission_hook
node_app_provider -->|"initializes"| node_setup_service
node_media_permission_hook -->|"delegates to"| node_scanner_permissions
node_scanner_permissions -->|"unlocks"| node_scanner_service
node_scanner_service -->|"reads from"| node_media_service
node_scanner_service -->|"parses with"| node_metadata_service
node_metadata_service -->|"feeds"| node_library_metadata_service
node_library_service -->|"orchestrates"| node_library_scanner_service
node_library_scanner_service -->|"uses"| node_scanner_service
node_library_service -->|"persists to"| node_database_service
node_library_metadata_service -->|"normalizes"| node_song_helpers
node_song_helpers -->|"updates"| node_library_store
node_database_service -->|"exposes"| node_songs_repo
node_database_service -->|"exposes"| node_albums_repo
node_database_service -->|"exposes"| node_artists_repo
node_library_store -->|"feeds"| node_search_service
node_library_store -->|"mutates via"| node_library_handlers
node_player_service -->|"coordinates"| node_queue_service
node_player_service -->|"drives"| node_playback_service
node_player_service -->|"maps through"| node_player_mapper
node_player_service -->|"updates"| node_player_store
node_player_service -->|"depends on"| node_setup_service
node_search_service -->|"queries"| node_library_store
node_library_layout -->|"reads"| node_library_store

click node_app_root "https://github.com/smrutiranjan-patra/wavetune/blob/main/app/_layout.tsx"
click node_tabs_layout "https://github.com/smrutiranjan-patra/wavetune/blob/main/app/(tabs)/_layout.tsx"
click node_home_screen "https://github.com/smrutiranjan-patra/wavetune/blob/main/app/(tabs)/home.tsx"
click node_library_layout "https://github.com/smrutiranjan-patra/wavetune/blob/main/app/(tabs)/library/_layout.tsx"
click node_player_screen "https://github.com/smrutiranjan-patra/wavetune/blob/main/app/player.tsx"
click node_mini_player "https://github.com/smrutiranjan-patra/wavetune/blob/main/components/MiniPlayer.tsx"
click node_app_provider "https://github.com/smrutiranjan-patra/wavetune/blob/main/providers/AppProvider.tsx"
click node_app_store "https://github.com/smrutiranjan-patra/wavetune/blob/main/store/app.store.ts"
click node_library_store "https://github.com/smrutiranjan-patra/wavetune/blob/main/store/library.store.ts"
click node_player_store "https://github.com/smrutiranjan-patra/wavetune/blob/main/store/player.store.ts"
click node_library_handlers "https://github.com/smrutiranjan-patra/wavetune/blob/main/store/handlers/library.handlers.ts"
click node_media_permission_hook "https://github.com/smrutiranjan-patra/wavetune/blob/main/hooks/useMediaPermission.ts"
click node_scanner_permissions "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/scanner/permissions.ts"
click node_scanner_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/scanner/scanner.service.ts"
click node_media_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/media.service.ts"
click node_metadata_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/metadata/metadata.service.ts"
click node_library_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/library/library.service.ts"
click node_library_scanner_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/library/scanner.service.ts"
click node_library_metadata_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/library/metadata.service.ts"
click node_song_helpers "https://github.com/smrutiranjan-patra/wavetune/blob/main/helpers/library/songs.ts"
click node_database_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/database.service.ts"
click node_songs_repo "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/songs.repository.ts"
click node_albums_repo "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/albums.repository.ts"
click node_artists_repo "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/artists.repository.ts"
click node_search_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/search/search.service.ts"
click node_player_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/player.service.ts"
click node_queue_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/queue.service.ts"
click node_playback_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/playback.service.ts"
click node_setup_service "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/setup.service.ts"
click node_player_mapper "https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/mapper.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_root,node_tabs_layout,node_home_screen,node_library_layout,node_player_screen,node_mini_player toneBlue
class node_app_provider,node_app_store,node_library_store,node_player_store,node_library_handlers toneAmber
class node_media_permission_hook,node_scanner_permissions,node_scanner_service,node_media_service,node_metadata_service toneMint
class node_library_service,node_library_scanner_service,node_library_metadata_service,node_song_helpers,node_search_service toneRose
class node_database_service,node_songs_repo,node_albums_repo,node_artists_repo toneIndigo
class node_player_service,node_queue_service,node_playback_service,node_setup_service,node_player_mapper toneTeal
```

## Components

### UI shell

File-based routes and reusable screens/components.

- [Root layout](https://github.com/smrutiranjan-patra/wavetune/blob/main/app/_layout.tsx): expo shell · Bootstraps the app and composes global providers. · `app/_layout.tsx`
- [Tabs layout](https://github.com/smrutiranjan-patra/wavetune/blob/main/app/(tabs)/_layout.tsx): navigation · Defines the main tab-based navigation surface. · `app/(tabs)/_layout.tsx`
- [Home](https://github.com/smrutiranjan-patra/wavetune/blob/main/app/(tabs)/home.tsx): screen · Primary landing screen for the music app. · `app/(tabs)/home.tsx`
- [Library layout](https://github.com/smrutiranjan-patra/wavetune/blob/main/app/(tabs)/library/_layout.tsx): navigation · Nested library browsing routes. · `app/(tabs)/library/_layout.tsx`
- [Player](https://github.com/smrutiranjan-patra/wavetune/blob/main/app/player.tsx): screen · Full-screen playback route. · `app/player.tsx`
- [Mini player](https://github.com/smrutiranjan-patra/wavetune/blob/main/components/MiniPlayer.tsx): Persistent compact playback UI. · `components/MiniPlayer.tsx`

### State

App-wide stores and state transition logic.

- [App provider](https://github.com/smrutiranjan-patra/wavetune/blob/main/providers/AppProvider.tsx): composition · Wires startup state, permissions, and player setup. · `providers/AppProvider.tsx`
- [App store](https://github.com/smrutiranjan-patra/wavetune/blob/main/store/app.store.ts): state store · Global app state container. · `store/app.store.ts`
- [Library store](https://github.com/smrutiranjan-patra/wavetune/blob/main/store/library.store.ts): state store · Catalog state for songs, albums, artists, and browse views. · `store/library.store.ts`
- [Player store](https://github.com/smrutiranjan-patra/wavetune/blob/main/store/player.store.ts): state store · Current track, queue, and playback status. · `store/player.store.ts`
- [Library handlers](https://github.com/smrutiranjan-patra/wavetune/blob/main/store/handlers/library.handlers.ts): state actions · State transition logic for library updates. · `store/handlers/library.handlers.ts`

### Ingestion

Permission, scan, and metadata pipeline from Android media.

- [Media permission](https://github.com/smrutiranjan-patra/wavetune/blob/main/hooks/useMediaPermission.ts): hook · Requests or checks Android media access. · `hooks/useMediaPermission.ts`
- [Scanner permissions](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/scanner/permissions.ts): android permissions · Permission helpers used by the scanning pipeline. · `services/scanner/permissions.ts`
- [Scanner](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/scanner/scanner.service.ts): media scan · Reads local device media into app-friendly records. · `services/scanner/scanner.service.ts`
- [Media source](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/media.service.ts): device media · Low-level access to device media content. · `services/media.service.ts`
- [Metadata](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/metadata/metadata.service.ts): parsing · Extracts and parses track metadata. · `services/metadata/metadata.service.ts`

### Library

Normalized catalog orchestration and helpers.

- [Library service](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/library/library.service.ts): orchestration · Coordinates permission, scan, metadata, and persistence for refreshes. · `services/library/library.service.ts`
- [Library scanner](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/library/scanner.service.ts): orchestration · Library-domain scanning entrypoint. · `services/library/scanner.service.ts`
- [Library metadata](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/library/metadata.service.ts): mapping · Maps extracted metadata into library entities. · `services/library/metadata.service.ts`
- [Song helpers](https://github.com/smrutiranjan-patra/wavetune/blob/main/helpers/library/songs.ts): normalization · Transforms raw track data into library models. · `helpers/library/songs.ts`
- [Search](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/search/search.service.ts): query service · Queries the persisted library index. · `services/search/search.service.ts`

### Persistence

Local database repositories and storage boundary.

- [Database](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/database.service.ts): local store · Persistence boundary for the indexed library. · `services/database/database.service.ts`
- [Songs repo](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/songs.repository.ts): repository · Song persistence and retrieval. · `services/database/songs.repository.ts`
- [Albums repo](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/albums.repository.ts): repository · Album persistence and retrieval. · `services/database/albums.repository.ts`
- [Artists repo](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/database/artists.repository.ts): repository · Artist persistence and retrieval. · `services/database/artists.repository.ts`

### Playback

Player initialization, queueing, and transport control.

- [Player service](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/player.service.ts): playback core · Coordinates playback behavior and player state. · `services/player/player.service.ts`
- [Queue](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/queue.service.ts): playback queue · Builds and advances the play queue. · `services/player/queue.service.ts`
- [Playback control](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/playback.service.ts): transport · Handles play, pause, skip, and other transport actions. · `services/player/playback.service.ts`
- [Player setup](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/setup.service.ts): initialization · Initializes native playback runtime. · `services/player/setup.service.ts`
- [Player mapper](https://github.com/smrutiranjan-patra/wavetune/blob/main/services/player/mapper.ts): mapping · Converts library entities to playable items. · `services/player/mapper.ts`

## Connections

- Root layout → App provider: composes · Root composition wires global app services.
- Root layout → Tabs layout: hosts · Root layout renders the main navigation surface.
- Tabs layout → Home: routes to · Primary tab landing screen.
- Tabs layout → Library layout: routes to · Nested library navigation.
- Root layout → Player: routes to · Full-screen player route is mounted separately.
- Home → Mini player: uses · Home screen participates in persistent playback UI.
- Player → Player store: reads · Playback screen reflects current player state.
- Mini player → Player store: reads · Compact player reflects current playback state.
- App provider → App store: initializes · Global app state is prepared at startup.
- App provider → Media permission: requests · Provider coordinates media permission flow.
- App provider → Player setup: initializes · Provider prepares player runtime.
- Media permission → Scanner permissions: delegates to · Hook uses Android permission helpers.
- Scanner permissions → Scanner: unlocks · Permission checks gate scanning.
- Scanner → Media source: reads from · Scanner pulls local device media.
- Scanner → Metadata: parses with · Scanner enriches tracks with metadata.
- Metadata → Library metadata: feeds · Parsed metadata is adapted to library entities.
- Library service → Library scanner: orchestrates · Library refresh is coordinated through the library domain.
- Library scanner → Scanner: uses · Library scanner triggers the device scan.
- Library service → Database: persists to · Normalized catalog is written to local storage.
- Library metadata → Song helpers: normalizes · Library domain helpers shape song entities.
- Song helpers → Library store: updates · Normalized entities flow into library state.
- Database → Songs repo: exposes · Database boundary includes song repository.
- Database → Albums repo: exposes · Database boundary includes album repository.
- Database → Artists repo: exposes · Database boundary includes artist repository.
- Library store → Search: feeds · Search queries the persisted catalog state.
- Library store → Library handlers: mutates via · Library state changes are centralized in handlers.
- Player service → Queue: coordinates · Player core manages queue behavior.
- Player service → Playback control: drives · Core player delegates transport actions.
- Player service → Player mapper: maps through · Library items are converted to playable entries.
- Player service → Player store: updates · Playback state is mirrored into the store.
- Player service → Player setup: depends on · Player core relies on initialization.
- Search → Library store: queries · Search reads the indexed library model.
- Library layout → Library store: reads · Library browsing screens consume catalog state.
