woylie

woylie

Simplified DDD in Elixir

The discussion in Must RFC - Event Sourcing, simplified? reminded me that I wrote down some ideas about a simplified DDD-inspired architecture recently, and I decided to publish them now. As the post says, the ideas are rough and unproven, but maybe someone finds something useful in there.

Most Liked

type1fool

type1fool

Interesting! I can see how

In the past, I have settled on using embedded schemas for everything except projections, which need regular schemas. Commands, events, aggregates, handlers, etc would all have embedded schemas so that readers wouldn’t have to understand structs vs schemas. That’s one less decision a developer has to make when adding new features.

Changesets are defined in each command, but not for aggregates. However, I would return a changeset when rejecting a command in an aggregate. This approach allows for validation before dispatching the command, which works nicely with LiveView.

def execute(%__MODULE__{status: nil}, %StartSession{} = command) do
  [
    %SessionStarted{
      session_id: command.session_id,
      name: command.name
    }
  ]
end

def execute(%__MODULE__{}, %StartSession{}) do
  {:error,
    %__MODULE__{}
    |> Changeset.change()
    |> Changeset.add_error(:session_id, "has already started")}
end

It’s cool to see different approaches to working with ES code. Thanks for sharing.

Where Next?

Popular in Blog Posts Top

rocket4ce
A comprehensive guide for deploying Phoenix 1.8 applications using Coolify on Hetzner servers. Covers server setup, Coolify configuration...
New
StuntProgrammer
Hey there! This is the first article in what I hope will be a nice series about how I built (and am building) Lofi Limo. If you have any ...
New
rms.mrcs
https://medium.com/the-realreal-product-tech-blog/monitoring-hackney-connection-pools-with-telemetry-3aaeafa8eeb8 Hi, everyone! In this ...
New
New
zacksiri
In December of 2023 we came to the realization that we needed to build our own image server. After hitting a few snags we decided that it...
New
ragamuf
Does the world need another How to create a blog article? Maybe not. But then again, creating something out of nothing is what we love....
New
bram209
Hello everyone, I just published my first blog post ever. I am learning Elixir, OTP & Phoenix and wanted to start a blog for a while...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
paulanthonywilson
I had a bit of a mini-adventure following Sobelow’s advice on adding a CSP to a Phoenix App. If you want to follow along, or want to add ...
New
rlopzc
Use the new log handlers to plug Slack or any other provider into your logging system. https://rlopzc.com/posts/integrate-slack-into-the...
New

Other popular topics Top

chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement