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

ErlangSolutions
Hey all, it’s Erlang Solutions. We released loads of Elixir content from our senior developers last week in celebration of ElixirConf US...
New
JohnnyCurran
I’ve been writing LiveView since 2020. In that time, I’ve seen the same three form mistakes at multiple companies. Here’s what they are a...
New
RudManusachi
Hi there! Recently I was playing around with extracting and updating data in the DB and for fun challenged myself to try to implement a ...
New
axelson
I talk about how I really like to use runtime configuration and discuss some common pitfalls of configuration in Elixir.
New
brainlid
You are storing some Phoenix LiveView state in the browser. You want to retrieve that saved state as early as possible to improve the use...
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
T0ha666
In this article, we discuss how to create a Docker image for a Phoenix application. https://t0ha.ru/en/devops/elixir/2023/11/10/how-to-b...
New
axelson
I describe how we use Hot Reloading with Webpack to develop faster and show how to integrate Webpack 5, webpack-dev-server, and Phoenix f...
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

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement