Generated banner for Kotlin Springboot
Generated logo for Kotlin Springboot

Kotlin Springboot

GitHubOfficialOriginally contributed by @josephgonzales01 as prompts/kotlin-springboot.prompt.md; moved into a skill by pull request #761Distributed by GitHub

  • Skill
  • Guidelines
  • Software development
  • MIT
  • No issues found

From the author

Get best practices for developing applications with Spring Boot and Kotlin.
— the description by josephgonzales01

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured set of best practices for building robust, idiomatic Spring Boot applications using Kotlin. It covers essential architectural patterns, project configuration, dependency injection, and data layer management, while emphasizing Kotlin-specific features like data classes, null safety, and coroutines to ensure clean and maintainable code.

What it does

  • Outlines idiomatic dependency injection using primary constructors.
  • Recommends project structures based on domain features rather than layers.
  • Provides guidance on leveraging Kotlin data classes for immutable DTOs.
  • Explains how to integrate Kotlin coroutines for non-blocking asynchronous programming.
  • Suggests testing strategies using JUnit 5, Kotest, and MockK.
  • Details configuration management using type-safe properties and profiles.

When to use it

  • When starting a new Spring Boot project with Kotlin.
  • When refactoring existing Java-based Spring applications to idiomatic Kotlin.
  • When seeking advice on integrating Kotlin-specific features like coroutines into a Spring environment.
  • When establishing team standards for Spring Boot and Kotlin development.

Advantages

  • Promotes cleaner, more concise code through Kotlin-specific idioms.
  • Ensures type safety and null safety across the application layers.
  • Encourages modern, non-blocking architecture using coroutines.
  • Provides a clear roadmap for consistent project structure and configuration.

Usage examples

“How should I structure my Spring Boot project using Kotlin?”
The agent will advise organizing code by feature or domain packages rather than by technical layers, and suggest using primary constructors for dependency injection.
“What is the idiomatic way to handle logging in a Kotlin Spring Boot class?”
The agent will provide a code snippet demonstrating the use of a companion object to declare a private logger.
“How do I handle DTOs in Kotlin for my REST API?”
The agent will recommend using Kotlin data classes to benefit from built-in methods like equals, hashCode, and copy, while ensuring immutability.
“Should I use coroutines in my Spring Boot service layer?”
The agent will explain how to use suspend functions for non-blocking operations and how to manage them using structured concurrency.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/github/kotlin-springboot/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip kotlin-springboot.zip -d .agents/skills

Documentation by josephgonzales01

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 (pom.xml) or Gradle (build.gradle) with the Kotlin plugins (kotlin-maven-plugin or org.jetbrains.kotlin.jvm).

  • Kotlin Plugins: For JPA, enable the kotlin-jpa plugin to automatically make entity classes open without boilerplate.

  • Starters: Use Spring Boot starters (e.g., spring-boot-starter-web, spring-boot-starter-data-jpa) as usual.

  • Package Structure: Organize code by feature/domain (e.g., com.example.app.order, com.example.app.user) rather than by layer.

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 private val in the primary constructor. Prefer val over var everywhere to promote immutability.

  • Component Stereotypes: Use @Service, @Repository, and @RestController annotations just as you would in Java.

Configuration

  • Externalized Configuration: Use application.yml for its readability and hierarchical structure.

  • Type-Safe Properties: Use @ConfigurationProperties with data class to create immutable, type-safe configuration objects.

  • Profiles: Use Spring Profiles (application-dev.yml, application-prod.yml) to manage environment-specific configurations.

  • 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 data class for all DTOs. This provides equals(), hashCode(), toString(), and copy() for free and promotes immutability.

  • Validation: Use Java Bean Validation (JSR 380) with annotations (@Valid, @NotNull, @Size) on your DTO data classes.

  • Error Handling: Implement a global exception handler using @ControllerAdvice and @ExceptionHandler for consistent error responses.

Service Layer

  • Business Logic: Encapsulate business logic within @Service classes.

  • Statelessness: Services should be stateless.

  • Transaction Management: Use @Transactional on service methods. In Kotlin, this can be applied to class or function level.

Data Layer (Repositories)

  • JPA Entities: Define entities as classes. Remember they must be open. It's highly recommended to use the kotlin-jpa compiler plugin to handle this automatically.

  • 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 JpaRepository or 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 (logger.info("Processing user {}...", userId)) for performance and clarity.

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 @WebMvcTest or @DataJpaTest to test specific parts of the application.

  • Testcontainers: Use Testcontainers for reliable integration tests with real databases, message brokers, etc.

Coroutines & Asynchronous Programming

  • suspend functions: For non-blocking asynchronous code, use suspend functions in your controllers and services. Spring Boot has excellent support for coroutines.

  • Structured Concurrency: Use coroutineScope or supervisorScope to manage the lifecycle of coroutines.

Files

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Originally contributed by
GitHub avatar of josephgonzales01@josephgonzales01as prompts/kotlin-springboot.prompt.mdmoved into a skill by pull request #761
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/kotlin-springboot · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
CypherHK, derekclair, josephgonzales01

AutoGineer is not affiliated with or endorsed by josephgonzales01 or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download kotlin-springboot.zip