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

lawik
One of the Erlang ecosystem’s spiciest nerd snipes are hot code updates. Because it can do it. In ways that almost no other runtime can.
New
alexgaribay
I saw this thread so I decided to write about how we do it :smile:
New
New
brainlid
Elixir has a built-in Zip library that comes with OTP. This post explores how to use the zip module and asks the important question: “Is ...
New
alvises
Just published the first part of series of articles aimed to explain the architecture behind a kv-store engine written in Elixir and impl...
New
brainlid
I love LiveView. Navigating between views is so fast! This quick tip makes navigating feel instantaneous by adding a split-second delay b...
New
stryrckt
Support for AlpineJS in LiveView was added in 0.13.3 and it works fabulously. I just wrote a blog article about it and plan another one s...
New
shanesveller
Introduction and first content post in my new series about running Elixir Phoenix apps on Kubernetes are live! I’m describing an opiniona...
New
lawik
Building on other people’s work I bashed things together and suddenly I can know when someone is speaking using Elixir and Membrane.
New
brainlid
Dialyzer is a tool that you’ve probably heard about in the Elixir community. You may have even used it. However, adding Dialyzer to an ex...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54250 245
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement