jMolecules – Architectural abstractions for Java
A set of libraries to help developers work with architectural concepts in Java. Goals:
-
Express that a piece of code (package, class, method…) implements an architectural concept.
-
Make it easy for the human reader to determine what kind of architectural concepts a given piece of code is.
-
Allow tool integration (to do interesting stuff like generating persistence or static architecture analysis to check for validations of the architectural rules.)
Expressing DDD concepts
Example:
import org.jmolecules.ddd.annotation.*;
@Entity
public class BankAccount { /* ... */ }
@ValueObject
public class Currency { /* ... */ }
@Repository
public class Accounts { /* ... */ }
When we take Ubiquitous Language serious, we want names (for classes, methods, etc.) that only contain words from the domain language. That means the titles of the building blocks should not be part of the names. So in a banking domain we don’t want BankAccountEntity
, CurrencyVO
or even AccountRepository
as types. Instead, we want BankAccount
, Currency
and Accounts
– like in the example above.
Still, we want to express that a given class (or other architectural element) is a special building block; i.e. uses a design pattern. jMolecules provide a set of standard annotations (and alternatively marker interfaces) for the building blocks known from DDD.
Libraries
-
jmolecules-ddd
— annotations and interfaces to express DDD building blocks (value objects, entities, aggregate roots etc.) in code. -
jmolecules-events
— annotations and interfaces to express the concept of events in code.
Expressing architecture
jMolecules provides annotations to mark a package as a layer (or ring):
import org.jmolecules.architecture.layered.*;
@DomainLayer
package org.acmebank.domain;
@ApplicationLayer
package org.acmebank.application;
That way, all classes in the respective package are considered to be part of the annotated layer.
Alternatively, classes can be annotated directly:
import org.jmolecules.architecture.layered.*;
@DomainLayer
@Entity
public class BankAccount { /* ... */ }
@ApplicationLayer
@Service
public class TransferMoney { /* ... */ }
Currently, annotations for Layered and Onion Architecture exist.
Libraries
-
jmolecules-architecture
— annotations to express architectural styles in code.-
jmolecules-architecture-layered
— Layered architecture-
@DomainLayer
-
@ApplicationLayer
-
@InfrastructureLayer
-
@InterfaceLayer
-
-
jmolecules-architecture-onion
— Onion architecture-
Classic
-
@DomainModelRing
-
@DomainServiceRing
-
@ApplicationServiceRing
-
@InfrastructureRing
-
-
Simplified (does not separate domain model and services)
-
@DomainRing
-
@ApplicationRing
-
@InfrastructureRing
-
-
-
Technology integration
-
jmolecules-archunit
— ArchUnit rules that verify the aggregate structures in your model. -
jmolecules-jpa
— A ByteBuddy plugin to derive default JPA mappings for code that expresses DDD building blocks viajmolecules-ddd
. -
jmolecules-spring
— A ByteBuddy plugin to derive Spring component annotations for code that expresses DDD building blocks viajmolecules-ddd
.
Examples
-
jmolecules-examples
— A collection of examples to showcase the usage of the concept types and annotations as well as the technology integration.
Installation
To use jMolecules in your project just install it from the Maven central repository.
Maven
<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-ddd</artifactId>
<version>1.0.0</version>
</dependency>
Gradle
compile("org.jmolecules:jmolecules-ddd:1.0.0")
Release instructions
-
mvn release:prepare -DscmReleaseCommitComment="$ticketId - Release version $version." -DscmDevelopmentCommitComment="$ticketId - Prepare next development iteration."
-
mvn release:perform -Dgpg.keyname=$keyname