
Kotlin Ktor Patterns
Implement and structure Ktor HTTP servers with routing, plugins, auth, Koin DI, serialization, WebSockets, and testApplication tests.
Overview
Kotlin Ktor Patterns is an agent skill for the Build phase that teaches routing DSL, plugins, Koin DI, kotlinx.serialization, WebSockets, and testApplication testing for Ktor HTTP servers.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill kotlin-ktor-patternsWhat is this skill?
- Standard layout: Application.kt, plugins (Routing, Serialization, Authentication, StatusPages, CORS), and route modules
- REST API patterns with kotlinx.serialization and response envelopes
- Koin dependency injection wiring for services and repositories
- WebSocket handlers alongside HTTP routes
- Integration testing with Ktor testApplication
Adoption & trust: 4.1k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are building a Ktor API but lack a consistent project layout and plugin configuration for auth, errors, serialization, and tests.
Who is it for?
Indie builders creating Kotlin microservices, BFFs, or internal APIs who want copy-paste structure for plugins and routes.
Skip if: Teams standardizing on Spring Boot only, frontend-only stacks, or greenfield mobile clients with no JVM server.
When should I use this skill?
Building Ktor HTTP servers; configuring plugins (Auth, CORS, ContentNegotiation, StatusPages); implementing REST APIs; setting up Koin; writing testApplication tests; working with WebSockets.
What do I get? / Deliverables
After the skill runs, you get implementable Ktor module structure, route/service patterns, and integration-test setup aligned to coroutine-based servers.
- Plugin and routing module skeleton
- Service/repository layering pattern
- testApplication integration test scaffold
Recommended Skills
Journey fit
Ktor patterns belong in Build because they guide server implementation after you have scoped what to ship. Backend is the canonical shelf: routing DSL, services, repositories, and API plugins are server-side concerns.
How it compares
Use as a procedural Ktor layout guide rather than a generic REST tutorial that ignores Ktor plugins and testApplication.
Common Questions / FAQ
Who is kotlin-ktor-patterns for?
Solo developers and small teams building Ktor HTTP servers who want routing, plugin, DI, and testing patterns in one place for coding agents.
When should I use kotlin-ktor-patterns?
Use it during Build/backend when configuring Auth, CORS, ContentNegotiation, StatusPages, implementing REST routes, adding Koin, enabling WebSockets, or writing Ktor integration tests.
Is kotlin-ktor-patterns safe to install?
Check the Security Audits panel on this Prism page before install; the skill is documentation-only patterns but example code may touch auth and network APIs you should review.
SKILL.md
READMESKILL.md - Kotlin Ktor Patterns
# Ktor Server Patterns Comprehensive Ktor patterns for building robust, maintainable HTTP servers with Kotlin coroutines. ## When to Activate - Building Ktor HTTP servers - Configuring Ktor plugins (Auth, CORS, ContentNegotiation, StatusPages) - Implementing REST APIs with Ktor - Setting up dependency injection with Koin - Writing Ktor integration tests with testApplication - Working with WebSockets in Ktor ## Application Structure ### Standard Ktor Project Layout ```text src/main/kotlin/ ├── com/example/ │ ├── Application.kt # Entry point, module configuration │ ├── plugins/ │ │ ├── Routing.kt # Route definitions │ │ ├── Serialization.kt # Content negotiation setup │ │ ├── Authentication.kt # Auth configuration │ │ ├── StatusPages.kt # Error handling │ │ └── CORS.kt # CORS configuration │ ├── routes/ │ │ ├── UserRoutes.kt # /users endpoints │ │ ├── AuthRoutes.kt # /auth endpoints │ │ └── HealthRoutes.kt # /health endpoints │ ├── models/ │ │ ├── User.kt # Domain models │ │ └── ApiResponse.kt # Response envelopes │ ├── services/ │ │ ├── UserService.kt # Business logic │ │ └── AuthService.kt # Auth logic │ ├── repositories/ │ │ ├── UserRepository.kt # Data access interface │ │ └── ExposedUserRepository.kt │ └── di/ │ └── AppModule.kt # Koin modules src/test/kotlin/ ├── com/example/ │ ├── routes/ │ │ └── UserRoutesTest.kt │ └── services/ │ └── UserServiceTest.kt ``` ### Application Entry Point ```kotlin // Application.kt fun main() { embeddedServer(Netty, port = 8080, module = Application::module).start(wait = true) } fun Application.module() { configureSerialization() configureAuthentication() configureStatusPages() configureCORS() configureDI() configureRouting() } ``` ## Routing DSL ### Basic Routes ```kotlin // plugins/Routing.kt fun Application.configureRouting() { routing { userRoutes() authRoutes() healthRoutes() } } // routes/UserRoutes.kt fun Route.userRoutes() { val userService by inject<UserService>() route("/users") { get { val users = userService.getAll() call.respond(users) } get("/{id}") { val id = call.parameters["id"] ?: return@get call.respond(HttpStatusCode.BadRequest, "Missing id") val user = userService.getById(id) ?: return@get call.respond(HttpStatusCode.NotFound) call.respond(user) } post { val request = call.receive<CreateUserRequest>() val user = userService.create(request) call.respond(HttpStatusCode.Created, user) } put("/{id}") { val id = call.parameters["id"] ?: return@put call.respond(HttpStatusCode.BadRequest, "Missing id") val request = call.receive<UpdateUserRequest>() val user = userService.update(id, request) ?: return@put call.respond(HttpStatusCode.NotFound) call.respond(user) } delete("/{id}") { val id = call.parameters["id"] ?: return@delete call.respond(HttpStatusCode.BadRequest, "Missing id") val deleted = userService.delete(id) if (deleted) call.respond(HttpStatusCode.NoContent) else call.respond(HttpStatusCode.NotFound) } } } ``` ### Route Organization with Authenticated Routes ```kotlin fun Route.userRoutes() { route("/users") { // Public routes get { /* list users */ } get("/{id}") { /* get user */ } // Protected routes