jettro edited this page Feb 24, 2012 · 3 revisions
Clone this wiki locally

The Axon-Trader is not called Axon-Trader by accidence. It is a sample application for the Axon framework. Within the sample application we demonstrate most of the mechanism that Axon comes with. For now the sample works with the latest released version of Axon. We will also be working on the newer axon features in 2.0 when release 1 of the sample is out the door.

That said, let us focus on the architecture of the sample. After reading this page you should be able to understand what is where in the code base and also why.

Used third party technology

In this section we'll explain the most important technologies that we use in the sample (except Axon). Throughout the sample we make use of different components of the spring framework. We use spring core for the bean wiring, spring mvc for the web application and spring-security for the authentication and authorization in the web application. We also make use of spring-data, the mongo module specifically, for encapsulating the query database.

Axon makes use of XStream for object to xml serialization. This is important for making the mongo based event store for axon.

The front-end is created with spring-mvc and sitemesh on the server side. To create the visual components we make use of the Bootstrap library. The perfect framework for the not talented front-end developers to create a very acceptable front-end.

Of course we use a lot of other libraries, check the pom files to find out more about them.

The different components

The application is made up out of multiple components. They all have their own responsibilities and are only related through identifiers. Of course they can use the api of each other, which is especially interesting for listeners and saga's. Each component exists of two different jars. One jar containing the api of the component (the commands and events) and another jar containing the actual implementations of the Event and Command handlers.


Nothing special here, you can use the create company command and listen for Company created events.

In the future we want to demonstrate with the Company that you can also used Axon without event sourcing. Even for just a part of the application. But that is not the case right now.

Trade engine

This is where the matching between buy and sell orders take place. The API is used internally by the transactions. Of course events are thrown when a trade is executed and when orders are created.

The interesting part about the trade engine is the way Axon handles Aggregate root and child entities. The OrderBook is the Aggregate root, the Orders are entity objects. The entity object Order extends AbstractAnnotatedEntity, this way events are also send to the Order instances.


The orders contain the Portfolio and Transaction entities. This component is interesting for the use of two Saga's. The saga's handle the complete Transaction from creation till full execution. To be able to track the transaction they receive events from the Portfolio, the OrderBook and the Transaction. The saga's know which command to create after events that are received.


One important part for the users of the system is that the username's must be unique. When receiving a command to create a new user, we first check against a special collection to see if the username is still available. After validation we actually create the user.

Another interesting thing to learn from the user part is the way we initialize a portfolio for a user. We register a special listener. This listener receives UserCreatedEvents and send a CreatePortfolioCommand to the command bus.