android-compose-architecture-review
Compose Architecture Review
When to Use This Skill:
- Reviewing EXISTING Compose screens/ViewModels
- Code review for architectural violations
- Refactoring guidance for specific files
- Validating state management patterns
When to Use
project-architecture-analyst-androidAgent Instead:
- Planning NEW features (uncertain file placement)
- Understanding project-wide architecture
- Major changes affecting multiple modules
- Need to discover existing patterns before implementing
Review Checklist
Separation of Concerns
- Composables: presentation only (no business logic, network, DB)
- ViewModels: state + business logic (StateFlow, events)
- Repository/UseCase: data access separated from UI
State Management
remember- composable-local state onlyrememberSaveable- survive config changesViewModelwithStateFlow/MutableStateFlow- screen statecollectAsStateWithLifecycle()- lifecycle-aware collectionderivedStateOf- computed state from other state- CompositionLocal - shared read-only state
- Use unidirectional data flow: state flows down, events flow up
- Prefer stateless composables (receive value + onChange callbacks)
- Use plain state-holder classes for complex state not tied to lifecycle
- Prefer side effects via
LaunchedEffect(async work),DisposableEffect(cleanup),SideEffect(framework integration),produceState,rememberCoroutineScope, orsnapshotFlowrather than arbitrary side effects in composable bodies - Use
SavedStateHandlefor persistent state across process death
State Lifecycle Issues
- No leaked ViewModels (use viewModel() or hiltViewModel())
- Proper cleanup in ViewModel.onCleared()
- StateFlow collected with lifecycle awareness
- No unnecessary state hoisting
Dependency Injection
- Dependencies injected (check project: Koin, Hilt, Dagger, or manual)
- No hardcoded singletons in composables
- ViewModels receive dependencies via constructor
Composable Design
- Composables are small (single responsibility)
- Complex screens broken into components
- Reusable components extracted
- Stateless composables preferred (state hoisting)
Common Issues
| Issue | Fix |
|---|---|
| Business logic in composable | Extract to ViewModel |
| Network call in composable | Move to ViewModel with LaunchedEffect |
| Singleton in composable | Inject via DI or CompositionLocal |
| 200+ line composable | Break into smaller components |
| State not hoisted | Hoist to parent or ViewModel |
| Side effects or network calls directly in composable | Wrap in LaunchedEffect(key) { ... } or move to ViewModel |
| Stateful composable when stateless would suffice | Hoist state and pass value + lambda |
State Hoisting Pattern
Composable receives: value: T, onValueChange: (T) -> Unit
ViewModel holds: MutableStateFlow<T>
Severity
- 🔴 Critical: Architecture violation
- 🟡 Improvement: Better pattern available
- 🟢 Enhancement: Optional optimization
More from desquared/agents-rules-skills
shared-bug-investigation
Scientific method expert for systematic bug investigation and root cause analysis. Use when users report bugs, crashes, unexpected behavior, or debugging requests. Applies hypothesis-driven investigation, controlled experiments, and rigorous validation across any programming language or platform.
23android-performance-profiler
Identifies potential performance bottlenecks in Jetpack Compose code including expensive recompositions, unnecessary redraws, and memory issues. Use when code involves lists, animations, complex UI, or when the user asks about performance optimization.
19ios-swiftui-architecture-review
Analyze SwiftUI view hierarchies and suggest MVVM or other architectural improvements. Use when **reviewing existing SwiftUI code**, creating new SwiftUI components, analyzing view structure, or when the user asks about SwiftUI architecture patterns. Best for code review and refactoring guidance.
13android-accessibility-validator
Checks and suggests accessibility improvements for Jetpack Compose and Android Views including TalkBack labels, dynamic text support, and color contrast. Use when creating or modifying UI components, screens, or when the user asks about accessibility.
12android-kotlin-api-design-reviewer
Review function and class interfaces for Kotlin Coding Conventions compliance. Use when creating public APIs, reusable components, library interfaces, or when the user asks for API design review or Kotlin naming conventions.
11flutter-performance-optimizer
Use when Flutter UI has jank, slow scrolling, excessive rebuilds, or memory leaks. Also use when optimizing lists, animations, or complex widget trees, or when the user asks about Flutter rendering performance.
10