kotlin-patterns

Apply idiomatic Kotlin patterns for Android ViewModel wiring and structured concurrency.

14|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/piyushverma0/android-agent-skills --skill kotlin-patterns-piyushverma0
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/piyushverma0/android-agent-skills/tree/main/skills/kotlin-patterns
Command: npx skills add https://github.com/piyushverma0/android-agent-skills --skill kotlin-patterns-piyushverma0

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Android projects often suffer from inconsistent Kotlin usage, leading to unstable memory management, boilerplate, and hard-to-maintain code. This skill provides a curated set of idiomatic Kotlin patterns and rules to enforce structured concurrency, safe nullability, robust state management, and clean architecture across Android apps.

Core Features & Use Cases

  • Coroutines and structured concurrency guidelines for lifecycle-aware execution in ViewModels and UI components.
  • Flow, StateFlow, and SharedFlow patterns for reactive UI without leaks and with predictable state.
  • Data classes and sealed interfaces for expressive, type-safe state and events, reducing boilerplate and debugging time.
  • Real-world scenarios include building a ViewModel that fetches data with safe error handling and a repository that injects dispatchers.

Quick Start

Refactor a sample Android module to apply idiomatic Kotlin patterns with structured concurrency, Flow-based state, and immutable data models.

Frequently Asked Questions about kotlin-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What are the best practices for structured concurrency in Android ViewModels?

Structured concurrency in Android ViewModels requires lifecycle-aware execution to prevent memory leaks. Idiomatic Kotlin patterns enforce safe coroutine cancellation and predictable background task management within UI components, ensuring reliable state handling across configuration changes.

How do I use StateFlow and SharedFlow for reactive UI state in Kotlin?

StateFlow and SharedFlow enable reactive UI state in Kotlin without leaks. Flow orchestration patterns provide predictable state emission and event sharing, replacing outdated LiveData implementations with robust immutable data modeling for ViewModels.

How do I model type-safe state and events in Kotlin Android apps?

Type-safe state and events in Kotlin Android apps are modeled using data classes and sealed interfaces. This expressive approach reduces boilerplate, enables compiler-checked state transitions, and significantly cuts debugging time for hard-to-maintain code.

How do I refactor an Android module to apply idiomatic Kotlin patterns?

Refactoring an Android module to apply idiomatic Kotlin patterns involves integrating structured concurrency, Flow-based state management, and immutable data models. This process enforces clean architecture rules and safe nullability across ViewModels and repositories.

Why does inconsistent Kotlin usage cause unstable memory management in Android?

Inconsistent Kotlin usage causes unstable memory management in Android through boilerplate and unsafe nullability. Applying curated idiomatic rules for coroutines and Flow orchestration enforces safe state management, resolving hard-to-maintain code and memory leaks.