Building a PHP CLI tool using DDD and Event Sourcing: why?
Last updated: 2023-07-10 :: Published: 2022-07-13 :: [ history ]You can also subscribe to the RSS or Atom feed, or follow me on Twitter.
In this series
- Why? ⬅️ you are here
- The domain
- The model
- Software design
- Setting up Laravel Zero
- Getting started with EventSauce
- Distribution
Anyone following me on Twitter is well aware of my interest in crypto. I find it a fascinating topic with ramifications that I believe will change society in many ways.
But whether you share this view or not doesn't really matter here – this post isn't about crypto (feel free to check this post if you want to know why I think Bitcoin is important, though).
The field just happens to serve as a backdrop for this series, focussed on the building of a PHP console application that will help me track my crypto activity for tax purposes.
And there are a few reasons why I'm getting into this.
Taxes
The only two certainties in life are death and taxes.
– Benjamin Franklin
As I keep exploring the ever-expanding crypto sphere, I'm performing all sorts of actions, some of which Her Majesty's Revenue and Customs (HMRC) has an interest in. I live in the UK and, like in many other places, the government is grappling with this rapidly evolving field, adding new rules and amending existing ones on a regular basis to try and keep up with new practices.
While it's fairly easy to keep track of and compute a limited number of transactions, it becomes far more complicated when that number goes up (wait – isn't NGU supposed to be good?). There are lots of portfolio- and tax-tracking tools out there, but I couldn't find one that covers all my use cases or that reports numbers I can make sense of.
As I wanted to understand the underlying rules to make informed decisions anyway, I figured I might as well build my own tool.
Technical exploration
The second reason for this series is that this project has some interesting technical aspects to it:
-
It's a good candidate for a console application, a topic I've been looking into lately;
-
It's sufficiently complex that it could use some advanced features typically provided by a framework. Laravel Zero has been on my radar for a while and this feels like a good opportunity to use it;
-
I've recently been exposed to Event Sourcing, an approach where an application's state is stored as a sequence of events leading to its current state, instead of storing the latter only. Keeping track of my crypto activity using this method could help me understand why the numbers are what they are, while allowing me to process the data in ways I haven't thought of later on (e.g. through additional projections);
-
Event Sourcing is considered a pattern of Domain-Driven Design (DDD), which involves talking to experts to come up with a model matching the business domain. I've got access to an accountant I can ask questions to and there's now plenty of literature available out there, which makes this approach suitable for this project.
Build in public
Finally, the third reason I'm writing this series is that I've been interested in building in public for a while. This approach is usually taken with an entrepreneurial mindset – advertise the product you're planning to build, document and share your progress, grow an audience and gather feedback along the way – the goal being to then convert part of that audience to buyers when the product is finally available.
The main difference here is I've got nothing to sell. The tool will be open-source and free to use, although if people decide to do so it will be their responsibility to ensure the numbers are correct (by running them by a professional accountant, for instance).
In short, people joining me on this journey should come for the process first and foremost, and not so much for the outcome.
I am not an expert in DDD any more than I am an Event Sourcing guru. My aim here is to learn as much as possible on these topics by building and to document my findings as I go. I hope to introduce others to these topics along the way, and to maybe gather useful feedback if people are kind enough to chip in. I'm also keen to explore how far PHP CLI applications can go.
Since I haven't done anything yet, I don't know how many parts this series will comprise. Feel free to subscribe to the newsletter using the form further down so you don't miss the next posts, or to follow me on Twitter where I'll share them also.
For now, as DDD commands, let us start with the domain.
You can also subscribe to the RSS or Atom feed, or follow me on Twitter.