rails-domain-architecture
Guides the design of model-centric Rails backends.
Install
mkdir -p .claude/skills/rails-domain-architecture && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/13124" && unzip -o skill.zip -d .claude/skills/rails-domain-architecture && rm skill.zipInstalls to .claude/skills/rails-domain-architecture
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Design or refactor the backend side of Ruby on Rails codebases toward a model-centric architecture that keeps domain logic, associations, scopes, callbacks, state transitions, and test ownership close to the owning models. Use when planning backend file layout, deciding between models, concerns, and query objects, organizing scopes, extracting capabilities into app/models/<model>/, designing request boundaries, or building reusable backend testing strategies for rich Rails domains. Do not use this skill for React or other frontend UI work; use `frontend-architecture` instead.Key capabilities
- →Choose the request boundary and access-scoped entry relation
- →Keep the base model file short as the composition root
- →Put associations, scopes, callbacks, predicates, and commands in app/models/<model>/<capability>.rb
- →Use app/models/concerns only for behavior reused across multiple models
- →Keep controllers thin by loading starting relation and composing named scopes
- →Keep tests aligned with ownership at the domain or request seam
How it works
The skill applies a set of architectural rules to organize Rails domain logic, keeping models rich and controllers thin, and aligning tests with ownership.
Inputs & outputs
When to use rails-domain-architecture
- →Refactoring Rails models
- →Organizing business logic
- →Planning backend architecture
About this skill
Rails Domain Architecture
Quick Start
- In this repo, treat
rails-domain-architectureas the default starting skill for backend and domain work. - For React pages, shared components, hooks, browser-side widgets, and frontend tests, switch to
frontend-architectureinstead of trying to force the backend skill to fit.
Default Workflow
- Choose the request boundary and access-scoped entry relation.
- Choose the owning model and keep the base model file short as the composition root.
- Put associations, scopes, callbacks, predicates, and commands for one business concept in
app/models/<model>/<capability>.rb. - Use
app/models/concernsonly for behavior reused across multiple models. - Prefer rich, intention-revealing model APIs over controller-shaped workflow methods or generic service wrappers.
- Keep scopes composable, relation-returning, and named after business concepts.
- Use named preload scopes for repeated read shapes.
- Keep controllers thin: load the starting relation, compose named scopes, and call model commands.
- Keep rendering at the edge: helpers for presentation, Jbuilder or serializers for JSON.
9a. If the change is frontend UI work, switch to
frontend-architectureso backend rules do not bleed into component design. 9b. For risky browser-side or visual work that still touches backend contracts, add focused feature specs that encode the rendered behavior. - Keep jobs thin and let model-adjacent objects own workflow rules.
- Keep tests aligned with ownership: model capability tests at the domain seam, integration tests at the request seam, and system tests only for the highest-risk end-to-end flows.
- Introduce query objects only when the query becomes a first-class subsystem such as saved filters, full-text search, reporting, or adapter-specific search backends.
- Keep orchestration, importers, parsers, payloads, and workflow objects in
app/modelsnamespaces when they are still part of the domain language. - Preserve deliberate advanced model patterns: concern contracts, association-proxy APIs, event fan-out, lifecycle gates, and domain-owned representations.
- Favor business verbs such as
publish,move_to,link_inventory, orsync_store_referencesover form-shaped names such asprocess_formorhandle_update. - Reach for a service object only when ownership is genuinely cross-aggregate, infrastructure-heavy, or not naturally expressible as one model-facing API.
- When a non-CRUD controller action starts to feel like its own concept, prefer a small nested resource controller before adding another member or collection action to a broad controller.
- Use controller scoping concerns such as
ProductScopedorSaleScopedfor repeated boundary loading when several small controllers share the same resource seam. 19a. “Shared” includes a namespaced controller family; do not create one-off concerns just to split one broad controller. - Treat command-style endpoints as write resources: prefer
POST,PATCH, orDELETEresource routes overGETlinks for actions such as pulls, links, moves, or webhook confirmations.
Placement Heuristics
- Use
app/models/<model>/<capability>.rbwhen one model owns the invariant and the feature needs both reads and writes. - Use
app/models/concerns/<concern>.rbwhen the same behavior truly applies to multiple models. - Use
app/models/<subsystem>/objects when the subsystem has its own lifecycle, persistence, params, or backend. - Use controller concerns for request setup, scoping, and policy, not for domain rules.
- Use namespaced controllers and base controllers to separate public, private, settings, and workflow surfaces.
- Keep existing project conventions when they are already strong; do not preserve weak or mixed legacy placement just because it already exists.
Deliverables
- Propose file placement before large refactors.
- Preserve request-scoped context such as tenant, account, user, and timezone.
- Preserve authorization and tenancy boundaries in the starting relation.
- Avoid
default_scopeand controller-built SQL when named scopes can express the intent. - Prefer business names such as
active,archived,awaiting_review, andpreloadedover transport-layer names. - Add or preserve tests at the same ownership seam as the code: capability, request, edge rendering, or async transport.
- For legacy refactors, propose explicit target files under
app/models/<model>/...rather than vague “extract helper object” guidance.
When not to use it
- →When working on React or other frontend UI
- →When the change is frontend UI work
- →When the project conventions are weak or mixed legacy placement
Limitations
- →The skill is not for React or other frontend UI work
- →The skill recommends using app/models/concerns only for behavior reused across multiple models
- →The skill introduces query objects only when the query becomes a first-class subsystem
How it compares
This skill provides a model-centric approach to Rails architecture, explicitly separating domain logic from UI concerns and promoting clear ownership, unlike a generic Rails development approach.
Compared to similar skills
rails-domain-architecture side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| rails-domain-architecture (this skill) | 0 | 2mo | No flags | Advanced |
| skill-rails-upgrade | 1 | 3mo | Review | Intermediate |
| rails-expert | 0 | 4mo | No flags | Advanced |
| rails-testing | 1 | 8mo | No flags | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
skill-rails-upgrade
sickn33
Analyze Rails apps and provide upgrade assessments
rails-expert
Sneha-1608
Use when building or modernizing Rails applications requiring API development, Hotwire reactivity, real-time features, background job processing, deployment automation, or Rails-idiomatic patterns for maximum productivity. Version-aware: adapts to Rails 7.x and 8.x projects.
rails-testing
etewiah
Help with Rails testing including unit tests, integration tests, fixtures, and debugging test failures. Use when working on tests or debugging test issues.
ruby-pro
sickn33
Write idiomatic Ruby code with metaprogramming, Rails patterns, and performance optimization. Specializes in Ruby on Rails, gem development, and testing frameworks. Use PROACTIVELY for Ruby refactoring, optimization, or complex Ruby features.
upgrade-dependencies
codenamev
Upgrade all Ruby gem dependencies to their latest versions with release note review and codebase alignment checks. Use this skill whenever the user asks to update, upgrade, or bump dependencies, gems, or packages — even casually like 'update my gems' or 'are my deps up to date?'
theme-creation
etewiah
Create new themes for PropertyWebBuilder. Use when creating custom themes, styling websites, or modifying theme templates. Handles theme registration, view templates, CSS, and asset configuration.