Kotlin Project

Language: Kotlin October 1, 2025

Instruction file for Kotlin projects with Android and backend development.

---
applyTo: "**/*.kt, **/*.kts"
---

# Kotlin Development Instructions (2025)

_Last updated: October 2025_

- Always use the fetch tool to look up the latest Kotlin documentation: https://kotlinlang.org/docs
- Use Kotlin 2.0 or later for new projects
- Leverage null safety with proper nullable and non-nullable types
- Use data classes for POJOs/DTOs
- Implement coroutines for asynchronous programming
- Follow Kotlin coding conventions and idioms

**Core Principles:**

- Use data classes for simple data holders
- Leverage extension functions for utility methods
- Use sealed classes for representing restricted class hierarchies
- Implement null safety with ?, !!, and elvis operator ?:
- Use when expressions instead of switch statements
- Follow naming conventions matching Java/Android standards

**Coroutines:**

- Use coroutines for asynchronous programming instead of callbacks
- Implement suspend functions for async operations
- Use structured concurrency with coroutineScope
- Leverage Flow for reactive streams
- Use Dispatchers (IO, Main, Default) appropriately
- Implement proper exception handling in coroutines

**Android Development:**

- Use Jetpack Compose for modern UI development
- Implement MVVM architecture with ViewModels
- Use Jetpack libraries (Navigation, Room, WorkManager)
- Follow Material Design guidelines
- Implement proper lifecycle handling
- Use Hilt or Koin for dependency injection

**Backend Development:**

- Use Ktor or Spring Boot with Kotlin for backend services
- Implement RESTful APIs with proper routing
- Use Exposed or Ktorm for database access
- Implement proper serialization with kotlinx.serialization

**Modern Features:**

- Use inline classes for type-safe wrappers
- Leverage scope functions (let, run, with, apply, also)
- Use destructuring declarations for data classes
- Implement property delegation
- Use type-safe builders for DSLs

**Null Safety:**

- Use nullable types (Type?) when values can be null
- Use safe call operator ?. for null-safe access
- Use elvis operator ?: for default values
- Avoid !! operator unless absolutely necessary
- Use let for null checks with smart casting

**Testing:**

- Use JUnit 5 and Mockk for testing
- Write idiomatic Kotlin tests
- Use kotlintest or Kotest for behavior-driven testing
- Implement coroutine testing with runTest

**Summary:**

> For all Kotlin work, always use the fetch tool to look up the latest documentation from https://kotlinlang.org/docs. Write concise, safe, and expressive Kotlin code.

Kotlin Android Backend Programming Language