Adept of DDD & Hexagonal architecture I am wondering:
Is it be possible to build business processes definitions programmatically from my domain using a neutral language?
You’d need to translate from your representation to the BPMN representation. The BpmnModel class (and related) can be used to construct a BPMN process model programmatically. It can be deployed by passing it to the RepositoryService#createDeployment method. Simple example here: https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/main/java/org/flowable/engine/impl/test/AbstractFlowableTestCase.java#L290
So far I have been able to reconcile Flowable, DDD and Hexagonal architecture by mapping domain services to service tasks or functions declared in process definition with the help of BP Expression Language.
When I need to push or update variable within the BP context, calling execution.setVariable()
method helps.
flowable:expression="${execution.setVariable("TICKET_ID", bookTicket.given(execution.processInstanceBusinessKey))}">
This way I can keep my domain module exempt of any Flowable specific code / dependencies.
However, regarding business process definition, which obviously belongs to the domain, I keep it defined as a standard BPMN XML document…