name: android-conventions
description: |
Defines Android/Kotlin coding conventions for the project. Includes naming
rules, forbidden patterns, preferred practices, and code style guidelines.
Use when writing code to ensure consistency. Use when user mentions:
네이밍, 컨벤션, 코딩 규칙, 스타일 가이드, 금지 패턴, 권장 패턴,
이름 규칙, 코드 스타일, 컨벤션 확인, 네이밍 규칙.
allowed-tools: Read, Glob, Grep
// ❌ Don't
val items = mutableListOf<Item>() // Public mutable
GlobalScope.launch { ... }
runBlocking { ... }
// ✅ Do
val items: List<Item> get() = _items.toList() // Immutable copy
viewModelScope.launch { ... }
suspend fun doSomething() { ... }
Preferred Patterns
✅ 권장 패턴
Pattern
Usage
invoke operator
UseCase entry point
Result<T>
Error handling
State hoisting
Compose state management
Immutable data class
Domain models
suspend functions
One-shot operations
Flow
Data streams
Modifier first optional
Composable parameters
Code Examples
// ✅ UseCase with invoke
class GetDataUseCase @Inject constructor(...) {
suspend operator fun invoke(id: String): Result<Data> = ...
}
// ✅ Result type for errors
suspend fun getData(): Result<Data> = runCatching {
repository.fetchData()
}
// ✅ Immutable data class
data class LottoResult(
val round: Int,
val numbers: List<Int>, // List is immutable interface
val bonusNumber: Int
)
// ✅ Modifier as first optional parameter
@Composable
fun MyComponent(
text: String, // Required
modifier: Modifier = Modifier, // First optional
enabled: Boolean = true // Other optionals
)
Architecture Rules
Layer Dependencies
✅ Allowed:
Presentation → Domain
Data → Domain
❌ Forbidden:
Domain → Data
Domain → Presentation
Presentation → Data (direct)
// ✅ Explicit imports (preferred)
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.MutableStateFlow
// ⚠️ Star imports (avoid when possible)
import kotlinx.coroutines.flow.*
Formatting
// ✅ Parameter on new line when many
fun createViewModel(
useCase1: UseCase1,
useCase2: UseCase2,
repository: Repository
): ViewModel
// ✅ Chain calls vertically
repository.getData()
.map { it.toDomain() }
.catch { emit(emptyList()) }
.collect { ... }
Comments
// ✅ KDoc for public APIs
/**
* Fetches lotto result for the given round.
*
* @param round The round number to fetch
* @return Result containing LottoResult or error
*/
suspend fun getLottoResult(round: Int): Result<LottoResult>
// ✅ Explain WHY, not WHAT
// Cache for 5 minutes to reduce API calls during rapid navigation
private val cache = CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.MINUTES)
.build()
// ❌ Don't explain obvious code
// Increment counter by 1
counter++