Skip to content

What is LibEntity?

LibEntity is a powerful (and fun!) Java library for building type-safe, state-driven business entities with validation and action handling. It provides a clean, expressive DSL for defining entities, their states, fields, and actions. It's like Spring Boot for your business rules, but with more good vibes and less boilerplate!

lib-entity vs Traditional Hexagonal Architecture

Feature/Aspectlib-entityTraditional Hexagonal Architecture (Hand-Made)
BoilerplateMinimal: most patterns, wiring, and validation are handled by the frameworkHigh: manual wiring, repetitive code, lots of classes
Business Logic FocusDSL lets you focus on rules, states, and actions, not on plumbingBusiness logic often mixed with infrastructure code
ExtensibilityEasily add actions, validations, fields, or states declarativelyRequires manual changes across multiple layers
Validation & ActionsBuilt-in, composable, and reusable via DSLCustom, often duplicated, and scattered
TestabilityEntities and actions are isolated, easy to mock and testTest setup is verbose, mocking can be complex
ConsistencyEnforced by the framework and DSL, less room for errorDepends on developer discipline
Learning CurveBeginner-friendly, especially for new team membersSteep: must learn patterns, best practices, wiring
DSL/DeclarativeFluent, type-safe, and self-documentingImperative, verbose, and error-prone
IntegrationOut-of-the-box integration with Spring, validation, and moreMust integrate and maintain dependencies manually
MaintainabilityHigh: changes in one place, less code rotMedium/Low: changes ripple through many files

Metamodel

A metamodel is a model of a model. In the context of LibEntity, a metamodel is a model of your entity types. The prebuilt metamodel brings structure to your services while keeping good flexibility and a exit path at any point in time.

A metamodel is what allows you to move fast. Most systems are "literal", that means they are too granular, and you end up with a lot of code, a lot of testing surface, and a lot of maintenance burdern that blocks your business to react fast. LibEntity metamodel is a balance between granularity and simplicity.

LibEntity metamodel is as follows:

Core Pieces

ComponentDescription
ActionExecutorInterface for executing actions based on incoming commands and the current state of the entity.
EntityTypeCore configuration of an entity, containing fields, actions, and their definitions.
EntityTypeBuilderDSL builder for fluently configuring entities with fields, actions, and validations.
FieldDefinitionDefines a field's type, validators, and state transition rules.
ActionDefinitionDefines an action's command type, allowed states, conditions (onlyIf), and handler.
ActionCommandInterface for commands that trigger actions on entities.
ActionResultResult of an action execution containing new state, modified request, and command.
ValidationContextCollects validation errors during action execution and field validation.
ValidatorInterface for field validators that run in specific states.
StateTransitionValidatorInterface for validators that run during state transitions.

Summary: > lib-entity lets you build robust, maintainable, and testable domain logic with far less code and cognitive overhead. You get all the benefits of Hexagonal Architecture, but with a declarative, beginner-friendly approach and much less boilerplate. Perfect for teams who value both flexibility and productivity.

Released under the MIT License. Made with ☕, 💡 and lots of Java love.