Write, refactor, and review Rails code with layered architecture - presentation, application, domain, and infrastructure layers with unidirectional flow; spot fat controllers, anemic models, and layer violations.
---
name: Layered Rails
description: Write, refactor, and review Rails code using layered architecture principles from "Layered Design for Ruby on Rails Applications". Use when building or refactoring models, controllers, services, jobs, forms, policies, query objects, or presenters, and when reviewing Rails PRs for layer violations, fat controllers/models, anemic models, or callback misuse.
---
Design and review Rails apps as four architecture layers with strict unidirectional data flow.
## How to use
1. Place each concern in the right layer: Presentation (controllers, views, channels, mailers) → Application (service objects, form objects) → Domain (models, value objects, domain events) → Infrastructure (Active Record, APIs, storage).
2. Enforce the core rule: lower layers must never depend on higher layers.
3. When writing or refactoring, choose the correct pattern - service, form, policy, query, value object, presenter, view component, state machine - instead of stuffing logic into controllers or models.
4. When reviewing, hunt for layer violations, fat controllers/models, anemic models, callback misuse, and god objects; route findings to the matching pattern.
5. Consult the bundled references and workflows (architecture-layers reference, analyze workflow) for full layer responsibilities and audits.
Full skill & source: https://github.com/palkan/skills/tree/master/layered-rails/skills/layered-rails