Trailblazer gives you a high-level architecture for web applications. It extends the basic MVC pattern with new abstractions. Rock-solid conventions that go far beyond database table naming or route paths let you focus on your application code, minimize bugs and improve the maintainability.
Trailblazer’s file structure organizes by CONCEPT, and then by technology.
The new abstractions in Trailblazer are optional. Only use what you need.
Trailblazer helps improving your software in all kinds of systems and applications.
The Trailblazer gems work with any Ruby framework. We provide glue code for Rails and Hanami, but there are TRB-powered apps in Roda, Grape, Sinatra and many more out there.
You can start using Trailblazer in existing, massive applications today. Refactorings can be applied step-wise, legacy code can be minimized as you go. Remember: Rome wasn’t build in one day, either.
Our promise to the community: Trailblazer 2 will be supported until end of 2020 or longer. Our API design makes it easy to provide automatic upgrading and backward-compatibility so you won’t have to change code when we ship updates.
Our patterns are developed to be used in highly complex, existing, messy legacy applications. Trailblazer is designed to refactor old code - you do not have to rewrite the entire system to get a better architecture.
By restructuring business code, application behavior can be tested more efficiently with more unit and less integration tests. Trailblazer engineers do enjoy the simplicity of testing and the speedup of the test suites.
Trailblazer is in use in thousands of production applications. Our patterns have evolved over a decade of engineering, our gems are mature and battle-tested. And: we will never stop innovating.
Trailblazer defines patterns for a better architecture, and gives you implementations to use those patterns in your applications. Your software will be better structured, more consistent and with stronger, faster, and way simpler tests.
Our high-level architecture and enterprise-ready™ gems will prevent you from reinventing the wheel again and again - you and your team are free to think about the next awesome feature.
By standardizing the business logic, new developers can be onboarded faster with help of our free documentation. Trailblazer’s patterns cover 75% of daily business code’s structure - you will feel the power of strong conventions within the first hours.
If that’s not enough, we provide on-site training, premium support and consulting. Dozens of companies worldwide trust us already.
class SongsController < ApplicationController
def create
run Song::Create do |result|
redirect_to songs_path(result["model"])
end
end
end
CONTROLLER They end up as lean HTTP endpoints. No business logic is to be found in the controller, they instantly delegate to their respective operation.
Oh, and did we say there won’t be controller tests anymore? That’s right. Only unit and integration tests.
MODEL Models contain associations, scopes and finders. Only persistence logic, no callbacks, no validations, no business logic here.
class Song < ActiveRecord::Base
has_many :albums
belongs_to :composer
end
Any number of POLICYs can be used in an operation to grant or deny access to functionality.
class Application::Policy < Pundit::Policy
def create?
user.can_create?(model)
end
end
Also, use your choice of authorization framework.
The OPERATION is the heart of the Trailblazer architecture. It orchestrates validations, policies, models, callback and business logic by leveraging a functional pipeline with built-in error handling.
class Song::Create < Trailblazer::Operation
step Model( Song, :new )
step Policy::Pundit( Application::Policy, :create? )
step Contract::Build( constant: Song::Contract::Create )
step Contract::Validate()
step Contract::Persist()
fail Notifier::DBError
step :update_song_count!
def update_song_count!(options, current_user:, **)
current_user.increment_song_counter
end
end
Designed to be a stateless object, the operation passes around one mutable options hash and makes heavy use of Ruby keyword arguments - if you want it.
class Song::Contract::Create < Reform::Form
property :title
property :length
validates :title, presence: true
end
Validations are implemented with CONTRACT.
Trailblazer supports Reform and Dry::Schema
validations in any number.
Any dependency, such as the current user, must be injected from the outside.
The concept of global state does not exist in Trailblazer, which leads to simplified, mock-free testability and concurrent-ready code.
And the best: there’s only one way to run an operation.
Song::Create.(
{ title: "Roxanne", length: 300 }, # params
"current_user": current_user # dependencies
)
describe Song::Create do
it "prohibits empty params" do
result = Song::Create.({})
expect(result).to be_failure
expect(result["model"]).to be_new
end
end
Clumsy, slow controller tests are history. Now that all your business logic is controlled by the operation, SIMPLE UNIT TESTS can test any edge-case scenario or avoid regressions.
Trailblazer’s encapsulation makes a programmer’s life better.
"At some point of time we started to decouple our form objects from models. Things got a lot easier when we found out there is a ready to use solution which solves our exact problem. That was Reform. Soon after, we started using all other parts of Trailblazer and haven't regretted a second of our time we spent using it." Igor Pstyga, PeerStreet
I'm a much stronger Ruby developer now because of TRB. More files, less code, I'll take it!! I wake up excited to start coding now again. Jared Rubin, CTO / Feeder Real Estate
"Trailblazer helps organize my code, the book showed me how. You can assume what each component does by its name, it's very easy and intuitive, it should be shipped as an essential part of Rails." Yuri Freire Lima, AzClick
Trailblazer has brought the fun back to Rails for me. It helps me organize large codebases into small, smart, testable chunks. Nick has brought together his years of insight in managing Rails projects and made them available for everyone. Any Rails engineer looking to expand past the default Rails Way should take a look at Trailblazer. Eric Skogen, Software Inventor
"Here at Chefsclub, we are very happy with Trailblazer. Our application already has 32 concepts, 130+ operations, and Cells surprised us as an awesome feature. We feel pretty safe with it." Paulo Fabiano Langer, Chefsclub
I haven't been this excited about Rails since 2007! Trailblazer - makes Rails development fun again. Especially on large projects. It's one of the better implementations of the ServiceObject / ViewModel / Form Object / Policy layers I've seen, which sooner or later ( rather sooner) you'll need. Nick Gorbikoff, Rinica Company
Your logo here? Send it to us →