rails-engine-author/SKILL.md
Use when creating, scaffolding, or refactoring a Rails engine. Covers engine types (Plain, Railtie, Engine, Mountable), namespace isolation, host-app contract definition, and recommended file structure.
npx skillsauth add igmarin/rails-agent-skills rails-engine-authorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill when the task is to create, scaffold, or refactor a Rails engine.
Favor maintainability over cleverness. A good engine has a narrow purpose, a clear host-app integration story, and a small public API.
Keep this skill focused on structure and design. Use adjacent skills for installer details, deep test coverage, release workflow, or documentation work.
| Engine Type | When to Use | |-------------|-------------| | Plain gem | No Rails hooks or app directories needed; pure Ruby library | | Railtie | Needs Rails initialization hooks but not models/controllers/routes/views | | Engine | Needs Rails autoload paths, initializers, migrations, assets, jobs, or host integration | | Mountable engine | Needs its own routes, controllers, views, assets, and namespace boundary |
Before engine work is complete, confirm all of the following:
1. The root file is minimal: requires version, configuration, and engine only.
2. Public-facing engines use isolate_namespace.
3. The root module exposes .configure yielding a Configuration object.
4. Host model references stay configurable strings (for example "User"), never ::User.
5. Engine code never auto-applies migrations at boot.
6. The host contract is documented per the Host App Contract section.
| Pitfall | What to do |
|---------|------------|
| Starting with mountable when plain gem suffices | Use the lightest option — mountable adds routes, controllers, views only when needed |
| Missing isolate_namespace | Mountable and public-facing engines must isolate to avoid constant collisions with host |
| No host contract defined | Without a documented contract, integration becomes guesswork across host apps — see Host App Contract section |
| Engine depends on host internals | Reference host models through configurable class names or adapters |
| No dummy app | Integration must be verified through a real mounted engine, not isolated classes |
rails plugin new my_engine --mountable # mountable engine
rails plugin new my_engine --full # full engine (non-isolated)
rails plugin new my_engine # plain Railtie/gem
bundle exec rake inside the engine must pass.bundle exec rails routes.If the user does not specify the engine type, infer it from the requested behavior and say which type you chose.
Use a structure close to this:
my_engine/
lib/
my_engine.rb
my_engine/version.rb
my_engine/engine.rb
generators/
app/
controllers/
models/
jobs/
views/
config/
routes.rb
locales/
db/
migrate/
spec/ or test/
dummy/
Keep the root module small:
lib/my_engine.rb: requires version, engine, and public configuration entrypoints.lib/my_engine/engine.rb: engine class, initializers, autoload/eager-load behavior, asset/config hooks.lib/my_engine/version.rb: version only.This is the single authoritative definition of the engine's integration surface. Define it before implementation and keep it updated throughout.
Prefer one explicit configuration surface, for example:
MyEngine.configure do |config|
config.user_class = "User"
config.audit_events = true
end
Do not scatter configuration across unrelated constants and initializers.
isolate_namespace for mountable and public-facing engines.config.to_prepare only for reload-sensitive code (e.g. decorators).config.paths['db/migrate'] or ActiveRecord::Migrator in initializers:# WRONG — auto-applies migrations at boot, host loses control
initializer 'my_engine.migrations' do
config.paths['db/migrate'] << root.join('db/migrate')
end
# RIGHT — host copies via install generator, runs manually
# See rails-engine-installers for generator patterns
Use rails-engine-installers for generator-heavy setup, rails-engine-testing for dummy-app coverage, and rails-engine-reviewer for audits.
Minimum coverage through the dummy app (not just isolated classes):
Minimal root module:
# lib/my_engine.rb
require "my_engine/version"
require "my_engine/configuration"
require "my_engine/engine"
module MyEngine
class << self
def configuration
@configuration ||= Configuration.new
end
def configure
yield(configuration)
end
end
end
Minimal mountable engine class:
# lib/my_engine/engine.rb
module MyEngine
class Engine < ::Rails::Engine
isolate_namespace MyEngine
config.generators do |g|
g.test_framework :rspec
g.fixture_replacement :factory_bot
end
end
end
Routes namespaced under engine:
# config/routes.rb
MyEngine::Engine.routes.draw do
root to: 'dashboard#index'
resources :widgets, only: %i[index show]
end
Before calling the engine structure done:
lib/my_engine.rb is still requires + configuration only.::User or ::Employee.db:migrate, ActiveRecord::Migrator, or config.paths['db/migrate'].When asked to create or refactor an engine:
If a real-world engine corpus is available, inspect comparable engines before making structural decisions. Prefer matching successful patterns from mature engines over inventing new conventions.
For a reusable starter layout and file stubs, read reference.md.
| Skill | When to chain | |-------|----------------| | rails-engine-testing | Dummy app setup, integration tests, regression coverage | | rails-engine-reviewer | Findings-first audits, structural review | | rails-engine-docs | README, installation guide, host-app contract documentation | | rails-engine-installers | Generator-heavy setup, install scripts, copy migrations | | api-rest-collection | When the engine exposes HTTP endpoints (generate/update Postman collection) |
development
Entry point for Rails development workflows covering TDD, RSpec, Service Objects, DDD, GraphQL, Engines, and Code Quality. Use when the user asks about Ruby on Rails development patterns, needs RSpec test suites generated, wants service objects scaffolded, is setting up GraphQL schemas, performing Rails code review, refactoring .rb files, working with domain-driven design, implementing background jobs, conducting Rails security checks, or building Rails engines. Generates RSpec tests, structures service objects, enforces TDD workflows, configures GraphQL schemas, and coordinates domain-driven design patterns. Trigger keywords: Rails, RSpec, TDD, Rails testing, Rails refactor, Rails API, Rails code review, domain driven design, service objects, GraphQL, Rails engine, Ruby, .rb, background jobs, Rails migrations, Rails security check.
development
Use when shipping a Rails engine gem — FIRST run full test suite (`bundle exec rspec`) and fix ALL failures, verify gemspec metadata and dependencies match tested Rails/Ruby versions, dry-run: `gem build *.gemspec && gem push --dry-run *.gem` and verify contents, generate CHANGELOG.md organized by category (added/changed/deprecated/removed/fixed), produce step-by-step upgrade notes with before/after code, set semantic version in `lib/[engine_name]/version.rb`, document deprecations with migration paths, load release assets conditionally and state which one informed the output. Trigger words: version bump, changelog, deprecation, gemspec, upgrade, release, publish gem, ship gem.
development
Orchestrates the full Rails TDD cycle with hard gates: test MUST exist, be run, and FAIL for the correct reason (e.g. undefined method, not syntax error) before any implementation code — propose minimal implementation and wait for user approval → verify test PASSES → run full suite with rubocop, brakeman, rspec all green → produce YARD documentation and self-reviewed PR; phases context/test design→implementation→iterate→finish. Use when practicing test-driven development, red-green-refactor, TDD workflow, writing tests before code, adding tests first, or building a Rails feature where specs must gate implementation.
development
Complete Rails project setup loop with hard gates: verify Ruby version matches .ruby-version, Bundler installed, database connection successful, all env vars loaded, and ALL external CI actions pinned to immutable commit SHAs (never mutable tags like @v4) → configure CI/CD pipeline with linting, testing, and security scanning → validate end-to-end with bundle install, db:create, db:migrate, rspec, and write SETUP_CHECKLIST.md; phases context/onboarding→CI/CD configuration→environment validation. Use when starting a new Rails project, running `rails new`, configuring a Gemfile or .ruby-version, setting up a development environment, or wiring up CI/CD for a Ruby on Rails app. Trigger: setup project, new Rails app, configure CI/CD, dev environment setup, rails new, Gemfile setup, .ruby-version, Ruby on Rails project bootstrap.