android-architecture
Use when implementing MVVM, clean architecture, dependency injection with Hilt, or structuring Android app layers.
What this skill does
# Android - Architecture
Modern Android architecture patterns following Google's recommended practices.
## Key Concepts
### MVVM Architecture
Model-View-ViewModel separates UI from business logic:
```kotlin
// UI State
data class UserUiState(
val user: User? = null,
val isLoading: Boolean = false,
val error: String? = null
)
// ViewModel
class UserViewModel(
private val userRepository: UserRepository
) : ViewModel() {
private val _uiState = MutableStateFlow(UserUiState())
val uiState: StateFlow<UserUiState> = _uiState.asStateFlow()
fun loadUser(userId: String) {
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true, error = null) }
userRepository.getUser(userId)
.onSuccess { user ->
_uiState.update { it.copy(user = user, isLoading = false) }
}
.onFailure { error ->
_uiState.update { it.copy(error = error.message, isLoading = false) }
}
}
}
}
// Composable
@Composable
fun UserScreen(viewModel: UserViewModel = hiltViewModel()) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
when {
uiState.isLoading -> LoadingIndicator()
uiState.error != null -> ErrorMessage(uiState.error!!)
uiState.user != null -> UserContent(uiState.user!!)
}
}
```
### Clean Architecture Layers
```
app/
├── data/
│ ├── local/ # Room database, DataStore
│ │ ├── dao/
│ │ └── entities/
│ ├── remote/ # Retrofit, network
│ │ ├── api/
│ │ └── dto/
│ └── repository/ # Repository implementations
├── domain/
│ ├── model/ # Domain models
│ ├── repository/ # Repository interfaces
│ └── usecase/ # Business logic
└── presentation/
├── ui/ # Composables
└── viewmodel/ # ViewModels
```
### Repository Pattern
```kotlin
// Domain layer - interface
interface UserRepository {
fun getUser(id: String): Flow<User>
suspend fun saveUser(user: User): Result<Unit>
suspend fun deleteUser(id: String): Result<Unit>
}
// Data layer - implementation
class UserRepositoryImpl(
private val userApi: UserApi,
private val userDao: UserDao
) : UserRepository {
override fun getUser(id: String): Flow<User> = flow {
// Emit cached data first
userDao.getUser(id)?.let { emit(it.toDomain()) }
// Fetch fresh data
try {
val remoteUser = userApi.getUser(id)
userDao.insertUser(remoteUser.toEntity())
emit(remoteUser.toDomain())
} catch (e: Exception) {
// Network error, cached data already emitted
}
}
override suspend fun saveUser(user: User): Result<Unit> = runCatching {
userApi.updateUser(user.toDto())
userDao.insertUser(user.toEntity())
}
}
```
## Best Practices
### Dependency Injection with Hilt
```kotlin
// Module definition
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun provideRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.API_BASE_URL)
.addConverterFactory(MoshiConverterFactory.create())
.build()
}
@Provides
@Singleton
fun provideUserApi(retrofit: Retrofit): UserApi {
return retrofit.create(UserApi::class.java)
}
}
@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindUserRepository(impl: UserRepositoryImpl): UserRepository
}
// ViewModel injection
@HiltViewModel
class UserViewModel @Inject constructor(
private val getUserUseCase: GetUserUseCase,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {
private val userId: String = savedStateHandle.get<String>("userId")
?: throw IllegalArgumentException("userId required")
// ViewModel implementation
}
```
### Use Cases for Business Logic
```kotlin
class GetUserUseCase @Inject constructor(
private val userRepository: UserRepository,
private val analyticsTracker: AnalyticsTracker
) {
operator fun invoke(userId: String): Flow<Result<User>> = flow {
emit(Result.Loading)
userRepository.getUser(userId)
.catch { e ->
analyticsTracker.trackError("get_user_failed", e)
emit(Result.Error(e))
}
.collect { user ->
emit(Result.Success(user))
}
}
}
// Sealed class for results
sealed class Result<out T> {
data class Success<T>(val data: T) : Result<T>()
data class Error(val exception: Throwable) : Result<Nothing>()
object Loading : Result<Nothing>()
}
```
### Room Database Setup
```kotlin
@Entity(tableName = "users")
data class UserEntity(
@PrimaryKey val id: String,
val name: String,
val email: String,
@ColumnInfo(name = "created_at") val createdAt: Long
)
@Dao
interface UserDao {
@Query("SELECT * FROM users WHERE id = :id")
suspend fun getUser(id: String): UserEntity?
@Query("SELECT * FROM users ORDER BY name ASC")
fun getAllUsers(): Flow<List<UserEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertUser(user: UserEntity)
@Delete
suspend fun deleteUser(user: UserEntity)
}
@Database(entities = [UserEntity::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): UserDao
}
// Hilt module
@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java,
"app_database"
).build()
}
@Provides
fun provideUserDao(database: AppDatabase): UserDao {
return database.userDao()
}
}
```
### Data Mapping
```kotlin
// DTO (Data Transfer Object) - from API
data class UserDto(
@Json(name = "id") val id: String,
@Json(name = "full_name") val fullName: String,
@Json(name = "email_address") val email: String
)
// Entity - for Room
@Entity(tableName = "users")
data class UserEntity(
@PrimaryKey val id: String,
val name: String,
val email: String
)
// Domain model
data class User(
val id: String,
val name: String,
val email: String
)
// Mappers
fun UserDto.toEntity() = UserEntity(
id = id,
name = fullName,
email = email
)
fun UserDto.toDomain() = User(
id = id,
name = fullName,
email = email
)
fun UserEntity.toDomain() = User(
id = id,
name = name,
email = email
)
fun User.toEntity() = UserEntity(
id = id,
name = name,
email = email
)
```
## Common Patterns
### Single Source of Truth
```kotlin
class OfflineFirstRepository @Inject constructor(
private val api: ItemApi,
private val dao: ItemDao
) : ItemRepository {
override fun getItems(): Flow<List<Item>> {
return dao.getAllItems()
.map { entities -> entities.map { it.toDomain() } }
.onStart {
// Refresh from network in background
refreshItems()
}
}
private suspend fun refreshItems() {
try {
val remoteItems = api.getItems()
dao.deleteAll()
dao.insertAll(remoteItems.map { it.toEntity() })
} catch (e: Exception) {
// Log error, local data still available
}
}
}
```
### Navigation with Type-Safe Args
```kotlin
// Define routes
sealed class Screen(val route: String) {
object Home : Screen("home")
object Detail : Screen("detail/{itemId}") {
fun createRoute(itemId: String) = "detail/$itemId"
}
object Settings : Screen("settings")
}
// Navigation setup
@Composable
fun AppNavigation(navController: NavHostControlleRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.