Kotlin Application Implementation and Review

Get idiomatic Kotlin code and targeted fixes for coroutines, Flow, Multiplatform, Compose, Ktor, and type-safe DSLs.

Development / Languageskotlincoroutines
by AgentVoltv1.0.0
Free to sign up · every skill included with AgentVolt Pro

Before & after

Same prompt, same agent — the only difference is the skill.

Prompt“How do I structure a Kotlin service using coroutines”
Beforegeneric AI agent
Kotlin and coroutines are great for building scalable services. There are several patterns you could use depending on your specific needs — you might want to consider structured concurrency, launch vs async, proper exception handling, and flow for streams. Coroutines are fairly flexible, so the best approach depends on your architecture and requirements. Do you have a specific use case in mind? For instance, are you building an HTTP server, a background worker, or something else? That would help me tailor the recommendation.
Afterwith Kotlin Application Implementation and Review
KOTLIN COROUTINE SERVICE PATTERN

FOUNDATION: STRUCTURED CONCURRENCY
• Use CoroutineScope for lifecycle management. Never GlobalScope — it has no cancellation.
• Pair scope with Job for clean shutdown. Example: val scope = CoroutineScope(Job() + Dispatchers.Default)
• On service shutdown, call scope.cancel() to propagate cancellation to all children.

CONCURRENCY MODEL: LAUNCH VS ASYNC
• launch() → fire-and-forget work (no return value). Use for logging, metrics, side effects.
• async() → suspendable work with Result. Use when you need .await() and exception handling.
• Never mix — launching an async that you forget to await() is a memory leak.

FLOW FOR STREAMS
• Flow<T> replaces callback hell. Build with flow { emit(data) }
• Collect safely: catch { e -> log.error() } then emit a fallback or rethrow.
• Use .buffer() if downstream is slow — otherwise backpressure stalls.

EXCEPTION HANDLING
• launch { try/catch } wraps each coroutine — unhandled exceptions crash the scope.
• Use CoroutineExceptionHandler on the scope dispatcher, not inside try/catch.
• async().await() surfaces exceptions to the caller (don't swallow with try/catch at launch).

TYPE-SAFE EXAMPLE: KTOR SERVER
embedApplication {
  install(StatusPages) { exception<Exception> { e -> respond(...) } }
  routing { get("/data") { val data = repository.fetchAsync().await(); respond(data) } }
}

About this skill

“My Flow opens a new connection for every screen.” “This coroutine keeps running after the screen closes.” This skill turns those symptoms into Kotlin implementations with explicit ownership, cancellation, sharing, and error behavior, then checks the failure paths that ordinary happy-path examples miss.

What it does

  • Fixes coroutine leaks, swallowed cancellation, misplaced dispatchers, and sibling failure behavior.
  • Chooses cold Flow, StateFlow, or SharedFlow according to delivery, replay, and subscriber requirements.
  • Implements callback cleanup, shared upstream connections, and recoverable stream states.
  • Separates portable Kotlin Multiplatform logic from platform dependencies without unnecessary expect/actual declarations.
  • Builds Compose state and effects, Ktor request handling, and scoped DSL builders using the right boundaries.
  • Supplies focused regression tests for cancellation, sharing, lifecycle changes, and invalid inputs.

What you get

Implementation code or a focused patch, the behavior it guarantees, dependency assumptions, and tests aimed at the actual failure. Reviews identify the mechanism behind each finding and show the smallest practical correction.

Best for

Kotlin developers building Android apps, shared Multiplatform modules, coroutine-based services, Ktor backends, or internal DSLs, especially when code works in a demo but fails under concurrency or lifecycle changes.

SKILL.md preview

SKILL.md
---
name: kotlin-application-implementation-and-review
description: Implement and review Kotlin applications by making coroutine ownership, Flow delivery, platform boundaries, and failure behavior explicit, then verifying them with focused tests. Use when the user says "my coroutine keeps running after navigation", "why does my Flow collect twice", "share this stream across screens", "move this into commonMain", "fix my Compose state", "build a Ktor endpoint", "review this Kotlin code", or "make this DSL type-safe".
---

# Kotlin Application Implementation and Review

… (sign up to view the full skill)
Sign up to view, copy, and install the full skill

More development skills

View all Development skills →