Agent skill · Backend & API

kotlin-ktor-patterns

Ktor server patterns including routing DSL, plugins, authentication, Koin DI, kotlinx.serialization, WebSockets, and testApplication testing.

mturacgithub.com/mturacGitHub ↗
codexcopilotcursorMIT
Install
npx skills add mturac/everything-openai-codex --skill kotlin-ktor-patterns --agent codex

Same command for any agent — swap --agent for claude-code, cursor, copilot.

Facts
Files in the skill folder: 1
SKILL.md size: 19 KB
Bundled scripts: none
Path: skills/kotlin-ktor-patterns/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 84
Language: JavaScript

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

Review
written from the skill's own SKILL.md · Aug 5, 2026

What it does

Describes a collection of Ktor server patterns for building HTTP servers with Kotlin coroutines. It outlines a standard project structure, including entry point, wiring for serialization, authentication, status pages, CORS, DI with Koin, routing, and tests. It provides concrete Kotlin code snippets that show how to configure routing, content negotiation, authentication, status pages, CORS, DI, Koin usage in routes, request validation, and WebSockets. It also demonstrates test patterns using testApplication for route testing and Koin-based test modules. The patterns cover REST endpoints for users and authentication flows, including JWT-based security, protected routes, and error handling via ApiResponse envelopes. The content includes example models, serializers, and utility components (InstantSerializer, ApiResponse, PaginatedResponse) and shows how to wire DI into routes and tests.

How it works

  • Application entry point is shown with embeddedServer(Netty, port = 8080) and module wiring that calls configureSerialization(), configureAuthentication(), configureStatusPages(), configureCORS(), configureDI(), and configureRouting().
  • Routing DSL demonstrates how to define routes for /users, /auth, and /health with public and protected sections, including JWT-based authentication for protected endpoints.
  • Content negotiation uses kotlinx.serialization, with a configured Json instance enabling prettyPrint, ignoreUnknownKeys, encodeDefaults, and explicitNulls settings. Serializable data classes for UserResponse, CreateUserRequest, ApiResponse, and PaginatedResponse are defined, along with a custom InstantSerializer.
  • Authentication shows JWT setup, token validation, and a helper to extract userId from the JWT payload; authentication routes include /login, /register, and /me for authenticated users.
  • StatusPages provides centralized error handling for common exceptions and 404 routing with ApiResponse wrappers.
  • CORS configuration demonstrates allowed hosts, headers, methods, and credentials.
  • Koin DI illustrates a module with Database, repositories, and services, plus application setup and usage in routes via inject<...>(). It also shows testing with a Koin test module and KoinTest integration in UserServiceTest.
  • Request validation examples show in-route validation and a separate validate() extension for CreateUserRequest.
  • WebSockets example configures WebSockets and defines a chat route that broadcasts messages to connected clients.
  • testApplication Testing section provides patterns for testing routes with testApplication, including setup with Koin modules, serialization, status pages, and routing, plus usage of a client for POST/GET requests and assertions on response data via ApiResponse and UserResponse types.

When to use it

  • When building Ktor HTTP servers and configuring Ktor plugins (Auth, CORS, ContentNegotiation, StatusPages)
  • When implementing REST APIs with Ktor
  • When setting up dependency injection with Koin
  • When writing Ktor integration tests with testApplication
  • When working with WebSockets in Ktor

What it can touch

  • Files and packages under the standard Ktor project layout as shown (src/main/kotlin/com/example/...). Accesses through DI with Koin, including services, repositories, and modules. Routes reference UserService, AuthService, and related models. The provided code uses kotlin and Ktor APIs such as embeddedServer, Netty, ContentNegotiation, JWT Authentication, StatusPages, CORS, WebSockets, and testApplication tooling. Tools listed: codex, copilot, cursor.

Caveats

  • The patterns assume a certain project layout and dependencies (Koin, kotlinx.serialization, JWT, WebSockets) and rely on a properties-based configuration for JWT (jwt.secret, jwt.issuer, jwt.audience, jwt.realm).
  • The provided snippets are illustrative and show configuration and usage; actual integration may require additional boilerplate or environment setup not described here.
From the SKILL.md

# 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 │ │ └── Ex

What's inside
Steps it walks through
  1. When to Activate
  2. Application Structure
  3. Standard Ktor Project Layout
  4. Application Entry Point
  5. Routing DSL
  6. Basic Routes
  7. Route Organization with Authenticated Routes
  8. Content Negotiation & Serialization
  9. kotlinx.serialization Setup
  10. Serializable Models
  11. Custom Serializers
  12. Authentication
  13. JWT Authentication
  14. Auth Routes
More from everything-openai-codex
All skills →
About this skill
What does the kotlin-ktor-patterns skill do?

Ktor server patterns including routing DSL, plugins, authentication, Koin DI, kotlinx.serialization, WebSockets, and testApplication testing.

How do I install it?

Run `npx skills add mturac/everything-openai-codex --skill kotlin-ktor-patterns --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From mturac/everything-openai-codex, a repository with 84 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going