kotlin-idiomatic-refactorer-spring-aware

작성자: kotlin

코틀린 코드를 더 명확하고 관용적인 설계로 리팩터링하되, Spring 동작, 직렬화, 지속성, 공개 계약을 깨뜨리지 않습니다. 다음과 같은 경우에 사용하세요…

npx skills add https://github.com/kotlin/kotlin-backend-agent-skills --skill kotlin-idiomatic-refactorer-spring-aware

Kotlin Idiomatic Refactorer Spring Aware

Source mapping: Tier 2 high-value skill derived from Kotlin_Spring_Developer_Pipeline.md (SK-20).

Mission

Improve the codebase's Kotlin quality without trading away framework correctness. Prefer refactorings that increase clarity and reduce accidental complexity while preserving behavior.

Read First

  • The current implementation and its tests.
  • Public signatures, annotations, and serialization or persistence boundaries.
  • Build plugins and framework constraints already discovered in project context.
  • Existing code style and module-boundary conventions.

Refactor In This Order

  1. Characterize current behavior with tests or existing callers.
  2. Identify whether the code is transport DTO, domain logic, entity, configuration, or framework glue.
  3. Apply the smallest idiomatic improvement that materially helps readability or safety.
  4. Re-check proxy, serialization, and persistence compatibility.
  5. Keep changes incremental unless the user explicitly wants a larger rewrite.

High-Value Kotlin Moves

  • Prefer constructor injection and immutable dependencies.
  • Replace imperative branching with when when it improves exhaustive reasoning.
  • Use sealed class or sealed interface for closed result or error domains.
  • Use data class for pure transport or value models, not for JPA entities.
  • Use value classes for domain primitives when the surrounding framework stack can support them safely.
  • Prefer explicit null-handling over scattered !!.
  • Use extension functions only when they improve discoverability and do not obscure ownership or layering.

Advanced Refactoring Traps

  • More concise is not always clearer. Scope functions can hide control flow and receiver identity quickly.
  • A beautiful Kotlin one-liner can become unreadable when side effects, logging, or transactions are involved.
  • Value classes are excellent domain tools but may require extra care for Jackson, JPA, validation, and map keys.
  • Sequence and lazy pipelines are not automatically faster, especially around JPA or repeated iteration.
  • Converting mutable services to expression-heavy style must not hide exception paths or operational logging.
  • Replacing explicit classes with generic helper abstractions often harms Spring traceability and domain clarity.
  • Refactoring null handling can silently change API semantics if null, absent, and default were distinct before.

Kotlin Language Nuances

  • Public inline functions, default arguments, and generated overloads can affect binary compatibility for library modules more than teams expect.
  • A read-only Kotlin collection type does not guarantee an immutable backing collection. Refactors that assume true immutability can still leak mutation.
  • copy() on data classes is convenient but can weaken domain invariants when state transitions should stay explicit.
  • Exhaustive when over sealed hierarchies improves safety, but only if the hierarchy is truly closed in the relevant module boundary.
  • Reified generics and extension-heavy DSLs can improve ergonomics while making stack traces and Java interop worse. Use them where the tradeoff is worth it.

Expert Heuristics

  • Prefer refactors that make invalid states harder to represent, not only code shorter to read.
  • Keep business transitions explicit when the domain has invariants, auditing, or transactional significance.
  • If a refactor improves local beauty but obscures logs, traces, or step-by-step debugging, it is probably not worth it.
  • In shared modules, treat source compatibility and binary compatibility as separate review questions.

Spring-Aware Safety Rules

  • Do not refactor proxy-reliant classes in ways that remove needed openness or change bean boundaries accidentally.
  • Do not convert entities into data classes or over-lean value objects without checking persistence support.
  • Do not change constructor shapes for DTOs or config classes without checking Jackson and configuration binding.
  • Do not move logic into extension functions that cross architecture layers implicitly.
  • Do not hide important framework interactions behind clever utility abstractions.

Output Contract

Return these sections:

  • Refactoring intent: what quality problem is being solved.
  • Safe transformations: the concrete Kotlin improvements that are appropriate here.
  • Framework constraints: the Spring, Jackson, JPA, or config rules that limit the refactor.
  • Minimal patch plan: incremental changes in a safe order.
  • Verification: which tests or runtime checks protect behavior.

Guardrails

  • Do not refactor for aesthetics alone when risk is non-trivial.
  • Do not introduce advanced Kotlin constructs just to prove idiomatic knowledge.
  • Do not compress code until debugability suffers.
  • Do not change public contracts without calling that out explicitly.

Quality Bar

A good run of this skill leaves the code more Kotlin-native and still boringly reliable in Spring. A bad run produces elegant Kotlin that is harder to debug, harder to evolve, or incompatible with framework behavior.

kotlin의 다른 스킬

ci-cd-containerization-advisor
kotlin
재현 가능한 빌드, 이미지 및 배포 파이프라인을 설계합니다. Kotlin 및 Spring 애플리케이션을 대상으로 하며, CI 검증, 계층형 컨테이너, 롤아웃 안전성 등을 포함합니다.
official
configuration-properties-profiles-kotlin-safe
kotlin
Design and diagnose Spring configuration, profiles, and `@ConfigurationProperties` binding for Kotlin applications. Use when property binding fails,…
official
dependency-conflict-resolver
kotlin
Diagnose and resolve Gradle and Spring classpath conflicts, version drift, and binary incompatibilities in Kotlin applications. Use when `NoSuchMethodError`,…
official
domain-decomposition-api-design-advisor
kotlin
구현을 시작하기 전에 비즈니스 범위를 경계 컨텍스트, 모듈 또는 서비스 경계, 워크플로우, API 계약으로 분해합니다. 새로운 것을 설계할 때 사용하세요.
official
error-model-validation-architect
kotlin
Kotlin과 Spring 서비스를 위한 일관된 API 검증 및 오류 처리 동작을 설계하고 구현합니다. 오류 페이로드를 정의하거나 프레임워크를 매핑할 때 사용합니다.
official
gradle-kotlin-dsl-doctor
kotlin
Generate, debug, and repair Kotlin + Spring Gradle builds with minimal, compatible changes. Use when `build.gradle.kts` or `settings.gradle.kts` is failing,…
official
integration-resilience-engineer
kotlin
탄력적인 HTTP, 메시징, 예약 통합을 Kotlin 및 Spring 서비스용으로 설계하며 명시적인 타임아웃 예산, 재시도, 멱등성, 서킷 브레이커를 포함합니다.
official
jackson-kotlin-serialization-specialist
kotlin
Kotlin과 Jackson을 사용하는 Spring 애플리케이션에서 JSON 직렬화 및 역직렬화 동작을 진단하고 설계합니다. DTO 역직렬화 실패 시, 기본값…
official