Envy-7z

kotlin-deep-logic-coroutines

Deep Kotlin logic workflow for use-cases, repositories, ViewModels, Flow/coroutine orchestration, and compact architecture-safe refactors. Use when implementing non-trivial business rules, fixing coroutine race/cancellation issues, reducing logic complexity, or enforcing clean layered boundaries in Android Kotlin code.

Envy-7z 0 Updated 3mo ago

Resources

3
GitHub

Install

npx skillscat add envy-7z/mobile-agent-skillpack/kotlin-deep-logic-coroutines

Install via the SkillsCat registry.

SKILL.md

Kotlin Deep Logic Coroutines

Overview

Implement Kotlin logic that is compact, testable, and coroutine-safe by separating contracts, orchestration, and side effects.

Workflow

  1. Define contract first
  • Clarify input, output, failure model, and idempotency.
  • Use explicit result models (sealed class, Result, domain error types).
  1. Place logic in the correct layer
  • UI layer: state mapping and intents only.
  • Domain/use-case layer: business rules and orchestration.
  • Data layer: API/DB details and DTO mapping.
  1. Build coroutine/Flow behavior intentionally
  • Use structured concurrency (coroutineScope, supervisorScope) by need.
  • Define dispatcher boundaries explicitly.
  • Handle cancellation as a normal path, not as generic failure.
  1. Keep code compact and readable
  • Extract named pure functions for branch-heavy logic.
  • Replace boolean soup with small domain types.
  • Keep function responsibilities singular; split oversized methods.
  1. Verify logic with focused tests
  • Test business rules with deterministic unit tests.
  • Test Flow emission order for loading/content/error transitions.
  • Validate timeout, retry, and cancellation behavior where used.

Coroutines Guardrails

  • Do not launch unscoped work from ViewModel/domain without lifecycle ownership.
  • Do not swallow exceptions silently.
  • Do not block threads inside suspend functions.
  • Prefer immutable state models for UI exposure.

Output Format

Use this structure in responses:

# Kotlin Logic Plan

## Problem
- Current behavior:
- Expected behavior:

## Layer Placement
- UI:
- Domain:
- Data:

## Coroutine Design
- Scope model:
- Dispatcher boundaries:
- Error/cancellation strategy:

## Minimal Refactor Plan
1. ...
2. ...

## Verification
- Unit tests:
- Flow/state checks:

Resources

  • Run scripts/kotlin_logic_snapshot.sh <repo_root> to find large/high-risk Kotlin logic files.
  • Use references/coroutine-logic-rubric.md for scoring complexity and safety.