|
| 1 | +--- |
| 2 | +alwaysApply: false |
| 3 | +--- |
| 4 | +For every Kotlin Android code you generate or refactor: |
| 5 | + |
| 6 | +1. **Architecture:** |
| 7 | + - Follow **MVVM pattern** strictly. |
| 8 | + - Business logic must go into `ViewModel`, not in `View` (Activity/Fragment/Composable). |
| 9 | + - Views should only observe `StateFlow`/`LiveData` from ViewModel. |
| 10 | + |
| 11 | +2. **Kotlin Best Practices:** |
| 12 | + - Use `StateFlow` instead of `LiveData` unless explicitly required. |
| 13 | + - Use Kotlin Coroutines (structured concurrency, `viewModelScope`, `SupervisorJob`). |
| 14 | + - Prefer `val` over `var` where possible. |
| 15 | + - Use extension functions and sealed classes when appropriate. |
| 16 | + - No memory leaks (avoid context leaks in ViewModel). |
| 17 | + - Use Dependency Injection (Hilt) if necessary. |
| 18 | + |
| 19 | +3. **Android Performance:** |
| 20 | + - Avoid heavy work on the main thread. |
| 21 | + - Use `Dispatchers.IO` or background coroutines for I/O, disk, and network tasks. |
| 22 | + - Use `lazy` initialization where suitable. |
| 23 | + - For RecyclerView/List: use `ListAdapter` + `DiffUtil`. |
| 24 | + - Avoid unnecessary recomposition in Jetpack Compose. |
| 25 | + - Apply LRU caching for repeated data/images if needed. |
| 26 | + |
| 27 | +4. **Testing:** |
| 28 | + - Generated ViewModel and Repository code must be testable (no static singletons). |
| 29 | + - Show sample unit test if introducing new logic. |
| 30 | + |
| 31 | +5. **Code Quality:** |
| 32 | + - Minimize code duplication. |
| 33 | + - Clear function separation (Single Responsibility Principle). |
| 34 | + - Provide brief inline comments for complex sections. |
| 35 | + |
| 36 | +6. **Output Requirement:** |
| 37 | + - Provide **full code samples** (including imports) unless specified otherwise. |
| 38 | + - Brief explanation of key design decisions made. |
0 commit comments