android-architecture
БесплатноБез исполняемых скриптовНе проверенUse when implementing MVVM, clean architecture, dependency injection with Hilt, or structuring Android app layers.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Android - Architecture
Modern Android architecture patterns following Google's recommended practices.
Key Concepts
MVVM Architecture
Model-View-ViewModel separates UI from business logic:
// 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
// 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
// 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
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
@Entity(tableName = "users")
data class UserEntity(
@PrimaryKey val id: String,
val name: String,
val email: String,
@ColumnInfo(name = "cr
Установить android-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGrepGlobFAQ
Что делает скилл android-architecture?
Use when implementing MVVM, clean architecture, dependency injection with Hilt, or structuring Android app layers.
Как установить скилл android-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл android-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic