118 lines
5.2 KiB
Markdown
118 lines
5.2 KiB
Markdown
# CLAUDE.md
|
||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this
|
||
repository.
|
||
|
||
## Project Overview
|
||
|
||
AudioVibe is an Android audio editing and voice changer app targeting international markets. Built
|
||
with Kotlin and Jetpack Compose, it provides audio tag editing, voice changing, audio cutting, and a
|
||
music library manager with support for 100+ audio formats.
|
||
|
||
## Build & Test Commands
|
||
|
||
```bash
|
||
# Build the project
|
||
./gradlew assembleDebug
|
||
|
||
# Run all unit tests (JVM, no device needed)
|
||
./gradlew test
|
||
|
||
# Run a single test class
|
||
./gradlew test --tests "com.audio.vibe.data.repository.MediaStoreMusicSelectionTest"
|
||
|
||
# Run a single test method
|
||
./gradlew test --tests "com.audio.vibe.data.repository.AudioScanFingerprintTest.someMethod"
|
||
|
||
# Run instrumented tests (requires connected device/emulator)
|
||
./gradlew connectedAndroidTest
|
||
|
||
# Run lint checks
|
||
./gradlew lint
|
||
|
||
# Clean build
|
||
./gradlew clean assembleDebug
|
||
```
|
||
|
||
## Architecture
|
||
|
||
Single-module project (`app/`) following MVVM with clean architecture layers:
|
||
|
||
```
|
||
ui/ — Compose screens & ViewModels (state: sealed interface + @Immutable data class)
|
||
domain/ — Models (ScannedAudioTrack, PlaybackTrack) + repository interfaces
|
||
data/ — Repository impls, Room DB, ExoPlayer/FFmpeg playback, DataStore preferences
|
||
common/ — Shared utilities (MetadataTextRepair, etc.)
|
||
```
|
||
|
||
### Key Layers
|
||
|
||
**Navigation** (`MainActivity.kt`): Single-Activity, NavHost-based routing with 6 destinations:
|
||
home, editor, voice, cutter, music, settings, premium.
|
||
|
||
**i18n** (`ui/i18n/AppLanguage.kt`): 23 languages via Android string resources. `AppStrings` data
|
||
class holds all translatable strings, provided through `CompositionLocal`. Language selection
|
||
persisted in DataStore (`LanguagePreferences`).
|
||
|
||
**Music Scanner** (`data/repository/MediaStoreMusicScannerRepository.kt`):
|
||
|
||
- Scans via MediaStore API (Android 10+) and SAF `OpenDocumentTree` for external storage
|
||
- Dual-metadata pipeline: jaudiotagger for common formats, FFprobe for exotic formats (WV, APE, DSD,
|
||
etc.) with automatic fallback merging
|
||
- Producer-worker-collector coroutine pattern with configurable parallelism for metadata parsing
|
||
- Room FTS4 for full-text search with prefix-matching
|
||
- Fingerprint-based incremental scanning (size + dateModified comparison)
|
||
|
||
**Room Database** (`data/local/MusicLibraryDatabase.kt`):
|
||
|
||
- `music_tracks` table indexed by source_path (unique), title, artist, album, format, date_modified
|
||
- `music_tracks_fts` FTS4 virtual table for searching
|
||
- Paging 3 integration via `PagingSource` DAO methods
|
||
- `fallbackToDestructiveMigration(true)` — schema at version 3
|
||
|
||
**Playback** (`data/playback/`):
|
||
|
||
- `AudioPlaybackService` — foreground service for background playback
|
||
- `AudioPlaybackController` — dual-backend: Media3 ExoPlayer (primary) + FFmpeg PCM → AudioTrack (
|
||
fallback for exotic formats, 8/24/64-bit PCM, non-standard sample rates)
|
||
- `PlaybackServiceController` interface decouples ViewModel from the service
|
||
|
||
**State Management**: ViewModel exposes `StateFlow<UiState>`, UI collects via `collectAsState()`.
|
||
Events dispatched through sealed interface `MusicManagerEvent`. Unidirectional data flow strictly
|
||
enforced.
|
||
|
||
### Tech Stack
|
||
|
||
| Component | Library |
|
||
|----------------------|-----------------------------------------------|
|
||
| UI | Jetpack Compose + Material 3 (BOM 2026.02.01) |
|
||
| Navigation | Navigation Compose 2.9.8 |
|
||
| Database | Room 2.8.3 + KSP |
|
||
| Paging | Paging 3 + Paging Compose |
|
||
| Preferences | DataStore Preferences |
|
||
| Playback | Media3 ExoPlayer 1.10.0 |
|
||
| FFmpeg | ffmpeg-kit-min 6.0.1 |
|
||
| Metadata | jaudiotagger 3.0.1 |
|
||
| Logging | Timber 5.0.1 |
|
||
| Min SDK / Target SDK | 26 / 36 |
|
||
| Kotlin / AGP | 2.2.10 / 9.1.1 |
|
||
|
||
## Coding Rules
|
||
|
||
1. 输出生产级高质量代码,严格遵循官方 MVVM 干净架构。
|
||
2. 强制使用协程、Flow、StateFlow,全程禁止使用 LiveData。
|
||
3. 严格遵守 Compose 状态提升、UiState 不可变、密封类管理页面状态。
|
||
4. 自动优化 Compose 重组,合理使用 remember、derivedStateOf。
|
||
5. 固定技术栈:Retrofit、Room、DataStore。
|
||
6. 可安全重构代码、修复潜在内存泄漏、做性能优化。
|
||
7. 统一编码风格与命名规范,只允许使用 Timber 日志,禁用原生 Log。
|
||
8. 禁止使用废弃 API,全程纯 Compose,不生成 XML 布局。
|
||
9. 遵循最小改动原则,不擅自大规模重构原有项目结构和代码风格。
|
||
10. 单向数据流:UI → 事件 → ViewModel → 状态 → UI
|
||
11. ViewModel 不持有 Context、不直接操作视图
|
||
12. 仓库为唯一数据源,UI 不直连网络/数据库
|
||
13. 耗时操作统一 Dispatchers.IO,使用 viewModelScope
|
||
14. 严格空安全,禁止滥用 !!
|
||
15. 禁止硬编码文字、尺寸、颜色,统一引用资源
|
||
16. 所有对话中文回答,遵循现有代码风格,所有的注释都要中文标注
|