Publié par : yoannr | 18 juillet 2012

Learning EDA/CQRS/ES- playing with the User Interface

I have started 6-7 month ago , a project of mine to study domain driven design and CQRS. This I do on my free time, so progress are slow. But the good thing is that between two development phases I have time to think. It can make things even slower because quite often, I decide to redo everything from scratch.

I am not going to dive into every little things I have been since the last months. May be I will, but here I just want to write down the past research I have been doing.

Since I started doing, CQRS and DDD, I tried to unlearn everything I have learnt so far, and put that knowledge to test.  Besides, I quite often have understood things « à la CQRS » to be very simple and learnt afterwards that I was being misleaded.

For instance, I thought that once you had your bunch of command , everything you had to do was to send them your UI and then back again to be processed by one command handler. But it doesn’t work that way.  You command might have mandatory fields that are not initialized. For instance,  description of an item is to be empty, but is mandatory when the user does the action DoStuff.  Other stuff might be part part of the UI responsible to produce an command, but have nothing to do with the command in itself ( example list of items to populate a drop down list, the command is only interested in the  value selected).

So far, I have find this path only to deal with the UI.

For my specific purpose, I am on my way to divide my interface between a general interface based on a projection for instance Stuff, and little task based user interface dedicated to do one thing like DoStuff.

The projection based interface undergo the following flow :

-> Stuff (c# object)  MVC Model
-> Json generated by MVC
-> Stuff  (object javascript, push array)
-> template Html

the only task  this view can do is a filter on the projection, to do this , one command is created in javascript and then send via Json to the MVC controller which return another bunch of Stuff object via the same way.

Whereas the task based ui is like this :

->Stuff (c# object)  MVC Model
-> Mvc strong typed view

and the generation of the command is as follows :

pageHtml, javascript
-> command javascript ( & validation)
-> json
-> deserialised by mvc to give command (from the actual commandProject)

Thus, to Execute a specific command, I have so far :

  • C# MVC model for the task base UI
  • Javascript command (with command validation)
  • C# Command of the command Project (with command validation )

The command is present in 3 different places. I would like to reduce this number of model but I do not know yet how.

The javascript validation is in two parts :

  1.  validation supporting interaction with the user of the web interface
  2. validation of the command in javascript in order to verify that the object created was complete

The C# command should be created via a builder. This builder uses the constructor that ensures the command to be in a valid state.  I am using right now, an automatic (and by default) creation of the command and therefore it uses a ctor(), so no invariants will be checked , this is to be done in the near future.




  1. UI is the problem I’m facing right now. I play with DDD and CQRS+ES very much the same way you do. My project is placed comletely on the client side. It’s JavaScript only. It’s a blackboard where a user can draw lines with chalk. The domain is very simple and is fully described with the previous sentence. One module contains the core domain model, another module is managing the DOM (it is the UI module). I found that it’s some sort of a special case when UI elements are dynamically created. When a user draws a line whith a mouse, dot coordinates are streamed to the domain model vie command messages. The domain model produces events which land in event log after they have activated some event handlers. The event handlers fill a sort of client side database with denormalized data. Now the chalk line on screen is still invisible. After issueing the command the UI querys the database to fetch the set of dot coordinates of the line being drawn. The problem is as follows. The command gives no data back to the UI. How can the UI know the ID of the last line?

    • You have basically three choices I found to deal with it in eventual consistent system.

      The first one is to make your view refresh the whole blackboard nt only the last action.

      The second one is to make your view add some javascript to retain information as you knew it before sending the command. For instance, I might have an action AddInventoryItem, this might lead to some serious calculation based on the domain. When the command is sent I can already shw the user, the new line with the new inventory item and its name at least.

      The third one is some following of the second one, it might be taken as a whole also. Think of the UI as an eventHandler that listens to some kind of events. In my precedent example, my ui is listenning to the event InventorytemAdded and reacst to show it to the user..

      I hope it helped. if you have further questions , do not hesitate, I am glad to have some reading already! 🙂 have a nice day.

  2. Thank you for the suggested solutions. The first one can’t be accepted while there will be hundreds of chalk paths and thousands of dots. Each second fifty new dots are created. Refreshing the whole view in the browser with this rate will make the application slow down.

    The second solution is what I tried a while ago. I sent a command to the domain module and showed the result simultaniously on screen. No query was sent to the read model. This solution has its problems.

    The third solution is what I really like.

    I also posted the problem at Google’s CQRS group. They advised me to try generating ids in the client (in the UI). I gess ID generation is a common question for CQRS beginners. Now I realize that this solution is not what is needed, while the content of the blackboard has to be rebuilt (replayed) like a video or a presentation. That is why I like your third solution. UI listens to domain events. It can be rebuilt. It also issues commands. I’ll meditate over the idea this weekend.

    Thank you very much

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:


Vous commentez à l'aide de votre compte Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s


%d blogueurs aiment cette page :