CQRS Domain Specific Language (DSL)

Hi all,

Working on the auction example application I found that creating an
app for Axon (as with other frameworks too :wink: involves creating much
boilerplate code...

Therefore I'm currently thinking about creating a small DSL to
generate some code and speed up development. Here is an example what I
have so far: http://www.fuin.org/files/cqrs-dsl.gif

What do you think?


not a bad idea, last time we did a workshop here at jteam and someone created a sample with scala. Somehow this reminds me of that.

A disadvantage could be that you put everything in one place, labels, errors. Not sure if I really like that. And it seems that your domain ‘classes’ can become pretty big this way.

regards Jettro

Hi Michael,

the idea of less and easier-to-read code is always very appealing. It’s definitely worth-while to explore the possibilities.

A few questions\remarks on your sample dsl-code, though. It seems that you are combining front-end and back-end logic into a single file. Or am I misinterpreting? What is the idea of the messages (UserRegisteredMessage)? Is that the return value of the command handling? Will this DSL allow for a single command to map to multiple events? Where does the validation logic go? is that part of this DSL, or will that need to be developed as “regular” aggregates?

It’s not really clear to me which problems you’re trying to address with this DSL. Could you elaborate on that?



If I am not mistaken, this looks like an external DSL. Personally I don’t like external DSLs because of the additional complexity in building an application. Internal DSLs do not have this disadvantage. In addition, proper internal DSLs are transparently mixed with regular code.

With Scala one could write an internal DSL. Actually some of the required syntax is already available. For example all events and commands could be written on a single line with case classes. Libraries for validation also exist.

Btw, you can probably use the proposed syntax (with small changes) in a Scala based internal DSL.


Op 13-12-10 08:03, Jettro Coenradie schreef:


A disadvantage could be that you put everything in one place, labels, errors. Not sure if I really like that. And it seems that your domain 'classes' can become pretty big this way.

I think I will use one file per aggregate. This way the file is kept
small and everything is still in place.

Hi out there,

After experimenting with an Eclipse Xtext DSL I finally decided to go
back to a good old XML structure:

This is not as easy to read as the Xtext DSL but contains the same

For now I generate the following sources:


Abstract Domain Objects:


Abstract Command Handler:


The manual code is now much smaller and cleaner:

Domain Objects:

Command Handler:

Feedback is welcome :slight_smile:


Hi Michael,

I’m wondering why you switched back from Xtext to XML. Did you encounter any hiccups w.r.t. Xtext? As you know, Xtext has changed quite a lot since '10 so any technical impedance mismatch might have become smaller since then.

Btw: my current interest in resurrecting this thread and potentially an Axon DSL is that I’m on a project team with Allard :slight_smile:

Hi Meinte,

Four years ago I struggled with using Xtext because I faced several little problems.
But actually things improved and Xtext together with Xtend is pretty cool.

I started another try with Xtext some time ago:

There is not much documentation yet, but I already use it in one of my projects. Generation of code is done with my SrcGen4J framework (https://github.com/fuinorg/srcgen4j-core) - It supports different input (like Xtext, EMFText or even XML) and supports also different template languages (like Xtend or Velocity) for generating source code.

At the moment above it’s just DDD - CQRS DSL will follow in a few weeks.

I’m very busy at the moment, but I think I can assist you in setting the stuff up. Defining the “Addressbook-Sample” with the DSL would be a nice example.



You can try the “Beta” of the plugin by installing it into Eclipse Kepler:
http://www.fuin.org/p2-repository/ (Select “DDD DSL”)

After installing the plugin you should be able to open the example Addressbook-Sample classes I just added:

This way you might get a feeling what the DSL is all about.