Giter Site home page Giter Site logo

ddd-rails-example's Introduction

What is this project?

DDD Rails Sample is a open-source project meant to be used as a start point 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.

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

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 💓

ddd-rails-example's People

Contributors

fabriciorissetto avatar mcapanema avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.