Awesome-copilot kotlin-springboot
Get best practices for developing applications with Spring Boot and Kotlin.
install
source · Clone the upstream repo
git clone https://github.com/github/awesome-copilot
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/github/awesome-copilot "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/kotlin-springboot" ~/.claude/skills/github-awesome-copilot-kotlin-springboot && rm -rf "$T"
manifest:
skills/kotlin-springboot/SKILL.mdsource content
Spring Boot with Kotlin Best Practices
Your goal is to help me write high-quality, idiomatic Spring Boot applications using Kotlin.
Project Setup & Structure
- Build Tool: Use Maven (
) or Gradle (pom.xml
) with the Kotlin plugins (build.gradle
orkotlin-maven-plugin
).org.jetbrains.kotlin.jvm - Kotlin Plugins: For JPA, enable the
plugin to automatically make entity classeskotlin-jpa
without boilerplate.open - Starters: Use Spring Boot starters (e.g.,
,spring-boot-starter-web
) as usual.spring-boot-starter-data-jpa - Package Structure: Organize code by feature/domain (e.g.,
,com.example.app.order
) rather than by layer.com.example.app.user
Dependency Injection & Components
- Primary Constructors: Always use the primary constructor for required dependency injection. It's the most idiomatic and concise approach in Kotlin.
- Immutability: Declare dependencies as
in the primary constructor. Preferprivate val
overval
everywhere to promote immutability.var - Component Stereotypes: Use
,@Service
, and@Repository
annotations just as you would in Java.@RestController
Configuration
- Externalized Configuration: Use
for its readability and hierarchical structure.application.yml - Type-Safe Properties: Use
with@ConfigurationProperties
to create immutable, type-safe configuration objects.data class - Profiles: Use Spring Profiles (
,application-dev.yml
) to manage environment-specific configurations.application-prod.yml - Secrets Management: Never hardcode secrets. Use environment variables or a dedicated secret management tool like HashiCorp Vault or AWS Secrets Manager.
Web Layer (Controllers)
- RESTful APIs: Design clear and consistent RESTful endpoints.
- Data Classes for DTOs: Use Kotlin
for all DTOs. This providesdata class
,equals()
,hashCode()
, andtoString()
for free and promotes immutability.copy() - Validation: Use Java Bean Validation (JSR 380) with annotations (
,@Valid
,@NotNull
) on your DTO data classes.@Size - Error Handling: Implement a global exception handler using
and@ControllerAdvice
for consistent error responses.@ExceptionHandler
Service Layer
- Business Logic: Encapsulate business logic within
classes.@Service - Statelessness: Services should be stateless.
- Transaction Management: Use
on service methods. In Kotlin, this can be applied to class or function level.@Transactional
Data Layer (Repositories)
- JPA Entities: Define entities as classes. Remember they must be
. It's highly recommended to use theopen
compiler plugin to handle this automatically.kotlin-jpa - Null Safety: Leverage Kotlin's null-safety (
) to clearly define which entity fields are optional or required at the type level.? - Spring Data JPA: Use Spring Data JPA repositories by extending
orJpaRepository
.CrudRepository - Coroutines: For reactive applications, leverage Spring Boot's support for Kotlin Coroutines in the data layer.
Logging
- Companion Object Logger: The idiomatic way to declare a logger is in a companion object.
companion object { private val logger = LoggerFactory.getLogger(MyClass::class.java) } - Parameterized Logging: Use parameterized messages (
) for performance and clarity.logger.info("Processing user {}...", userId)
Testing
- JUnit 5: JUnit 5 is the default and works seamlessly with Kotlin.
- Idiomatic Testing Libraries: For more fluent and idiomatic tests, consider using Kotest for assertions and MockK for mocking. They are designed for Kotlin and offer a more expressive syntax.
- Test Slices: Use test slice annotations like
or@WebMvcTest
to test specific parts of the application.@DataJpaTest - Testcontainers: Use Testcontainers for reliable integration tests with real databases, message brokers, etc.
Coroutines & Asynchronous Programming
functions: For non-blocking asynchronous code, usesuspend
functions in your controllers and services. Spring Boot has excellent support for coroutines.suspend- Structured Concurrency: Use
orcoroutineScope
to manage the lifecycle of coroutines.supervisorScope