kotlin-springboot-rules

kotlin-springboot-rules is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (1,826 once invoked), scanned A, original, MIT.

A set of coding rules for Kotlin applications built with Spring Boot, a Java-based framework for web services. It covers project layout, naming, Kotlin style, and common design patterns.

In plain words
What is it for?
Use it when creating or reviewing Kotlin Spring Boot controllers, services, repositories, models, and application packages.
Why use it?
It gives the codebase consistent structure and naming, making files easier to find and changes easier to review. It also encourages safer Kotlin practices, such as limiting mutable variables.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when creating or reviewing Kotlin Spring Boot controllers, services, repositories, models, and application packages.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/kotlin-springboot-rules
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for kotlin-springboot-rules

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/kotlin-springboot-rules.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/kotlin-springboot-rules)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/kotlin-springboot-rules"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/kotlin-springboot-rules.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,826 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01826
Opus 5 $0.00000 $0.00913
Sonnet 5 $0.00000 $0.00365
Haiku 4.5 $0.00000 $0.00183

Measured 7d ago against content hash 0e719ad1b952, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

kotlin-springboot-rules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/backend/kotlin/springboot-best-practices/kotlin-springboot-rules.mdc · 101 lines

How it starts

The opening of the file, as written. The whole thing — 101 lines — stays where its author put it; the contents beside it link to each section on GitHub.

项目结构与组织

  1. 将你的源代码分组到明确定义的包中,如 controller、service、repository 和 model,以分离关注点并提高可维护性。
  2. 组织你的文件系统,使每个目录都镜像 Kotlin 的包名(例如,将 com.myapp.users 放在 src/main/kotlin/com/myapp/users 下)。
  3. 每个 Kotlin 文件都以其包含的主要类或概念命名,以使代码库更易于导航和理解。
  4. 避免使用像 Utils.kt 这样模糊的文件名;相反,使用简洁且有意义的名称,以反映文件内容的目的。
  5. 将你的 Spring Boot 应用程序入口点放在根包中,并按层或功能组织子包,以帮助 Spring 高效地扫描和组织组件。

编码风格与约定

  1. 类和对象名使用 PascalCase,函数和变量名使用 camelCase,常量名使用 UPPER_SNAKE_CASE,以遵循 Kotlin 的命名约定并提高可读性。
  2. 默认使用 val 声明变量,仅在需要可变性时才使用 var,以促进更安全、更可预测的代码。
    val maxConnections = 10    // 不可变引用
    var currentUsers = 0       // 可变的,如果可能,尽量避免
    
  3. 将变量的作用域限制在其实际使用的地方——函数内部或更小的代码块中——以避免意外误用,并使代码更易于遵循。
  4. 使用 4 空格缩进、在运算符和逗号周围使用适当的间距,以及编写简短、专注的函数来统一格式化你的代码,以提高清晰度和可维护性。
  5. 编写清晰且富有表现力的代码,而不是巧妙的单行代码;将复杂的逻辑分解为中间变量或命名良好的函数,以提高可读性。
  6. 为类、函数和变量使用描述性的名称以传达意图,并避免使用像 '-Manager' 或 '-Helper' 这样没有实际意义的模糊后缀。
  7. 保持属性的 getter 和 setter 简单且不含复杂逻辑;如果需要复杂的行为,请将其移至单独的方法中,以保持属性访问的可预测性。

地道的 Kotlin 用法

  1. 使用数据类(data class)定义 DTO 和实体,这样你就可以获得像 equals()copy() 这样的有用方法,而无需编写样板代码。
  2. 使用默认参数和命名参数替换重载的构造函数,以简化函数调用并使其更具表现力。
    // Kotlin – 使用默认参数
    fun createConnection(host: String, secure: Boolean = true) { … }
    
    createConnection("example.com")                      // 使用默认的 secure=true
    createConnection(host = "test.com", secure = false)  // 使用命名参数以提高清晰度
    
  3. 使用 when 表达式代替冗长的 if-else 链,以编写更清晰、更易读的条件逻辑,从而清楚地处理每种情况。
  4. 创建扩展函数而不是工具类,以更自然、更易读的方式为现有类型添加可重用行为。
    fun String.capitalizeFirst(): String = replaceFirstChar { it.uppercaseChar() }
    
    println("kotlin".capitalizeFirst())  // 打印 "Kotlin"
    
  5. 使用作用域函数如 applyletalsorunwith 来减少重复,并清晰地表达对象配置或空安全操作。
  6. 仅在必要时将变量声明为可空,并使用安全调用运算符(?.)和 Elvis 运算符(?:)来处理它们,以避免运行时崩溃。
  7. 避免使用非空断言(!!),而是提供回退值或显式的空检查,以编写更安全、更可预测的代码。
  8. 立即处理来自 Java API 的平台类型,通过将它们显式转换为 StringString?,以避免在你的 Kotlin 代码中传播可空性的不确定性。
  9. 使用 Kotlin 的函数式集合操作如 filtermapforEach 代替手动循环,以编写简洁且富有表现力的数据转换逻辑。
    // 命令式方法
    val activeUsers = mutableListOf<User>()
    for (user in users) {
        if (user.isActive) activeUsers.add(user)
    }
    
    // 地道的函数式方法
    val activeUsers = users.filter { it.isActive }
    
  10. 当逻辑清晰时,将简单函数转换为单表达式函数,以消除不必要的语法并提高代码的简洁性。
    fun toDto(entity: User) = UserDto(name = entity.name, email = entity.email)
    
  11. 使用字符串模板($var${expression})构建字符串,而不是使用拼接,并使用三引号字符串处理干净的多行文本。

Read the full file on GitHub · 101 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 101 lines · 0 tokens per session scan A 0e719ad1b952

Subscribe to this mod's changes

kotlin-springboot-rules is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (232 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,826 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.