kotlin-android-data-flow-and-api-pitfalls
Step 5 of the pipeline (WORKFLOW.md), for Kotlin on Android and shared Kotlin code. The premise: a repository
that returns a snapshot, a view model that exposes a cold flow, or an extension function that hides a
dependency each works in the first screen and rots by the fifth, because the data can change under the
caller, the UI cannot show every state, and nobody owns the behaviour. Android edge-to-edge and security rules
are android-edge-to-edge-insets and android-security-hardening; the Gradle and R8 side is
android-agp9-r8-gradle.
When
- A repository, data source, view model or UI state class is added or its shape changes.
- A background sync, a local database or a remote source is wired to the screen.
- A Kotlin extension function, a factory, a one-field wrapper type or an
expect declaration is added.
Steps
Read only the part the task meets. They are independent.
| Part |
Covers |
Read it when |
File |
| 1 |
Android data flow: layers, offline-first reads, writes, sync, UI state, state flows, events |
a repository, a view model or a screen state is written |
01-android-data-flow.md |
| 2 |
Kotlin API design: function ownership, value classes versus data classes, multiplatform boundaries |
an extension, a factory, a wrapper type or a platform seam is added |
02-kotlin-api-design.md |
Output / checkpoint
Each repository method says whether it returns a stream or performs a write, each screen state is a closed
hierarchy the UI handles exhaustively, and each new function names its semantic owner. A claim that a screen
"handles loading and errors" without naming the state type that carries them is not verified.
Guardrails
- Never expose repository reads as one-shot snapshots when the data can change (part 1).
- Never add an extension on a standard or framework type that hides parsing, repository access or clock policy
(part 2).
- Never put a platform type in a common signature (part 2).
- No block and no agent installs a library: the blocks name it and the user installs it (
CONVENTIONS.md).
- Versions: the rules are architecture guidance, not API reference; each names its source. Nothing was built
or run while writing this block.
Origin
Rewritten from the Now in Android architecture guide (Apache-2.0) and the Kotlin API design skill of the
chrisbanes skills repository (Apache-2.0), read 2026-10-16. Overlaps with skills/kotlin-android-conventions (2026-10-19); cross-referenced, not merged. 🟡: never run by us; open
points are in references/origin.md.
1---2name: kotlin-android-data-flow-and-api-pitfalls3description: "Use when structuring an Android app's data and UI layers or designing Kotlin APIs: offline-first repositories, flows instead of snapshots, sealed UI state, state flows in view models, sync with backoff, and where Kotlin functions, value classes and multiplatform platform boundaries belong."4metadata:5 source: https://skillmd.com/skills/techmefr/kotlin-android-data-flow-and-api-pitfalls6---78# kotlin-android-data-flow-and-api-pitfalls910Step 5 of the pipeline (`WORKFLOW.md`), for Kotlin on Android and shared Kotlin code. The premise: **a repository11that returns a snapshot, a view model that exposes a cold flow, or an extension function that hides a12dependency each works in the first screen and rots by the fifth**, because the data can change under the13caller, the UI cannot show every state, and nobody owns the behaviour. Android edge-to-edge and security rules14are `android-edge-to-edge-insets` and `android-security-hardening`; the Gradle and R8 side is15`android-agp9-r8-gradle`.1617## When18- A repository, data source, view model or UI state class is added or its shape changes.19- A background sync, a local database or a remote source is wired to the screen.20- A Kotlin extension function, a factory, a one-field wrapper type or an `expect` declaration is added.2122## Steps2324**Read only the part the task meets.** They are independent.2526| Part | Covers | Read it when | File |27|---|---|---|---|28| 1 | Android data flow: layers, offline-first reads, writes, sync, UI state, state flows, events | a repository, a view model or a screen state is written | [`01-android-data-flow.md`](./references/01-android-data-flow.md) |29| 2 | Kotlin API design: function ownership, value classes versus data classes, multiplatform boundaries | an extension, a factory, a wrapper type or a platform seam is added | [`02-kotlin-api-design.md`](./references/02-kotlin-api-design.md) |3031## Output / checkpoint32Each repository method says whether it returns a stream or performs a write, each screen state is a closed33hierarchy the UI handles exhaustively, and each new function names its semantic owner. A claim that a screen34"handles loading and errors" without naming the state type that carries them is not verified.3536## Guardrails37- Never expose repository reads as one-shot snapshots when the data can change (part 1).38- Never add an extension on a standard or framework type that hides parsing, repository access or clock policy39 (part 2).40- Never put a platform type in a common signature (part 2).41- No block and no agent installs a library: the blocks name it and the user installs it (`CONVENTIONS.md`).42- Versions: the rules are architecture guidance, not API reference; each names its source. Nothing was built43 or run while writing this block.4445## Origin46Rewritten from the Now in Android architecture guide (Apache-2.0) and the Kotlin API design skill of the47chrisbanes skills repository (Apache-2.0), read 2026-10-16. Overlaps with `skills/kotlin-android-conventions` (2026-10-19); cross-referenced, not merged. 🟡: never run by us; open48points are in [`references/origin.md`](./references/origin.md).