🧹 Eliminating mapper boilerplate in Kotlin #4
LVMVRQUXL
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Every backend eventually hits the same wall: a domain concept needs a different shape at every layer it touches. One model becomes three, and someone has to write — and maintain — the code that translates between them.
😩 The problem
In a typical Kotlin backend, a single concept like
Userneeds a parallel data structure to be persisted:Two data classes for one concept, plus two functions whose only job is to shuttle values between them. Multiply that by every layer a domain model crosses — HTTP request/response, persistence entity, another service's contract — and the mapper functions start to outnumber the domain logic they surround.
This pattern leads to:
🔍 Why this happens
The root cause isn't carelessness — it's that today's tooling gives no other option. A data class can only have one shape. If persistence needs
idas aStringand the domain needs it as aUUID, something outside that class has to reconcile the difference. That something is a mapper function, written by hand, reviewed by hand, and updated by hand every time the domain model changes.The mapper isn't just glue code — it's a place where business rules quietly accumulate, disconnected from the model they describe.
✨ A domain-first alternative
Kotools Facet is exploring a different starting point: keep the domain model as the only model, and let it declare — on itself — how each layer should see it.
No
UserEntitywritten by hand, no mapper functions to keep in sync — the projection is declared once, onUseritself, and the glue code is generated at compile time. The rule thatidis aUUIDon the domain and aStringin persistence lives in exactly one place: the model.This is still early-stage design, not a shipped feature — Kotools Facet is in active development. But the direction is set: eliminate the mapper, not by hiding it better, but by never needing to hand-write it.
🚀 What's next
Kotools Facet is commercial software currently in early development. To get notified when it ships and discuss licensing, join the waiting list by sending an email to contact@kotools.org with the subject "Kotools Facet – Waiting List".
Follow the project's progress on the kotools/facet repository.
Beta Was this translation helpful? Give feedback.
All reactions