β All skills
Kotlin Specialist
Use when building Kotlin applications with coroutines, Ktor server framework, Kotlin Multiplatform, and idiomatic language patterns.
About this skill
Use when building Kotlin applications with coroutines, Ktor server framework, Kotlin Multiplatform, and idiomatic language patterns.
SKILL.md
kotlin-specialist.SKILL.mdPlace it in your Syntic skills folder. For Syntic Code, install in your local skills directory, review the contents and run it in a controlled environment first.
---
name: Kotlin Specialist
description: Use when building Kotlin applications with coroutines, Ktor server framework, Kotlin Multiplatform, and idiomatic language patterns.
category: Languages
version: 1.0.0
tools: []
---
# Idiomatic Kotlin Development
Write concise, safe, and expressive Kotlin code. Leverage Kotlin's type system, coroutines, and multiplatform capabilities to build applications without sacrificing clarity.
## Core Principles
- Prefer immutability: `val` over `var`, `List` over `MutableList`, `data class` for value types.
- Use null safety aggressively. The `!!` operator is a code smell. Use `?.let`, `?:`, or redesign to eliminate nullability.
- Extension functions are powerful but must be discoverable. Define them in files named after the type they extend.
- Adopt Kotlin idioms: scope functions, destructuring, sealed classes, delegation.
## Coroutines
- Use `suspend` functions for all asynchronous operations. Never block threads with `Thread.sleep` or `runBlocking` in production code.
- Tie `CoroutineScope` to lifecycle: `viewModelScope` (Android), `CoroutineScope(SupervisorJob())` (server).
- Use `async/await` for parallel independent operations. Use sequential `suspend` calls for dependent operations.
- Handle cancellation properly. Check `isActive` in long-running loops. Use `withTimeout` for deadline enforcement.
- Use `Flow` for reactive streams: `flow { emit(value) }`, `stateIn`, `shareIn` for shared state.
## Ktor Server
- Use the Ktor plugin system for modular server configuration: `install(ContentNegotiation)`, `install(Authentication)`.
- Define routes in extension functions on `Route` for clean separation: `fun Route.userRoutes() { ... }`.
- Use `call.receive<T>()` with kotlinx.serialization for type-safe request parsing.
- Implement structured error handling with `StatusPages` plugin and sealed class hierarchies for domain errors.
- Use Koin or Kodein for dependency injection. Ktor does not bundle a DI container.
## Kotlin Multiplatform
- Place shared business logic in `commonMain`. Platform-specific implementations in `androidMain`, `iosMain`, `jvmMain`.
- Use `expect/actual` declarations for platform-specific APIs: file system, networking, crypto.
- Use kotlinx.serialization for cross-platform JSON parsing. Use Ktor Client for cross-platform HTTP.
- Use SQLDelight for cross-platform database access with type-safe SQL queries.
- Keep the shared module dependency-light. Heavy platform SDKs belong in platform source sets.
## Idiomatic Patterns
- Use `sealed class` or `sealed interface` for type-safe state machines and result types.
- Use `data class` for DTOs and value objects. Use `value class` for type-safe wrappers around primitives.
- Use `when` expressions exhaustively with sealed types. The compiler enforces completeness.
- Use scope functions intentionally: `let` for null checks, `apply` for object configuration, `also` for side effects, `run` for transformations.
- Use delegation with `by` for property delegation (`by lazy`, `by Delegates.observable`) and interface delegation.
## Testing
- Use Kotest for BDD-style tests with `StringSpec`, `BehaviorSpec`, or `FunSpec`.
- Use MockK for mocking: `mockk<UserRepository>()`, `coEvery { ... }` for suspend function mocking.
- Use Turbine for testing Kotlin Flows: `flow.test { assertEquals(expected, awaitItem()) }`.
- Use Testcontainers for integration tests with real databases and message brokers.
- Test coroutines with `runTest` from `kotlinx-coroutines-test`. It advances virtual time automatically.
## Verification
- Compile and test all targets: `./gradlew build`.
- Run static analysis: `./gradlew detekt` for code smell detection.
- Run code formatting checks: `./gradlew ktlintCheck`.
- Verify no `!!` operators in production code.
Install
Syntic App
- 1Create a dedicated folder for this skill in your local skills library.
- 2Place SKILL.md into that folder.
- 3Restart Syntic and invoke this skill on matching tasks.
Syntic Code (CLI)
- 1Save SKILL.md in your local Syntic Code skills directory.
- 2Keep related files in the same skill folder.
- 3Run in a safe environment and validate outputs.