CQRS/ES & MVVM using RX, EF & SQL in UWP & PCL …

...OMG right?!

Published on 22 December 2016

So, while ToddlerBox is riding high, I'd like to share some thoughts about another app I have in the store; LittleLittle. This app has been the subject of most of my efforts over the last few months and is significantly more complex (and, frustratingly, less successful!) than ToddlerBox.

LittleLittle was started shortly after my baby girl started weaning and became constipated - apparently a very common occurrence. When we visited a paediatrician about it, they asked that we keep a record of her bowel movements so that we could track the condition to see if it was getting better or worse.

"I wonder if there's an app for that", I thought. And, of course, there was.

Opportunity and Methodology

However, while there are plenty of other baby tracking apps out there, very few work across platform (I use Windows Mobile while my partner uses Android) and even fewer work as I feel they should.

Given the requirement to work across a variety of platforms, maximising code re-use was extremely desirable. As such, I decided that all of the core-logic for the app needed to be written in a PCL. Furthermore, particular care would be taken to observe a pure MVVM methodology so that ViewModels (an embodiment of the app's UX) could also be shared across platform.

Finally, following some work in the CQRS/ES space at my previous employer, I wanted to write an app that used this methodology end-to-end. LittleLittle seemed a perfect opportunity to do so.

Technology and Platform

To partner the CQRS/ES methodology, I was keen to use Rx as the driving technology for implementation. As readers of my blog will know, I am very much of the opinion that "everything is a stream" and event sourcing from "a stream of events" seemed a perfect fit for Rx.

Given that the Event Sourcing methodology - not to mention the nature of the app itself - required a persistence layer, I decided to use a recently new technology; Entity Framework Core. I decided on EFCore simply because the tooling for the UWP platform was pretty good and I liked the 'code-first' approach to schema and migration generation. Coupled with this, I decided to use a SQLite database as it was a proven data store for use with EFCore and across a variety of underlying platforms.

Finally, when I started LittleLittle I was studying for the Microsoft Beta Exam "Developing Mobile Apps". As such, while I was keen for the app to be cross-platform, the initial platform I wanted to support was UWP. I was - and still am - amazed by how, if you craft your code and views carefully, an application can run on an amazing number for platforms including RaspberryPi, Phone, Tablet, PC, Xbox and Hololens.

And here's one I made earlier…

After many weeks of work, innumerable iterations and much refactoring, I ended up with this:

Available actions
Height and weight charts
Sleep and excretion charts

And I'm extremely happy with the result. CQRS/ES and Rx are a perfect match and the technology stack in general has been extremely productive.

This morning I drew up a (retrospective) architecture to illustrate how much of the application is portable and how simple yet extensible it is.

Architecture diagram

"The proof is in the dog-fooding"

Apologies for the mixed metaphors but, suffice to say, while the technology choices may be deemed to be a success, the app can only be consider to be so if it is fit for purpose. As such, I have been using LittleLittle everyday for the past several weeks - across a number of iterations and versions - and I'm very, very pleased with the result. The UI is fast and efficient to use and the app has yet to crash or lose any data (either at runtime or between versions).

Indeed, a little while ago my other half took our baby to stay with her grandparents for a several days and agreed to keep LittleLittle up to date while she was away. She came back with a couple of small suggestions but overall very impressed by how fast and easy to use it was.

While it has yet to see a significant number of Windows Store acquisitions, Store Analytics shows there are a few people actively using the app and, so far, I have yet to see any crashes or failures. I intend to leverage the success of ToddlerBox to promote LittleLittle in the near future so, fingers crossed, it'll start getting some serious use and useful feedback.

Moving forward

While I intend to put LittleLittle on hold for a little while in order to work on some other projects I've been meaning to look at, I very much intend to return to the project early in the new year. I have a backlog full of features I'd like to implement not to mention the need to write a version which runs on Android/iOS (which will probably be in Xamarin).

In the mean time, I will be blogging about a few of the components in the architecture diagram above and sharing some of the approaches I have taken and successes (or problems!) I encountered.