In the previous post, we implemented and configured the messaging infrastructure thereby now have a fully working example from request to response and from the controller, the message handler to a repository and all the way back.

The last thing from our list is the documentation of the API.

API documentation

We want to provide a documentation of the API for everyone using or depending on it. But we also want to get the most out of our current structure and not type everything by hand. Luckily there exists a Symfony Bundle called NelmioApiDocBundle which does just that. …


In the previous post we took a look on how to create objects from requests, validate them and if they are valid pass them as arguments directly on to a controller action as an argument. Now we want to really process the request or in our case the command or query object.

If you are not yet familiar with the Symfony Messenger component and the way it can be used for CQRS have a look at their documentation here and here. In this article we will just go briefly over the way we configured it.

What we want to have…


In the previous part I explained our file structure, routing with the REST endpoints and how our controllers work. In this part we are going to have a look at how to pass those automatically created command and query objects to the controller actions.

In Symfony there exists a concept called “argument value resolvers” which is used to inject parameters like the request into a controller action. In our case we are less interested in the request object itself, but more on how to get the data from the request object into our command and query objects e.g.


In the previous part I explained what we wanted to achieve and how we accomplished that. Now let’s get started with some code. We are going to build a small SPA that will showcase all the different parts we saw in the previous articles. You can find the example used in these articles in this repository. We are going to use some of Symfony’s components to accomplish our goal. Please refer to the composer file to see them in detail.

Structure

Let’s get started with the structure of every module. Instead of putting all controllers in one directory, all repositories in…


While working on Symfony applications for the last few years I have had a lot of fun but also my fair share of headaches while working on and especially maintaining them. Therefore I am of course interested in keeping those headaches as minimal as possible and one of the biggest issues in my experience is the architecture.

I am always striving to find the best possible architecture for a project (as probably all of you do) and read a lot of articles on various related topics. But I seldomly find an example that shows how to put all the different…

Michael Zangerle

backend developer from Austria mostly working with PHP and Symfony // software architecture // continuous improvements // legacy code // self improvement

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store