home / skills / pluginagentmarketplace / custom-plugin-android / architecture

architecture skill

/skills/architecture

This skill helps implement MVVM, Clean Architecture, and SOLID principles in Android apps using repository and dependency injection for robust, testable code.

npx playbooks add skill pluginagentmarketplace/custom-plugin-android --skill architecture

Review the files below or copy the command above to add this skill to your agents.

Files (8)
SKILL.md
2.5 KB
---
name: architecture
description: MVVM pattern, Clean Architecture, Repository pattern, dependency injection, SOLID principles.
version: "2.0.0"
sasmp_version: "1.3.0"

# Agent Binding
bonded_agent: 06-architecture
bond_type: PRIMARY_BOND

# Skill Configuration
atomic: true
single_responsibility: App architecture & design patterns

# Parameter Validation
parameters:
  pattern:
    type: string
    enum: [mvvm, clean_architecture, repository, di]
    required: false
  complexity:
    type: string
    enum: [simple, medium, complex]
    default: medium

# Retry Configuration
retry:
  max_attempts: 2
  backoff: exponential
  on_failure: suggest_simpler_pattern

# Observability
logging:
  level: info
  include: [pattern_type, layer, dependencies]
---

# App Architecture Skill

## Quick Start

### MVVM Pattern
```kotlin
@HiltViewModel
class UserViewModel @Inject constructor(
    private val repository: UserRepository
) : ViewModel() {
    private val _state = MutableLiveData<UiState>()
    val state: LiveData<UiState> = _state
    
    fun loadUser(id: Int) {
        viewModelScope.launch {
            _state.value = repository.getUser(id)
        }
    }
}
```

### Repository Pattern
```kotlin
interface UserRepository {
    suspend fun getUser(id: Int): User
}

class UserRepositoryImpl(
    private val dao: UserDao,
    private val api: UserApi
) : UserRepository {
    override suspend fun getUser(id: Int): User {
        return dao.getUser(id) ?: api.fetchUser(id)
    }
}
```

### Dependency Injection (Hilt)
```kotlin
@Module
@InstallIn(SingletonComponent::class)
object RepositoryModule {
    @Provides
    fun provideUserRepository(dao: UserDao, api: UserApi): UserRepository {
        return UserRepositoryImpl(dao, api)
    }
}
```

## Key Concepts

### MVVM Benefits
- Lifecycle awareness
- Configuration change handling
- Separation of concerns
- Testability

### Clean Architecture Layers
- Domain: Business rules
- Application: Use cases
- Presentation: UI
- Infrastructure: Data sources

### SOLID Principles
- S: Single Responsibility
- O: Open/Closed
- L: Liskov Substitution
- I: Interface Segregation
- D: Dependency Inversion

## Best Practices

✅ Dependency injection
✅ Interface-based design
✅ Layered architecture
✅ Single responsibility
✅ Testable code

## Resources

- [Architecture Guide](https://developer.android.com/jetpack/guide)
- [SOLID Principles](https://en.wikipedia.org/wiki/SOLID)
- [Hilt Documentation](https://developer.android.com/training/dependency-injection/hilt-android)

Overview

This skill provides concise guidance and examples for building Android apps using MVVM, Clean Architecture, the Repository pattern, dependency injection, and SOLID principles. It focuses on practical code patterns, module boundaries, and testable abstractions to help teams scale and maintain projects. The content is oriented toward Android developers integrating these patterns with Kotlin and DI frameworks like Hilt.

How this skill works

The skill inspects typical architectural layers and shows how to organize responsibilities across domain, application, presentation, and infrastructure. It demonstrates wiring repositories to ViewModels, defining interfaces for data sources, and providing DI modules to assemble implementations. Example snippets illustrate coroutine usage in ViewModelScope, repository fallbacks between local DAO and remote API, and Hilt provider modules.

When to use it

  • Starting a new Android app to establish a maintainable architecture
  • Refactoring a monolithic codebase into clear layers and testable units
  • Implementing dependency injection to manage lifetime and replaceable implementations
  • Designing offline-first apps that combine local DAO and remote API access
  • Enforcing SOLID principles across teams for clearer ownership and easier testing

Best practices

  • Define clear layer boundaries: domain, application/use-cases, presentation, infrastructure
  • Program to interfaces: expose repositories and use-cases as abstractions
  • Use dependency injection for wiring and to enable easy replacement in tests
  • Keep ViewModels free of heavy logic; delegate business rules to use-cases or domain services
  • Write small, single-responsibility classes and keep side effects at the infrastructure layer
  • Prefer suspend functions and structured concurrency (viewModelScope) for async work

Example use cases

  • User profile flow: ViewModel calls UserRepository which queries local DAO then falls back to remote API
  • Onboarding: orchestrate use-cases for registration, persistence, and navigation in presentation layer
  • Caching strategy: implement repository that merges API responses and local cache with TTL
  • Feature toggle rollout: swap repository implementation via DI for different backend behavior
  • Unit testing: provide fake repositories or DAOs via DI to validate ViewModel and use-case logic

FAQ

How do I choose what goes in domain vs application layers?

Keep pure business rules and entities in domain; put orchestration and app-specific use-cases in the application layer that call domain logic and coordinate repositories.

When should I create a repository interface?

Create an interface when you need to decouple data access from callers, support multiple data sources, or enable test doubles. If data access is trivial and unlikely to change, a direct DAO may suffice.