# Layered Design for Ruby on Rails Applications

> Discover practical design patterns and modern abstractions for maintainable Rails applications. Transition from the traditional Rails MVC trio to an abstraction model and evolve your application codebase with synchronized components, boosting flexibility and maintainability.

- URL: https://evilmartians.com/products/layered-design-book
- Website: https://www.amazon.com/Layered-Design-Ruby-Rails-Applications-ebook/dp/B0FVDMDWZZ

---

Written by Evil Martians' [Vladimir Dementyev](https://evilmartians.com/martians/vladimir-dementyev), this book tackles the complexity that naturally emerges in growing Rails applications. Learn how to keep your code maintainable by implementing abstraction layers and dividing your application into manageable modules—without sacrificing Rails' productivity benefits.

## When Rails abstractions are not enough

The Ruby on Rails framework revolutionized web development with its convention-over-configuration principle and MVC pattern. But as applications grow, that initial simplicity often leads to complexity, making a well-structured codebase difficult to maintain.

This book helps you get the most out of Rails while keeping your code clean and maintainable through useful patterns and abstraction layers.

## What's new in the second edition

The second edition came out in December 2025. It keeps the techniques from the first edition and adds two topics that reflect today's Rails development:

- **State transitions and workflows**: identify implicit state machines, make them explicit, and isolate them for clarity and resilience
- **Abstractions in the AI era**: treat LLMs as APIs, extract agent layers, and use third-party libraries and RAG strategies to keep AI features organized and testable

## What's inside

### Core concepts
- Rails' architectural patterns with their advantages and disadvantages
- Rails anti-patterns and how to refactor them
- Organizing business logic when the default approach is insufficient
- Introducing new abstractions to address design problems

### Practical patterns covered
- **Data layer abstractions**: beyond Active Record
- **State transitions and workflows**: from implicit to explicit state machines
- **Handling user input**: outside of models
- **Representation layer**: pulling out view logic
- **Authorization models**: multiple layers and approaches
- **Notifications layer**: from mailers to multi-channel deliveries
- **HTML views**: better abstractions for complex UIs
- **AI integrations**: LLMs as APIs, agent layers, and context management

## Who this book is for

Whether you're growing an MVP into a production system, scaling a monolithic app, or adding AI-driven features, this book provides battle-tested patterns from Evil Martians' extensive experience building and scaling Rails applications for startups and enterprises.

### Prerequisites
- Deep understanding of core Rails principles
- Prior experience building web apps with Rails
- Desire to write maintainable, scalable code

## About the author

Vladimir Dementyev is a backend engineer at Evil Martians, award-winning contributor to Ruby on Rails and Ruby, creator of AnyCable, TestProf, Action Policy, and dozens of other open source projects. He's been solving Rails architectural challenges for over a decade, working with startups and established companies worldwide.

## Get the book

Available in print, Kindle, and PDF formats:

- [Amazon](https://www.amazon.com/Layered-Design-Ruby-Rails-Applications-ebook/dp/B0FVDMDWZZ)—Print and Kindle editions
- [Packt Publishing](https://www.packtpub.com/en-us/product/layered-design-for-ruby-on-rails-applications-9781806114238)—All formats including PDF

Purchase of the print or Kindle book includes a free PDF eBook from Packt Publishing.

---

*"This book will help you keep your code maintainable while working on a Rails app... By the end of this book, you'll become a code design specialist with a deep understanding of the Rails framework principles."*
