Skip to content
kotoolsPublic

About

One model, many facets. A Kotlin SDK to eliminate data class duplication and mapper boilerplate.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

75 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💎 Kotools Facet

Status: Early Development

One model, many facets.

Kotools Facet is a Kotlin SDK that lets you define a faceted class once and project it across every layer of your application.

😩 Problem

In a typical Kotlin project, a single concept needs a parallel data structure to communicate with external systems. For example, representing a user accessible via HTTP that needs persistence would look like this:

data class UserDto(val email: String) {
    fun toUser(): User = User(email)
}

data class User(val email: String) {
    fun toUserDto(): UserDto = UserDto(email)
    fun toUserEntity(): UserEntity = UserEntity(email)
}

data class UserEntity(val email: String) {
    fun toUser(): User = User(email)
}

This pattern leads to:

  • Boilerplate code: Redundant data classes and mappers.
  • Maintenance burden: A single property change ripples through every layer.

✨ Solution

With Kotools Facet, the faceted class is the only model. Declare each facet in it, and this SDK takes care of the rest at compile-time.

// Client code:

@Faceted
data class User(val email: String) {
    object Dto : BidirectionalFacet<User>
    object Entity : BidirectionalFacet<User>
}

// Generated code:

fun User.toUserDto(): UserDto = UserDto(email)
fun User.toUserEntity(): UserEntity = UserEntity(email)

data class UserDto(val email: String) {
    fun toUser(): User = User(email)
}

data class UserEntity(val email: String) {
    fun toUser(): User = User(email)
}

This solution provides several benefits:

  • Single source of truth: User is declared once. No parallel data classes and mappers to maintain.
  • Easy maintenance: Changing one property in User propagates across facets.

Note

Kotools Facet is not just another mapper generator.

Classic mapper generators answer "How do I convert A to B?". They require UserDto and UserEntity to exist.

Kotools Facet answers "Why do I need B at all?". It requires only the faceted class (User).

📦 Modules

Kotools Facet ships following modules:

  • facet-core-dsl that provides @Faceted and DSL for declaring facets.
  • facet-core-ksp that generates projections at compile-time.

🛠️ Setup

When released, setup will require a KSP plugin and the modules for your stack:

// In build.gradle.kts file:

plugins {
    id("com.google.devtools.ksp") version "<ksp-version>"
}

dependencies {
    ksp("org.kotools:facet-core-ksp:<facet-version>")
    implementation("org.kotools:facet-core-dsl:<facet-version>")
}

📚 Additional Documentation

📬 Get Early Access

Kotools Facet is commercial software. To get notified when it ships and to discuss licensing, join the waiting list by sending an email to contact@kotools.org with the subject "Kotools Facet – Waiting List".

📄 License

The SDK modules are distributed under a commercial license. To enquire about licensing, contact us at contact@kotools.org.

About

One model, many facets. A Kotlin SDK to eliminate data class duplication and mapper boilerplate.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Contributors