rails new way

42
or... rethinking Rails architecture ...if there's any. Rails new way

Upload: kamil-lelonek

Post on 06-Aug-2015

112 views

Category:

Education


0 download

TRANSCRIPT

or... rethinking Rails architecture...if there's any.

Rails new way

A few facts about me

Bloggerkamil.lelonek.me

Live in Wrocław,

Poland

First talk in front of such an advanced community

English as a second language

CTO at woumedia, Denmark

Full-stack Developer (mostly Ruby, Scala)

@KamilLelonek

DCI DDD CQRS Event Sourcing Actor model Reactive programming Microservices Service objects

What won't be about?

No fancy stuff

What will be about then?

Why?

On an architectural level, everything in Rails is crying for separation and encapsulation.

For every Rails project, there are exactly two outcomes.

Either they can be well designed.

or you will struggle a lot when maintaining them.

Because there is no architecture.

So why a conventional Rails architecture fails?

Why to rails-way at all in that case?

When not to rails way?

Where's the problem?

simplicity vs maintainability

models with thousands of lines of code

following the Rails conventions

What are we doing?

What is the solution?

MVC

?

So, why do we need Rails?

Rails needs more abstraction layers.

time to refactor

It's

Value Objects

immutable no identity

Entities

differs by ID stateful

Mappers

ActiveRecord -> Domain Object Renaming, Coercing, ...

Form Objects

Validation User input -> Domain Object

Repositories

DAO Infrastructural layer

Queries

Wraps query logic Query API

Validators

Ensure valid models Ensure valid data

Use cases

Slim down controllers Data flow orchestration

Testing

Features

No more "where do I put this kind of logic?" Clean architecture and right order

A lot of boilerplate Not very useful for simple domain

Infrastructure

Resources

https://github.com/KamilLelonek/rails-new-way/

https://github.com/KamilLelonek/react-new-way/

http://bit.ly/controversial-service-objects

http://bit.ly/ddd-dictionary

http://bit.ly/decouple-from-activerecord

Thank you for having me here

rails new app --skip-rails