A collection of specialized AI agents for modern Rails development, for AI driven-development and follow TDD best practices.
Built using insights from GitHub's analysis of 2,500+ agent.md files.
Most AI coding assistants treat Rails like any other framework. These agents understand:
- ποΈ Rails Architecture: Service Objects, Query Objects, Presenters, Form Objects
- π Authorization: Pundit policies with least privilege principle
- β‘ Rails 8 Features: Solid Queue,
normalizes,generates_token_for,authenticate_by - π¨ Modern Stack: Hotwire (Turbo + Stimulus), ViewComponent, Tailwind CSS
- β TDD Workflow: RED β GREEN β REFACTOR
@feature_planner_agent- Analyzes feature specs, breaks down into tasks, recommends which specialist agents to use
@tdd_red_agent- Writes failing tests FIRST (RED phase of TDD)@rspec_agent- Expert in RSpec testing for models, services, controllers, etc.@tdd_refactoring_agent- Refactors code while keeping all tests green (REFACTOR phase)
@model_agent- Creates thin ActiveRecord models with validations, associations, scopes@controller_agent- Creates thin RESTful controllers that delegate to services@service_agent- Creates business service objects with Result patterns@query_agent- Creates query objects for complex database queries (prevents N+1)@form_agent- Creates form objects for multi-model forms@presenter_agent- Creates presenters/decorators for view logic@policy_agent- Creates Pundit authorization policies (deny by default)@view_component_agent- Creates tested ViewComponents with Hotwire@job_agent- Creates background jobs with Solid Queue@mailer_agent- Creates mailers with HTML/text templates and previews@migration_agent- Creates safe, reversible, production-ready migrations
@review_agent- Analyzes code quality, runs static analysis (read-only)@lint_agent- Fixes code style and formatting (no logic changes)@security_agent- Audits security with Brakeman and Bundler Audit
Here's how to use the agents together for a new feature:
1. @feature_planner_agent analyze the user authentication feature
2. @tdd_red_agent write failing tests for User model
3. @model_agent implement the User model to pass the tests
4. @tdd_red_agent write failing tests for AuthenticationService
5. @service_agent implement AuthenticationService
6. @controller_agent create SessionsController with authorization
7. @review_agent check the implementation
8. @tdd_refactoring_agent improve the code structure
9. @lint_agent fix any style issues
Each agent follows best practices:
- YAML Frontmatter: Each agent has
nameanddescription - Executable Commands: Specific commands with flags (e.g.,
bundle exec rspec spec/models/user_spec.rb:25) - Three-Tier Boundaries:
- β Always: Things the agent must do
β οΈ Ask first: Actions requiring confirmation- π« Never: Hard limits
- Code Examples: Real good/bad examples instead of abstract descriptions
- Concise: Each under 1,000 lines to stay within AI context limits
- Tech Stack Specified: Ruby 3.3, Rails 8.1, PostgreSQL, Pundit, ViewComponent
- Project Structure: Clear file paths and architecture
- Commands First: Testing, linting, and verification commands
- Rails Conventions: Follows Rails way and modern best practices
These agents are optimized for the Rails 8.x stack:
- Ruby 3.3+
- Rails 8.x
- PostgreSQL
- Hotwire (Turbo + Stimulus)
- ViewComponent
- Tailwind CSS
- Solid Queue (database-backed jobs)
- Pundit (authorization)
- RSpec + FactoryBot (testing)
module Users
class CreateService < ApplicationService
def call
# Returns Result.new(success:, data:, error:)
end
end
enddef create
authorize User
result = Users::CreateService.call(params: user_params)
if result.success?
redirect_to result.data
else
# Handle error
end
endclass Users::SearchQuery
def call(params)
@relation
.then { |rel| filter_by_status(rel, params[:status]) }
.then { |rel| search_by_name(rel, params[:q]) }
end
endclass UserPolicy < ApplicationPolicy
def update?
user.present? && (record.id == user.id || user.admin?)
end
endAll agents follow strict boundaries to prevent mistakes:
| Agent Type | Never Does |
|---|---|
| TDD Red | Never modifies source code, only writes tests |
| Model | Never adds business logic (delegates to services) |
| Controller | Never implements business logic (delegates to services) |
| Service | Never skips error handling or Result objects |
| Refactoring | Never changes behavior, never refactors with failing tests |
| Migration | Never modifies migrations that have already run |
| Security | Never modifies credentials, secrets, or production configs |
| Lint | Never changes business logic, only formatting |
@feature_planner_agent I need to add a blog post feature with comments
The planner will:
- Analyze requirements
- Break down into models, services, controllers
- Recommend the sequence of agents to use
- Suggest the TDD approach
@tdd_red_agent write tests for a Post model with title, body, published_at, and belongs_to :author
The agent will:
- Create
spec/models/post_spec.rbwith failing tests - Create
spec/factories/posts.rb - Verify tests fail for the right reason
- Document what code needs to be implemented
@model_agent implement the Post model to pass the tests
The agent will:
- Create
app/models/post.rb - Add validations, associations, scopes
- Keep the model thin (no business logic)
- Run tests to verify they pass
@review_agent check the Post implementation
The agent will:
- Run Brakeman for security issues
- Run RuboCop for style violations
- Check for SOLID principle violations
- Provide actionable feedback (no modifications)
These agents are designed to be customized for your team's needs. Feel free to:
- Adjust boundaries based on your workflow
- Add project-specific commands
- Include custom validation rules
- Extend with your own coding standards
Built following the insights from:
- How to write a great agents.md by GitHub
MIT License - Feel free to use and adapt these agents for your projects.