Back to list
abaddon

kotlin-implement

by abaddon

0🍴 0📅 Jan 13, 2026

SKILL.md


name: kotlin-implement description: Phase 4 of feature development - Implement commands, REST handlers, Kafka consumers/producers in Kotlin for the Burraco distributed system. Use after domain-modeling to write the implementation code.

Kotlin Implementation Skill

This skill implements the feature code including commands, REST handlers, and Kafka integration.

Usage

/kotlin-implement <feature-name>

Prerequisites

Run /domain-modeling first to have events and value objects created.

Instructions

Step 1: Implement Commands

Location: [Service]/src/main/kotlin/com/abaddon83/burraco/[service]/commands/[state]/

package com.abaddon83.burraco.[service].commands.[state]

data class [CommandName](
    override val aggregateID: [Context]Identity,
    val param1: Type1,
    val param2: Type2
) : Command<[Aggregate]>(aggregateID) {

    override fun execute(currentAggregate: [Aggregate]?): Result<[Aggregate]> = runCatching {
        when (val agg = currentAggregate) {
            is [ValidState] -> agg.[action](param1, param2)
            null -> throw IllegalStateException("Aggregate not found: $aggregateID")
            else -> throw UnsupportedOperationException(
                "[CommandName] not valid for state: ${currentAggregate::class.simpleName}"
            )
        }
    }
}

Step 2: Implement REST Handler

Location: [Service]/src/main/kotlin/.../adapters/commandController/rest/handlers/

class [Feature]RoutingHandler(
    private val commandControllerAdapter: CommandControllerAdapter
) {
    private val log = LoggerFactory.getLogger(this::class.java)

    fun handle(ctx: RoutingContext) {
        CoroutineScope(ctx.vertx().dispatcher()).launch {
            try {
                val gameId = [Context]Identity.create(ctx.pathParam("gameId"))
                val body = ctx.body().asJsonObject()
                val param1 = body.getString("param1")

                requireNotNull(param1) { "param1 is required" }

                val command = [CommandName](aggregateID = gameId, param1 = param1)
                commandControllerAdapter.handle(command)

                ctx.response()
                    .setStatusCode(200)
                    .putHeader("Content-Type", "application/json")
                    .end("""{"status": "success"}""")

            } catch (e: IllegalArgumentException) {
                ctx.response().setStatusCode(400).end("""{"error": "${e.message}"}""")
            } catch (e: UnsupportedOperationException) {
                ctx.response().setStatusCode(409).end("""{"error": "${e.message}"}""")
            } catch (e: Exception) {
                log.error("Error processing [feature]", e)
                ctx.response().setStatusCode(500).end("""{"error": "Internal server error"}""")
            }
        }
    }
}

Step 3: Register Route

In RestHttpServiceVerticle.kt:

router.post("/games/:gameId/[feature]")
    .handler(BodyHandler.create())
    .handler { ctx -> [Feature]RoutingHandler(commandControllerAdapter).handle(ctx) }

Step 4: Implement Kafka Event Handler (if consuming events)

class [Feature]EventHandler(
    private val commandControllerAdapter: CommandControllerAdapter
) : KafkaEventHandler<[EventName]ExternalEvent> {

    override val eventClass = [EventName]ExternalEvent::class.java

    override suspend fun handle(event: [EventName]ExternalEvent) {
        val command = [CommandName](
            aggregateID = event.aggregateId,
            param1 = event.field1
        )
        commandControllerAdapter.handle(command)
    }
}

Step 5: Register Event Handler

In Kafka consumer verticle:

router.register([Feature]EventHandler(commandControllerAdapter))

Step 6: Update External Event Publisher (if publishing events)

In KafkaExternalEventPublisherAdapter.kt:

override fun publish(event: [Aggregate]Event) {
    when (event) {
        is [EventName] -> publishToKafka([EventName]ExternalEvent.from(event))
        // ... existing cases ...
    }
}

Step 7: Build and Verify

./gradlew :[Service]:compileKotlin
./gradlew :[Service]:test
./gradlew :[Service]:build

Step 8: Implementation Checklist

### Commands
- [ ] Command class created in correct package
- [ ] execute() method validates state
- [ ] Correct state transition on success

### REST Handler (if applicable)
- [ ] Handler class created
- [ ] Input validation implemented
- [ ] Route registered in verticle

### Kafka Handler (if applicable)
- [ ] Handler implements KafkaEventHandler
- [ ] Handler registered in consumer

### Event Publisher (if applicable)
- [ ] External event mapping added
- [ ] Partition key is gameId

Reference Files

  • Command: Game/src/main/kotlin/com/abaddon83/burraco/game/commands/gameDraft/CreateGame.kt
  • REST Handler: Game/src/main/kotlin/com/abaddon83/burraco/game/adapters/commandController/rest/handlers/NewGameRoutingHandler.kt
  • Kafka Handler: Game/src/main/kotlin/com/abaddon83/burraco/game/adapters/commandController/kafka/KafkaDealerConsumerVerticle.kt

Score

Total Score

55/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon