Cursor Kotlin 编码规范

Model: qwen-max | ¥0.15/call
AI工具GPT-4.1智能助手CursorKotlin

Cursor Kotlin 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 kot,适用于各类文档与内容的智能化处理。

Calls: 1

Skill Documentation

Cursor Kotlin 编码规范

摘要

Cursor Kotlin 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 kot,适用于各类文档与内容的智能化处理。

**文件来源:** PatrickJS/awesome-cursorrules → `rules/kotlin-ktor-development-cursorrules-prompt-file.mdc`

**原仓库:** https://github.com/PatrickJS/awesome-cursorrules

**评分:** ⭐ 仓库 40k stars (社区最权威 Cursor rules 合集)

这个 skill 是干什么的?

把 `kotlin-ktor-development-cursorrules-prompt-file.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for Kotlin development with Ktor integration.

🤖 Agent 使用说明

👤 用户需要做什么?

适用场景

原始规则内容

globs: **/*
alwaysApply: false
---
## Instruction to developer: save this file as .cursorrules and place it on the root project directory

## Core Principles
- Follow **SOLID**, **DRY**, **KISS**, and **YAGNI** principles
- Adhere to **OWASP** security best practices
- Break tasks into smallest units and solve problems step-by-step

## Technology Stack
- **Framework**: Kotlin Ktor with Kotlin 2.1.20+
- **JDK**: 21 (LTS)
- **Build**: Gradle with Kotlin DSL
- **Dependencies**: Ktor Server Core/Netty, kotlinx.serialization, Exposed, HikariCP, kotlin-logging, Koin, Kotest

## Application Structure (Feature-Based)
- **Organize by business features, not technical layers**
- Each feature is self-contained with all related components
- Promotes modularity, reusability, and better team collaboration
- Makes codebase easier to navigate and maintain
- Enables parallel development on different features

src/main/kotlin/com/company/app/

├── common/ # Shared utilities, extensions

├── config/ # Application configuration, DI

└── features/

├── auth/ # Feature directory

│ ├── models/

│ ├── repositories/

│ ├── services/

│ └── routes/

└── users/ # Another feature

├── ...


Test structure mirrors the feature-based organization:

src/test/kotlin/com/company/app/

├── common/

└── features/

├── auth/

│ ├── models/

│ ├── repositories/

│ ├── services/

│ └── routes/

└── users/

├── ...


## Application Logic Design
1. Route handlers: Handle requests/responses only
2. Services: Contain business logic, call repositories
3. Repositories: Handle database operations
4. Entity classes: Data classes for database models
5. DTOs: Data transfer between layers

## Entities & Data Classes
- Use Kotlin data classes with proper validation
- Define Table objects when using Exposed ORM
- Use UUID or auto-incrementing integers for IDs

## Repository Pattern

interface UserRepository {

suspend fun findById(id: UUID): UserDTO?

suspend fun create(user: CreateUserRequest): UserDTO

suspend fun update(id: UUID, user: UpdateUserRequest): UserDTO?

suspend fun delete(id: UUID): Boolean

}

class UserRepositoryImpl : UserRepository {

override suspend fun findById(id: UUID): UserDTO? = withContext(Dispatchers.IO) {

transaction {

Users.select { Users.id eq id }

.mapNotNull { it.toUserDTO() }

.singleOrNull()

}

}

// Other implementations...

}


## Service Layer

interface UserService {

suspend fun getUserById(id: UUID): UserDTO

suspend fun createUser(request: CreateUserRequest): UserDTO

suspend fun updateUser(id: UUID, request: UpdateUserRequest): UserDTO

suspend fun deleteUser(id: UUID)

}

class UserServiceImpl(

private val userRepository: UserRepository

) : UserService {

override suspend fun getUserById(id: UUID): UserDTO {

retur

...(完整内容在原仓库)...


## 数据来源

- 仓库: PatrickJS/awesome-cursorrules (40,581 stars, 257 个 .mdc 规则)
- 抓取时间: 2026-08-17
- License: 跟随原仓库(MIT)

## 联系方式

有问题或建议,在本 skill 下留言。

FAQ

这个 skill 是干什么的?

把 `kotlin-ktor-development-cursorrules-prompt-file.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for Kotlin development with Ktor integration.

👤 用户需要做什么?
  • [ ] 知道这条规则适合用在什么场景(参考下面"适用场景")
  • [ ] 把规则原文内容应用到 IDE 项目的 `.cursor/rules/` 目录(直接复制 .mdc 文件)
  • [ ] 调本 skill 时说清楚你的代码任务(语言/框架/目标)
  • [ ] 输出后人工 review 风格是否符合预期
suspend fun findById(id: UUID): UserDTO?

suspend fun create(user: CreateUserRequest): UserDTO

suspend fun update(id: UUID, user: UpdateUserRequest): UserDTO?

suspend fun delete(id: UUID): Boolean

}

class UserRepositoryImpl : UserRepository {

override suspend fun findById(id: UUID): UserDTO? = withContext(Dispatchers.IO) {

transaction {

Users.select { Users.id eq id }

.mapNotNull { it.toUserDTO() }

.singleOrNull()

}

}

// Other implementations...

}

interface UserService {

suspend fun getUserById(id: UUID): UserDTO

suspend fun createUser(request: CreateUserRequest): UserDTO

suspend fun updateUser(id: UUID, request: UpdateUserRequest): UserDTO

suspend fun deleteUser(id: UUID)

}

class UserServiceImpl(

private val userRepository: UserRepository

) : UserService {

override suspend fun getUserById(id: UUID): UserDTO {

retur

...(完整内容在原仓库)...