LLM Skills
~/catalogue/backend//kotlin-springboot-best-practices-cursorrules-prompt-filec
Backendsource GitHub

Kotlin springboot best practices

/kotlin-springboot-best-practices-cursorrules-prompt-filec

Applique des règles Cursor pour développer avec Kotlin springboot best practices de façon cohérente et maintenable.

PatrickJSPatrickJS
40.6k
27 mai 2026
CC0-1.0
// contenu du skill

description: "Cursor rules for Kotlin Springboot Best Practices."

globs: */

alwaysApply: false


Kotlin Coding Best Practices for Spring Boot Development

Project Structure and Organization

  1. Group your source code into clearly defined packages like controller, service, repository, and model to separate concerns and improve maintainability.
  2. Organize your file system so that each directory mirrors the Kotlin package name (e.g. put com.myapp.users under src/main/kotlin/com/myapp/users).
  3. Name each Kotlin file after the primary class or concept it contains to make the codebase easier to navigate and understand.
  4. Avoid vague file names like Utils.kt; instead, use concise and meaningful names that reflect the purpose of the file’s contents.
  5. Place your Spring Boot application entry point in the root package and structure sub-packages by layer or feature to help Spring scan and organize components efficiently.

Coding Style and Conventions

  1. Use PascalCase for class and object names, camelCase for functions and variables, and UPPERSNAKECASE for constants to follow Kotlin naming conventions and improve readability.
  2. Declare variables using val by default, and only use var when mutation is necessary to promote safer, more predictable code.
kotlin
    val maxConnections = 10    // immutable reference
    var currentUsers = 0       // mutable, try to avoid if possible
  1. Limit the scope of variables to where they are actually used—inside functions or smaller blocks—to avoid accidental misuse and make code easier to follow.
  2. Format your code consistently using 4-space indentation, proper spacing around operators and commas, and short, focused functions to improve clarity and maintainability.
  3. Write clear and expressive code instead of clever one-liners; break complex logic into intermediate variables or well-named functions to improve readability.
  4. Name classes, functions, and variables descriptively to convey intent, and avoid vague suffixes like '-Manager' or '-Helper' that don’t add meaning.
  5. Keep property getters and setters simple and free of heavy logic; if complex behavior is needed, move it into a separate method to keep property access predictable.

Idiomatic Kotlin Usage

  1. Use data class to define DTOs and entities so you get useful methods like equals() and copy() without writing boilerplate code.
  2. Replace overloaded constructors with default and named parameters to simplify function calls and make them more expressive.
kotlin
    // Kotlin – use default parameters
    fun createConnection(host: String, secure: Boolean = true) { … }

    createConnection("example.com")                      // uses default secure=true
    createConnection(host = "test.com", secure = false)  // named arg for clarity
  1. Use when expressions instead of long if-else chains to write cleaner, more readable conditional logic that clearly handles each case.
  2. Create extension functions instead of utility classes to add reusable behavior to existing types in a more natural and readable way.
kotlin
    fun String.capitalizeFirst(): String = replaceFirstChar { it.uppercaseChar() }

    println("kotlin".capitalizeFirst())  // prints "Kotlin"
  1. Use scope functions like apply, let, also, run, and with to reduce repetition and clearly express object configuration or null-safe operations.
  2. Declare variables as nullable only when necessary, and handle them using safe-call operators (?.) and the Elvis operator (?:) to avoid runtime crashes.
  3. Avoid using the not-null assertion (!!) and instead provide fallback values or explicit null checks to write safer and more predictable code.
  4. Handle platform types from Java APIs immediately by explicitly casting them to String or String? to avoid spreading nullability uncertainty in your Kotlin code.
  5. Use Kotlin’s functional collection operations like filter, map, and forEach instead of manual loops to write concise and expressive data transformation logic.
kotlin
    // Imperative approach
    val activeUsers = mutableListOf<User>()
    for (user in users) {
        if (user.isActive) activeUsers.add(user)
    }

    // Idiomatic functional approach
    val activeUsers = users.filter { it.isActive }
  1. Convert simple functions into single-expression functions when the logic is clear, to eliminate unnecessary syntax and improve code brevity.
kotlin
    fun toDto(entity: User) = UserDto(name = entity.name, email = entity.email)
  1. Build strings using string templates ($var or ${expression}) instead of concatenation, and use triple-quoted strings for clean multi-line text.

Implementation Patterns and Design

  1. Inject dependencies via constructor parameters using val to keep them immutable and to align with Spring and Kotlin idioms.
kotlin
    @Service
    class OrderService(
        private val orderRepo: OrderRep
// source originale publique
PatrickJS/awesome-cursorrules
/rules/kotlin-springboot-best-practices-cursorrules-prompt-file.mdc
Licence : CC0-1.0. Consultez le dépôt avant toute réutilisation.
Projet indépendant, non affilié à Anthropic. Ce skill reste la propriété de son auteur original.
// installer ce skill
Collez cette commande dans votre terminal à la racine de votre projet :
mkdir -p .claude/commands && curl -o ".claude/commands/kotlin-springboot-best-practices-cursorrules-prompt-file.mdc" "https://raw.githubusercontent.com/PatrickJS/awesome-cursorrules/main/rules/kotlin-springboot-best-practices-cursorrules-prompt-file.mdc"
Ensuite dans Claude Code, tapez /kotlin-springboot-best-practices-cursorrules-prompt-filec pour l'activer.
open_in_newVoir la source originale
// sauvegarder
Sauvegarde disponible après connexion.
loginSe connecter pour sauvegarder
// informations
CréateurPatrickJS
Étoiles 40.6k
CatégorieBackend
LicenceCC0-1.0
Mis à jour27 mai 2026
Format.md
AccèsGratuit
// similaires

Skills Backend

Voir toutarrow_forward