compose-architecture
Skill0 starsChanged 33 days agoMITView on GitHub
Jetpack Compose architecture discipline: layer separation, unidirectional data flow, ViewModel construction and coroutine scopes, lifecycle-aware state collection. Use when creating screens, wiring state holders to composables, or reviewing UI-layer structure. Core rules have machine checks in checks/.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Meet-Miyani/compose-skilltheir own version, first seen Oct 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Meet-Miyani/compose-skill★ 303same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- android-testingSkill
- compose-migrationSkill
- compose-multiplatformSkill
- compose-performanceSkill
- compose-testingSkill
- dependency-injectionSkill
- gradle-build-logicSkill
- kmp-fundamentalsSkill
- material3-themingSkill
- offline-firstSkill
- release-engineeringSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
After ANY screen or state-holder edit, run the Verification step (bottom of this file).
- Very specific: line 20
MUST read UI state from a state holder: a ViewModel for screen UI state, a @Stable plain class for UI logic.
- Very specific: line 47
MUST pass child composables plain state + event lambdas.
- Very specific: line 73
MUST obtain ViewModels via viewModel() / hiltViewModel() (or DI scoped with SavedStateHandle).
- Very specific: line 88
MUST NOT use GlobalScope in UI code — its lifetime is unmanaged and outlives the screen.
- Very specific: line 104
MUST collect state-holder flows with collectAsStateWithLifecycle() (androidx.lifecycle:lifecycle-runtime-compose).
- Distinctive: line 123
Run after every screen or state-holder edit (from the project root):
- Distinctive: line 132
All four must pass (exit 0) before declaring the task done.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Compose Architecture
Operational rules for a coding agent. RIGHT/WRONG pairs are canonical. After ANY screen or state-holder edit, run the Verification step (bottom of this file).
1. Layer separation
MUST read UI state from a state holder: a ViewModel for screen UI state, a
@Stable plain class for UI logic. MUST NOT import or call the data layer
(Room DAOs, Retrofit services, DataStore, *Repository) from any file that
declares a @Composable.
WRONG:
@Composable
fun FeedScreen() {
val posts = remember { postsRepository.posts() } // data layer in UI
}RIGHT:
@Composable
fun FeedScreen(viewModel: FeedViewModel = viewModel()) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
}WHY: dependencies point downward only (UI → state holder → domain → data). A composable that reaches into the data layer bypasses the single source of truth, loses config-change retention, and cannot be previewed or unit-tested.
2. Unidirectional data flow
MUST pass child composables plain state + event lambdas. MUST NOT pass a ViewModel instance down into a reusable composable ("Don't pass ViewModel instances down to other composable functions" — official guidance, see references/architecture.md #3).
WRONG:
@Composable
fun Feed(viewModel: FeedViewModel) {
FeedItem(item = viewModel.selected, onClick = { viewModel.toggle() })
}RIGHT:
@Composable
fun Feed(uiState: FeedUiState, onToggle: (String) -> Unit) {
FeedItem(item = uiState.selected, onClick = { onToggle(uiState.id) })
}Events travel up to the screen-level composable that owns the ViewModel; that composable is the single source of truth for handling the event.
3. ViewModel construction & coroutine scopes
MUST obtain ViewModels via viewModel() / hiltViewModel() (or DI scoped
with SavedStateHandle). MUST NOT construct one inside a composable — a
manual FooViewModel() call creates a fresh instance per composition, with
no retention and no sharing.
WRONG:
val viewModel = FeedViewModel()RIGHT:
val viewModel: FeedViewModel = viewModel()MUST NOT use GlobalScope in UI code — its lifetime is unmanaged and
outlives the screen. Use rememberCoroutineScope() inside event callbacks
and LaunchedEffect(key) for effects keyed to composition.
WRONG:
GlobalScope.launch { analytics.logOpen(screen) }RIGHT:
LaunchedEffect(Unit) { analytics.logOpen(screen) }4. Lifecycle-aware state collection
MUST collect state-holder flows with collectAsStateWithLifecycle()
(androidx.lifecycle:lifecycle-runtime-compose). Plain collectAsState()
keeps collecting while the UI is stopped, wasting resources.
WRONG:
val uiState by viewModel.uiState.collectAsState()RIGHT:
val uiState by viewModel.uiState.collectAsStateWithLifecycle()Plain collectAsState() is allowed only in KMP-common code where the
Android lifecycle API is unavailable; leave a comment at the call site.
Verification
Run after every screen or state-holder edit (from the project root):
bash <skill-dir>/checks/check_no_data_layer_in_ui.sh <src-dir>
bash <skill-dir>/checks/check_viewmodel_construction.sh <src-dir>
bash <skill-dir>/checks/check_no_global_scope.sh <src-dir>
bash <skill-dir>/checks/check_collect_as_state_lifecycle.sh <src-dir>All four must pass (exit 0) before declaring the task done. Checks are deterministic import/call-site heuristics — they catch the documented anti-patterns above, not every architecture violation. The parameter shape of §2 is verified by review against references/architecture.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

