Top Banner
component based Rails application primer Enrico Teotti -- @agenteo
24

Lightening a component based Rails architecture

Feb 21, 2017

Download

Software

Enrico Teotti
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lightening a component based Rails architecture

component based Rails application primer

Enrico Teotti -- @agenteo

Page 2: Lightening a component based Rails architecture

component based Rails application primer

Rogrido Teotti -- @agenteo

Page 3: Lightening a component based Rails architecture

misconception that working on complex software must feel hard

Page 4: Lightening a component based Rails architecture

like carrying 200 potatos is harder than carrying 20

Page 5: Lightening a component based Rails architecture

This is wrong for two reasons: software development is knowledge work not labour and

because of documented patterns to tackle software complexity with incremental code design

Page 6: Lightening a component based Rails architecture

decorators, presenters, service objects can be sufficient to handle some complexity but

when the project is over a certain size they don’t help understand what the

whole application does

Page 7: Lightening a component based Rails architecture

Component based architecture is complementary to good object oriented practices and uses

namespaces, test driven development and Ruby gems to gradually define application boundaries and enforce an internal dependency structure.

Page 8: Lightening a component based Rails architecture

path 'components' do

gem 'public_ui'

gem 'admin_ui'

gem 'legacy_migration'

end

intention revealing Gemfile

Page 9: Lightening a component based Rails architecture

Component is the name given to a Ruby on Rails engine or Ruby gem when used as building block of

the Rails application

Page 10: Lightening a component based Rails architecture

● are ruby gems● are special ruby gems that provide extra

behaviour (models, views, routes, rake tasks) to a Rails application

● they can be hosted on a gemserver or they can live inside your repository

● can be tested in isolation

what are rails engines?

Page 11: Lightening a component based Rails architecture

config/routes.rb

Rails.application.routes.draw do

case AppRunningMode.value

when :admin

mount AdminUi::Engine => "/"

when :public

mount PublicUi::Engine => "/"

else

mount AdminUi::Engine => "/"

mount PublicUi::Engine => "/"

end

end

Page 12: Lightening a component based Rails architecture

don’t architect an application with components from day one instead introduce them gradually as the

complexity grows or when the scope changes

Page 13: Lightening a component based Rails architecture

RUNNING_MODE=public rails s

RUNNING_MODE=admin rails s

http://example-internal-vpn-domain.com/admin

http://example.com/content

rails s

http://localhost:3000

Page 14: Lightening a component based Rails architecture

proceeding without automated tests

could drive you crazy

Page 15: Lightening a component based Rails architecture

use the test dummy app

Page 16: Lightening a component based Rails architecture

avoid high level engines coupling

admin_ui

public_ui

Page 17: Lightening a component based Rails architecture

admin_ui public_ui

domain_logic

Page 18: Lightening a component based Rails architecture

DomainLogic::Content::Article

Page 19: Lightening a component based Rails architecture

admin_ui public_ui

shared_ui domain_logic

Page 20: Lightening a component based Rails architecture

Gem::Specification.new do |s|

# ... other fields up here

s.name = "admin_ui"

s.add_dependency "rails", "~> 4.1.1"

s.add_dependency 'jquery-rails'

s.add_dependency 'mongoid'

s.add_dependency 'faraday'

s.add_dependency "domain_logic"

s.add_dependency "shared_ui"

s.add_development_dependency 'byebug'

s.add_development_dependency 'database_cleaner'

s.add_development_dependency 'rspec-rails', '2.99.0'

s.add_development_dependency 'vcr'

s.add_development_dependency 'webmock'

s.add_development_dependency 'capybara'

s.add_development_dependency 'poltergeist'

end

admin_ui/admin_ui.gemspec

Page 21: Lightening a component based Rails architecture

admin_ui public_ui

shared_ui domain_logic

legacy data import

Page 22: Lightening a component based Rails architecture

admin_ui public_ui

shared_ui domain_logic

legacy data importglobal search

Page 23: Lightening a component based Rails architecture

admin_ui/app/views/cargo_preview/show.html.erb

<%# admin console stuff here %>

<%= render partial: 'shared_ui/cargos/show' %>

<%# admin spaceship here %>

public_ui/app/views/cargos/show.html.erb

<%= render partial: 'shared_ui/cargos/show' %>

Page 24: Lightening a component based Rails architecture

http://teotti.com

Enrico Teotti - @agenteo

http://teotti.com/component-based-rails-architecture-primer/

Questions?