DEV Community 👩‍💻👨‍💻

Cover image for Understanding Clean Architecture with Small Ruby Libraries
Moeki Kawakami
Moeki Kawakami

Posted on • Updated on

Understanding Clean Architecture with Small Ruby Libraries

After about 5 laps around Clean architecture since I came across hanami/hanami: The web, with simplicity., I'm finally getting it down in my gut, so I'll summarize.

It is difficult to understand while using a frameworks like Ruby on Rails

When using a framework, the outer moat of the Usecase in the diagram is filled in: Controller, View, and Model in the case of MVC, and Repository in the case of other patterns. Personally, I feel that if all three layers from the inner layer are integrated, they are the center of the application.

Image description

So I tried to implement each responsibility of the application using different libraries.

Here it is. cc-kawakami/clean-architecture-minimal-app: A minimal Clean Architecture app

These are the libraries we used.

"Let there be Entity."

We will attack from the heart of the architecture. First, Entity.

class User
  attr_reader :id, :name, :email

  def initialize(id:, name:, email:)
    @id