AGENT SKILL

stack-kotlin

Kotlin language guidelines — idioms, coroutines and flows, Ktor servers, Exposed ORM, and testing with Kotest and MockK

License 许可
Apache-2.0
最近更新
2026-11-15
Stars
★ 3
Forks
0

01 前言 Front Matter

name
stack-kotlin
license
Apache-2.0
metadata
{ "author": "manuel-retamozo-garcia", "version": "1.0" }
description
Kotlin language guidelines — idioms, coroutines and flows, Ktor servers, Exposed ORM, and testing with Kotest and MockK
capabilities
[ "kotlin" ]

02 资源文件 8

03 SKILL.md 正文

Kotlin Development Patterns

Idiomatic Kotlin patterns and best practices for building robust, efficient, and maintainable applications.

When to Use

  • Writing new Kotlin code
  • Reviewing Kotlin code
  • Refactoring existing Kotlin code
  • Designing Kotlin modules or libraries
  • Configuring Gradle Kotlin DSL builds
  • Writing coroutines, flows, Ktor routes, Exposed queries, or Kotlin tests

Core Rules

  1. Null Safety: Leverage Kotlin's type system (non-nullable by default). Use safe-call (?.) and Elvis (?:) operators; never use force-unwarp (!!).
  2. Immutability by Default: Use val for variables, immutable collections, and data class copy() for transformations.
  3. Sealed Types: Model restricted hierarchies and results with sealed class or sealed interface for exhaustive when expressions.
  4. Structured Concurrency: Scope async calls using coroutineScope or supervisorScope. Respect coroutine cancellation via ensureActive().
  5. DSL Builders: Implement type-safe builders using @DslMarker and lambda receivers.
  6. Coroutines and Flows (references/coroutines-flows.md): Never GlobalScope; Dispatchers.IO for blocking I/O, Default for CPU work; expose StateFlow for state and SharedFlow for one-time events; never catch CancellationException.
  7. Ktor (references/ktor.md): Thin routes as Route extensions delegating to services; errors mapped centrally in StatusPages; protected routes inside authenticate("jwt").
  8. Exposed (references/exposed.md): Every query inside newSuspendedTransaction; HikariCP with isAutoCommit = false; schema through Flyway migrations.
  9. Testing (references/testing.md): Failing test first; Kotest specs, MockK coEvery/coVerify for suspend functions (never mock data classes); runTest with virtual time.

References

Load on demand, only the file the task needs:

04 同仓库更多 Skills