百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

ddd-rails-sample

> 后端框架
开源

一个使用 Ruby on Rails 的域驱动设计项目示例:heart:

160 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

一个使用 Ruby on Rails 的域驱动设计项目示例:heart:

What is this project?

DDD Rails Sample is a open-source project meant to be used as a start point, or an inspiration, for those who want to build Domain Driven Design applications in Ruby. As Rails is the most robust web framework in Ruby community we tried to use it in a way we could modularize the layers and decouple responsabilities. This project is the result of this efforts.

NOTE: This is NOT intended to be a definitive solution or a production ready project

Technologies/frameworks involved

  • Ruby on Rails
  • Active Record
  • Dry::Types
  • Dry::Validations

Architecture

  • Object oriented programming following SOLID and Clean Code principles
  • Domain Driven Design
  • Repository Pattern
  • CQRS (same database)
    • Commands
    • Queries

Nice to have in the future

  • Include different Bounded Contexts
  • Domain Events
  • IoC Container or Service Locator
  • Domain Notifications instead of raising exceptions
  • Event Sourcing
  • A simple front-end implementation

Setup

bash
bundle install
rails db:create
rails db:migrate
rails db:seed
rails s

Different implementation versions

This project describes a two-phase implementation of the Repository pattern. The first implementation (version 1) is somewhat more pragmatic as the domain class itself inherit from Active Record. In the second one (version 2) we evolve this implementation in a way that our domain model became PORO classes, but that came with a cost as you can see in more details below.

Version 1

In this version we treat te Persistence Model and Domain Model as the same thing. We use this in the first version because it is a way more simple, fast, and we can have take advantage from all benefits the ORM offers.

ORM + DDD dilemma: You can see more details about the tradeoffs and the risks of using the Persistence Model and Domain Models as the same thing or in a separated way in this SO answer.

The only problem with Active Record is that, different from other ORMs like SQLAlchemy (Python), Hibernate (Java), Entity Framework (.NET), you can't create an external class to map your domain model to the database. In Active Record your class MUST inherit from ActiveRecord::Base in order to be persisted. This breaks (:hankey:) the Clean Architecture but as mentioned above, its a tradeoff that you may want to pay in face to the pragmatism.

Version 2

... More details soon ...

About

The DDD Rails Sample was developed by Murilo Capanema and Fabrício Rissetto under the WTFPL license.

Contributions are welcome :heartbeat:

Issues· 7 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubydddpersistence-modelrailsrepository-pattern

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架