29
.
04
.
2024
25
.
11
.
2022
Ruby on Rails
Domain-Driven Design
Backend
Tutorial

Example Application - DDD in Ruby on Rails

Paweł Strzałkowski
Chief Technology Officer

There is a ton of materials on Domain-Driven Design. There are books, lectures, videos - you can choose whatever works for you. But one question is often asked - how to put all those concepts in code.

I have seen a lot of comments, that Ruby on Rails is not suitable for the domain-driven approach. That it somehow lacks the ability to hold and make use of all its elements.

Presentation of the application

Recently, at a Ruby meetup at Visuality, I have had a great pleasure to give a talk describing an example DDD application written in Ruby on Rails. The application uses plain Rails, with no additional gems (there is a glimpse of Sidekiq - just to see how well it fits).

It contains:
- Bounded contexts,
- Layered architecture,
- Application services,
- Entities,
- Aggregates,
- Repositories,
- Factory methods,
- Domain events and domain event handlers,
- Read models,
- and much more

All of the above, without using any additional dependencies. If you are interested, please check the presentation:

Code Example

Unfortunately I cannot share the code for this application. I use it for educational purposes - for individual research and in-house workshops.

However, I've written a small example, which contains (or will contain shortly) all the pieces included in the presentation. If you'd like to play with it, please take a look at https://github.com/pstrzalk/ddd-example-in-ruby-on-rails

Honestly, it's just a piece of code written in a few hours. It's not perfect (by far) and it's not supposed to be. I wanted to give you a piece of code, which can be the base for future discussions. I would love if you could let me know on Twitter / Mastodon / Miłośnicy Ruby discord if you found it useful or if you have any comments.

Articles in this series

Do you want to know more? Register for our DDD webinar

Paweł Strzałkowski
Chief Technology Officer

Check my Twitter

Check my Linkedin

Did you like it? 

Sign up To VIsuality newsletter

READ ALSO

Ruby MCP Client in Rails by Paweł Strzałkowski

MCP Client in Rails using ruby-mcp-client gem

11
.
06
.
2025
Paweł Strzałkowski
LLM
Ruby on Rails
Actionmcp in Ruby on Rails by Paweł Strzałkowski

MCP Server with Rails and ActionMCP

11
.
06
.
2025
Paweł Strzałkowski
LLM
Ruby on Rails
Banner - MCP Server with FastMCP and Rails by Paweł Strzałkowski

MCP Server with Rails and FastMCP

11
.
06
.
2025
Paweł Strzałkowski
LLM
Ruby
Ruby on Rails

Ruby on Rails and Model Context Protocol

11
.
06
.
2025
Paweł Strzałkowski
Ruby on Rails
LLM
Title image

Highlights from wroclove.rb 2025

11
.
06
.
2025
Kaja Witek
Conferences
Ruby
Jarosław Kowalewski - Migration from Heroku using Kamal

Migration from Heroku using Kamal

11
.
06
.
2025
Jarosław Kowalewski
Backend
store-vs-store_accessor by Michał Łęcicki

Active Record - store vs store_accessor

11
.
06
.
2025
Michał Łęcicki
Ruby
Ruby on Rails
How to become a Ruby Certified Programmer Title image

How to become a Ruby Certified Programmer

11
.
06
.
2025
Michał Łęcicki
Ruby
Visuality
Vector Search in Ruby - Paweł Strzałkowski

Vector Search in Ruby

11
.
06
.
2025
Paweł Strzałkowski
ChatGPT
Embeddings
Postgresql
Ruby
Ruby on Rails
LLM Embeddings in Ruby - Paweł Strzałkowski

LLM Embeddings in Ruby

11
.
06
.
2025
Paweł Strzałkowski
Ruby
LLM
Embeddings
ChatGPT
Ollama
Handling Errors in Concurrent Ruby, Michał Łęcicki

Handling Errors in Concurrent Ruby

11
.
06
.
2025
Michał Łęcicki
Ruby
Ruby on Rails
Tutorial
Recap of Friendly.rb 2024 conference

Insights and Inspiration from Friendly.rb: A Ruby Conference Recap

11
.
06
.
2025
Kaja Witek
Conferences
Ruby on Rails

Covering indexes - Postgres Stories

11
.
06
.
2025
Jarosław Kowalewski
Ruby on Rails
Postgresql
Backend
Ula Sołogub - SQL Injection in Ruby on Rails

The Deadly Sins in RoR security - SQL Injection

11
.
06
.
2025
Urszula Sołogub
Backend
Ruby on Rails
Software
Michal - Highlights from Ruby Unconf 2024

Highlights from Ruby Unconf 2024

11
.
06
.
2025
Michał Łęcicki
Conferences
Visuality
Cezary Kłos - Optimizing Cloud Infrastructure by $40 000 Annually

Optimizing Cloud Infrastructure by $40 000 Annually

11
.
06
.
2025
Cezary Kłos
Backend
Ruby on Rails

Smooth Concurrent Updates with Hotwire Stimulus

11
.
06
.
2025
Michał Łęcicki
Hotwire
Ruby on Rails
Software
Tutorial

Freelancers vs Software house

11
.
06
.
2025
Michał Krochecki
Visuality
Business

Table partitioning in Rails, part 2 - Postgres Stories

11
.
06
.
2025
Jarosław Kowalewski
Backend
Postgresql
Ruby on Rails

N+1 in Ruby on Rails

11
.
06
.
2025
Katarzyna Melon-Markowska
Ruby on Rails
Ruby
Backend

Turbo Streams and current user

11
.
06
.
2025
Mateusz Bilski
Hotwire
Ruby on Rails
Backend
Frontend

Showing progress of background jobs with Turbo

11
.
06
.
2025
Michał Łęcicki
Ruby on Rails
Ruby
Hotwire
Frontend
Backend