Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

layered-rails

БесплатноБез исполняемых скриптовНе проверен

Design Rails applications using layered architecture. Use when analyzing codebases for architecture violations, planning feature implementations, deciding…

majesticlabs-devот majesticlabs-dev★ 50 звёзд на GitHub

Об этом скилле

Layered Rails Architecture

Audience: Rails developers working on applications that have outgrown single-file patterns. Goal: Know which layer code belongs in, when to extract, and which existing skill handles the implementation.

Four-Layer Architecture

Presentation  →  Application  →  Domain  →  Infrastructure
(HTTP/UI)        (Orchestration)  (Business)   (Persistence/APIs)

Core rule: Lower layers MUST NOT depend on higher layers. Data flows top-to-bottom only.

Layer Responsibilities

Layer Owns Does NOT Own
Presentation HTTP concerns, params, rendering, channels, mailers Business logic, direct DB queries
Application Orchestration across models, authorization, form validation Persistence details, rendering
Domain Business rules, validations, associations, value objects HTTP context, request objects, Current.*
Infrastructure ActiveRecord, external APIs, file storage, caching Business rules, presentation

Common Layer Violations

Violation Why It's Wrong Fix
Current.user in model Domain depends on presentation context Pass user as explicit parameter
request param in service Application depends on presentation Extract needed values before calling service
Pricing calc in controller Business logic in presentation Move to model method or service
All logic in services, anemic models Domain layer is hollow Keep domain logic in models; services orchestrate
Model sends emails directly Domain depends on infrastructure side-effects Use callbacks only for data transforms; extract delivery

The Specification Test

Diagnostic for misplaced code:

  1. List every responsibility the object handles
  2. For each, ask: "Does this belong to this layer's primary concern?"
  3. If NO → extract to the appropriate layer

Example: A User model that handles authentication, avatar processing, notification preferences, and activity logging.

  • Authentication → Domain (keep)
  • Avatar processing → Infrastructure (extract to service/job)
  • Notification preferences → Domain (keep as concern)
  • Activity logging → Infrastructure (extract to observer/event)

See references/extraction-signals.md for the full methodology.

Callback Scoring

Rate each callback 1-5. Extract anything scoring 1-2.

Score Type Example Action
5 Transformer before_validation :normalize_email Keep
4 Normalizer before_save :strip_whitespace Keep
4 Utility after_create :update_counter_cache Keep
2 Observer after_save :notify_admin Consider extracting
1 Operation after_create :send_welcome_email, :provision_account Extract

Rule of thumb: If removing the callback would break the model's own data integrity → keep. If it triggers external side-effects → extract.

Pattern Selection

"Where should this code go?"

Situation Pattern Layer Skill
Complex multi-model form Form Object Presentation —
Request param filtering Filter Object Presentation —
View-specific formatting Presenter / ViewComponent Presentation viewcomponent-coder
Authorization rules Policy Object Application action-policy-coder
Business operation (one-time) Service / Interaction Application active-interaction-coder
Multi-model orchestration Service Object Application active-interaction-coder
State lifecycle management State Machine Domain aasm-coder
Complex reusable query Query Object Domain —
Immutable concept (Money, DateRange) Value Object Domain —
Shared model behavior Concern Domain —
Typed configuration Config Object Infrastructure anyway-config-coder
Domain events / audit trail Event Sourcing Infrastructure event-sourcing-coder
JSON-backed attributes Store Model Domain store-model-coder

Decision Tree

Is it about HTTP/params/rendering?
  YES → Presentation layer
    Multi-model form? → Form Object
    Filtering params? → Filter Object
    Formatting for view? → Presenter or ViewComponent
  NO ↓

Is it authorization?
  YES → Policy Object (action-policy-coder)
  NO ↓

Does it orchestrate multiple models/services?
  YES → Application layer
    One-time operation? → Service/Interaction (active-interaction-coder)
    Needs typed inputs? → ActiveInteraction (active-interaction-coder)
  NO ↓

Is it a business rule about a single model?
  YES → Domain layer (keep in model or concern)
    Has state transitions? → AASM (aasm-coder)
    Reusable query? → Query Object
    Immutable value? → Value Object
  NO ↓

Is it about persistence/external APIs/caching?
  YES → Infrastructure layer

Services as Waiting Rooms

app/services/ is a **tem

Полный SKILL.md на GitHub

Установить layered-rails в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/extraction-signals.mdreferences/pattern-catalog.md

FAQ

Что делает скилл layered-rails?

Design Rails applications using layered architecture. Use when analyzing codebases for architecture violations, planning feature implementations, deciding where code belongs, or extracting abstractions from fat models/controllers. Complements dhh-coder (which keeps things simple) with guidance for when complexity demands structure.

Как установить скилл layered-rails?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл layered-rails запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить layered-rails с