Skip to main content
Jonas Weber·

Scaffolded a Kafka microservice with idempotent consumers and graceful shutdown baked in

Generates a complete microservice with inter-service communication, service discovery, health checks, and event-driven patterns.

Microservice Complete Scaffold

You are a platform engineer scaffolding a new microservice. Create a complete, production-ready service. ## Service Spec - Service name: {{service_name}} - Language: {{programming_language}} - Framework: {{framework}} - Communication: {{communication_style}} (REST, gRPC, event-driven, GraphQL) - Message broker: {{message_broker}} (Kafka, RabbitMQ, NATS, none) ## Required Components 1. **Service Structure** - Clean/Hexagonal architecture folders 2. **API Layer** - Controllers/handlers with request validation 3. **Service Layer** - Business logic with interfaces 4. **Repository Layer** - Data access with {{database}} integration 5. **Domain Models** - Entities, value objects, DTOs with validation 6. **Event Publishing** - Domain events to {{message_broker}} 7. **Event Consumption** - Event handlers with idempotency 8. **gRPC/REST Clients** - Typed clients for downstream services 9. **Health Checks** - Deep health checks (DB, broker, downstream) 10. **Graceful Shutdown** - Signal handling, in-flight request draining 11. **Configuration** - Environment-based config with validation 12. **Docker** - Multi-stage Dockerfile + docker-compose with deps 13. **OpenAPI Spec** - Auto-generated API documentation 14. **Tests** - Unit, integration, and contract tests 15. **README** - Architecture decision records, setup guide ## Output 1. Complete project with all files 2. Architecture diagram (ASCII) 3. docker-compose with dependencies 4. Makefile for common operations 5. Deployment manifests for Kubernetes 6. Inter-service communication examples

Ergebnisse

Scaffolded `notification-service` — a Go microservice, event-driven over Kafka, hexagonal layout with idempotent consumers. ## Architecture ``` ┌─────────────── notification-service ───────────────┐ HTTP/gRPC ──▶ │ adapters/in ─▶ application (use cases) ─▶ ports │ │ │ │ Kafka topic ─▶│ consumer ──idempotency──┘ adapters/out ─▶ Postgres └────────────────────────────────────────────────────┘ ``` ```go // consumer.go — idempotent handler keyed on message id func (c *Consumer) Handle(ctx context.Context, m kafka.Message) error { id := string(m.Key) if seen, _ := c.store.Exists(ctx, id); seen { return nil // already processed — safe replay } var evt OrderPlaced if err := json.Unmarshal(m.Value, &evt); err != nil { return c.dlq.Publish(ctx, m) // poison message → dead-letter } if err := c.usecase.Notify(ctx, evt); err != nil { return err // not committed → Kafka redelivers } return c.store.Mark(ctx, id, 24*time.Hour) } ``` **Graceful shutdown:** on `SIGTERM` the server stops accepting new requests, drains in-flight ones with a 15s deadline, then closes the Kafka reader. **Health:** `/health` deep-checks Postgres and broker connectivity. A multi-stage `Dockerfile`, `docker-compose.yml` (app + kafka + postgres), and K8s `Deployment`/`Service` manifests are included.

Modell: Claude Sonnet 4

12 Likes5 SavesScore: 7

1 Kommentar

Luca Brunner·

Ran it on our repo and it worked first try, honestly impressed.