Akkurate Project Overview
Akkurate is a validation library that leverages the expressive capabilities of Kotlin, providing a way to write validation code through an intuitive and elegant declarative API. This project is designed to simplify the complexity associated with traditional validation libraries that often require numerous annotations and intricate custom constraints.
Key Characteristics
-
Intuitive Validation Syntax Akkurate allows developers to articulate constraints in their code as if they're crafting sentences in English. For example, the constraint
title.isNotEmpty() otherwise { "Missing title" }
translates to "Check if the title is not empty; otherwise, prompt 'Missing title'." -
Designed for Complexity Built from the ground up to manage complex business logic, Akkurate’s primary aim is to assist developers in writing validation code that is both high-quality and maintainable.
-
Under Development It's worth noting that Akkurate is still in development. While extensively tested, its API may undergo changes that could break compatibility with minor releases. However, the developers pledge to provide migration guides to ease these transitions.
-
Open for Input Users are encouraged to report bugs or issues via the GitHub repository, fostering a community-driven development process.
Showcase Example
To illustrate Akkurate’s capability, consider the following example which demonstrates how to apply constraints to a Book
and its Author(s)
:
// Define your classes
@Validate
data class Book(
val title: String,
val releaseDate: LocalDateTime,
val authors: List<Author>,
)
@Validate
data class Author(val firstName: String, val lastName: String)
// Write your validation rules
val validateBook = Validator<Book> {
title.isNotEmpty() otherwise { "Missing title" }
releaseDate.isInPast() otherwise { "Release date must be in past" }
authors.hasSizeBetween(1..10) otherwise { "Wrong author count" }
authors.each {
(firstName and lastName) {
isNotEmpty() otherwise { "Missing name" }
}
}
}
In this example, the library checks various constraints like ensuring the book's title isn't empty, the release date is in the past, and that the authors list holds a valid number of entries, each having a non-empty name.
Features
-
Beautiful DSL and API: Akkurate offers a clear, concise DSL that prevents redundant coding and embraces looping and conditional logic without clutter.
-
Essential Constraints: It provides all necessary constraints for most business logics, letting developers extend functionality with their custom constraints easily.
-
Extensibility: Writing custom constraints within Akkurate is straightforward, often as simple as a lambda function.
-
Async and Contextual: Akkurate allows asynchronous operations to query data from different sources like a database or REST API within the validation process.
-
Integration Ready: Seamless integration with popular frameworks is supported, ensuring that your data validation fits naturally into your preferred tech stack.
-
Cross-platform Deployment: Utilizing Kotlin Multiplatform means you write your validation logic once and apply it across both frontend and backend environments.
-
Easily Testable: Akkurate provides built-in tools to assist in testing your validation logic, making sure your code meets quality standards without the need to figure it out from scratch.
Akkurate represents a modern approach to validation in software development, providing fluidity, integration, and versatility by leveraging the power and simplicity of Kotlin.