Categories
Semester 3 Unidash

Foody’s Architecture

Until the last sprint, we set the rails for our microservices’ architecture. For all the ASP.NET Core backends we make use of Domain Driven Development. Without going too much into details, here is a basic gist of our architecture:

  • Domain models are persisted and may consist of a root aggregate, value objects (immutable child of root aggregates) and a repository interface. Actual repository implementations are added by Dependency Injection.
  • CQRS – Command Query Responsibility Segregation. Commands fire away data, queries retrieve data. Neither one can do both at the same time. It makes use of the Mediator Pattern.
  • Mapping. We use AutoMapper to map from Data Transfer Objects to Commands over to Domain Models, and vice-versa.

Something along the lines MVC

Our setup is an abstraction of MVC. We have Models (our domain models), we have Views (JSON) and we have Controllers. Our controller has a lot more stuff behind it. This code map should serve as an overview:

A quick overview of the MVC architecture behind the backends

A quick TL;DR:

ASP.NET Core controllers may contain multiple routes (such as /auth/connect/ and /auth/finalize/). These routes fire a command through a mediator that fetches the associated handler. A command is a POCO (Plain Old C# Class) with read-only properties only.

The mediator looks for the associated command handler that matches the command and executes it. After execution, it returns the result back to the controller and from there back to the view as JSON.

If you’re a nerd like us and you’re curious, take a look at one of the controllers, commands, command handlers and requests handlers (requests consolidate commands and queries for the controller methods).

Tell me why?

This setup makes it fairly easy to separate concerns and maintain business logic without destroying other parts of our code. It also helps to reduce redundancy and improves portability.

Test Driven Development for Backend

I really wanted to try out TDD for the backend projects. Since we would like to include automated tests where applicable, it made sense to create tests for business-oriented classes and test them right away.

.NET Core offers several test environments. One of the popular ones is xUnit. Without going too deep – if you want to read more about TDD, I recommend you to check out this article for more details. The great part of automated testing is that we can easily integrate it with Azure DevOps as part of our CI pipeline:

xUnit allows us to test multiple implementations for interfaces. For example, when we implemented the database repository interface, we implemented the in-memory class first, tested it, and then implemented it as MongoDB implementation, and associated some integration tests to it. It works like a charm.

Frontend Story Time

Isabell and Imke have worked on the client app. Both of them looked further into Angular and Ionic, and successfully connected the canteen pages to the backend.

In addition to that, they’ve tried out several layouts for the start and betting pages. Here’s a screenshot of the non-final static bets page on both Android and iOS:

This should hopefully cover this week’s post. If you have further questions or comments, please let us know in the comments.

Cheers,
Gino

3 replies on “Foody’s Architecture”

Hey!
This is probably the most complicated post I’ve read this semester, and I really like it because you go into detail about the technology you use and even referenced some links if one wants to read more.
Your MVC gives partially a good overview, I wished there was also the frontend in there somewhere so you can see the whole picture. I don’t think an IDE can Auto-Generate that, but with some pictures and arrows this can easily be done by hand 🙂
Other than that your Blog is well structured and written, and your frontend even though is still a static page already looks pretty good.
Best Regards
Nico (bookly)

Hey Nico, thank you for your kind feedback. Good idea – the front end API bindings are still work in progress but we’ll make sure to update this post and add some sort of visualization when we’re ready to go.

Hello Foodies Team,

you did a really good job in this weeks blogpost.
It was a lot to read haha.

I did not understand everything you wrote, but I think I got your main idea. To me it looks like a normal MVC model for a backend API. It looks like one we did for our backend. Controllers, Models(mostly POJOs) and JSON responses as view for our frontend or in your case your app.

I appreciate your efforts for automated testing. I think it’s really important for dev ops. That is another point that we want to implement for our API as well in the future. So you can be glad that you implemented it already.

I think your design layout looks really nice as well.

Keep up the good work, you did a really good job this week.

Best regards,
Jan from Clairvoyance

Leave a Reply

Your email address will not be published. Required fields are marked *