Rails Expert
Purpose
Provides expert Ruby on Rails development expertise specializing in Rails 7+ modern features, Hotwire stack (Turbo, Stimulus), and modern Rails patterns. Excels at building full-stack web applications with server-rendered HTML, real-time updates, and structured client-side behavior without heavy JavaScript frameworks.
When to Use
- Building modern Rails 7+ applications with Hotwire (Turbo, Stimulus)
- Implementing real-time features with Turbo Streams and Action Cable
- Migrating legacy Rails apps to modern Rails patterns and conventions
- Building API-first Rails applications with JSON:API or GraphQL
- Optimizing Rails application performance (database queries, N+1, caching)
- Implementing complex Rails patterns (Service Objects, Form Objects, Query Objects)
- Integrating Rails with modern frontend tools (Import Maps, esbuild, Vite)
Quick Start
Invoke this skill when:
- Building Rails 7+ apps with Hotwire/Turbo/Stimulus
- Implementing real-time features (Turbo Streams, Action Cable)
- Migrating legacy Rails to modern patterns
- Building API-first Rails (JSON:API, GraphQL)
- Optimizing performance (N+1, caching, eager loading)
- Using Rails patterns (Service Objects, Form Objects, Query Objects)
Do NOT invoke when:
- Only frontend development needed → Use frontend-developer or react-specialist
- Database-specific optimization → Use database-optimizer or postgres-pro
- Pure API design without Rails → Use api-designer
- DevOps/deployment only → Use devops-engineer
Core Capabilities
Rails 7+ Modern Features
- Hotwire: Turbo, Stimulus, and dynamic HTML updates without JavaScript frameworks
- Import Maps: JavaScript dependency management without build tools
- Rails 7 Action Text: Rich text editing with modern UI
- Encrypted Credentials: Enhanced security for sensitive data
- Async Query Loading: Improved database query performance
- Multi-DB Support: Primary/replica database configurations
- Parallel Testing: Faster test execution across processes
- Async Action Mailer: Non-blocking email delivery
Hotwire Stack
- Turbo Drive: Faster page navigation with automatic page caching
- Turbo Frames: Partial page updates without full reloads
- Turbo Streams: Real-time updates over WebSocket or SSE
- Stimulus Controllers: Structured client-side JavaScript behavior
- Turbo Morph: Smart DOM diffing for minimal re-renders
Modern Rails Patterns
- Service Objects: Extract business logic from controllers
- Query Objects: Complex database queries as reusable objects
- Form Objects: Handle complex form logic and validation
- Decorators: Presentational logic separation
- View Components: Reusable UI component architecture
- API Resources: Consistent API response formatting
Decision Framework
Rails Feature Selection
Rails Development Decision
├─ Need real-time updates
│ ├─ User-specific updates → Turbo Streams + Action Cable
│ ├─ Broadcast to multiple users → Action Cable channels
│ └─ Simple form responses → Turbo Streams over HTTP
│
├─ Frontend architecture
│ ├─ Minimal JS, server-rendered → Hotwire (Turbo + Stimulus)
│ ├─ Complex client-side logic → Rails API + React/Vue
│ └─ Hybrid approach → Turbo Frames for islands of interactivity
│
├─ Database strategy
│ ├─ Read-heavy workload → Multi-DB with read replicas
│ ├─ Complex queries → Query Objects + proper indexing
│ └─ Caching needed → Russian doll caching + fragment caching
│
└─ Code organization
├─ Fat models → Extract Service Objects
├─ Complex validations → Form Objects
└─ Business logic in controllers → Move to services
Performance Optimization Matrix
| Issue |
Solution |
Implementation |
| N+1 queries |
Eager loading |
includes(:association) / preload |
| Slow counts |
Counter caches |
counter_cache: true on associations |
| Repeated queries |
Fragment caching |
cache @object do blocks |
| Large datasets |
Pagination |
Kaminari / Pagy gems |
| Slow API responses |
JSON caching |
stale? / fresh_when |
Best Practices
Rails 7+ Features
- Hotwire First: Use Turbo/Stimulus before reaching for JS frameworks
- Import Maps: Manage JS dependencies without complex bundlers
- Async Query Loading: Leverage parallel query execution
- Multi-DB: Use read replicas for read-heavy workloads
Code Organization
- Service Objects: Extract business logic from controllers
- Query Objects: Encapsulate complex database queries
- Form Objects: Handle complex form validation logic
- View Components: Create reusable, testable UI components
Performance
- Eager Loading: Always use includes/preload for associations
- Counter Caches: Pre-calculate counts for associations
- Caching Strategy: Implement multi-level caching
- Database Indexes: Add indexes based on query patterns
Testing
- System Tests: Use for critical user journeys
- Component Tests: Test View Components in isolation
- Request Tests: Test API endpoints comprehensively
- Model Tests: Test business logic at unit level
Anti-Patterns
Architecture Anti-Patterns
- Fat Controllers: Business logic in controllers - use Service Objects and POROs
- Massive Models: Models handling too many responsibilities - extract concerns
- Callback Spaghetti: Complex callback chains - use service objects
- Skinny Controller, Fat Model: All logic in model - balance distribution
Database Anti-Patterns
- N+1 Queries: Not using eager loading - use includes/joins/preload
- Missing Indexes: Slow queries without proper indexes - analyze and add
- Counter Cache Miss: Repeated count queries - use counter caches
- Migrations Without Down: Non-reversible migrations - ensure reversibility
Performance Anti-Patterns
- Eager Loading Excess: Over-eager loading causing memory issues
- Missing Caching: No caching strategy - implement appropriate levels
- Render Bloat: Heavy view rendering - use fragments and caching
- Job Queue Backlog: No background job processing - use Active Job
Additional Resources
- Detailed Technical Reference: See REFERENCE.md
- Code Examples & Patterns: See EXAMPLES.md
1---2name: rails-expert3description: Rails 7+ specialist with expertise in Hotwire, Turbo, Stimulus, and modern Rails development4---5
6# Rails Expert
7
8## Purpose
9
10Provides expert Ruby on Rails development expertise specializing in Rails 7+ modern features, Hotwire stack (Turbo, Stimulus), and modern Rails patterns. Excels at building full-stack web applications with server-rendered HTML, real-time updates, and structured client-side behavior without heavy JavaScript frameworks.
11
12## When to Use
13
14- Building modern Rails 7+ applications with Hotwire (Turbo, Stimulus)
15- Implementing real-time features with Turbo Streams and Action Cable
16- Migrating legacy Rails apps to modern Rails patterns and conventions
17- Building API-first Rails applications with JSON:API or GraphQL
18- Optimizing Rails application performance (database queries, N+1, caching)
19- Implementing complex Rails patterns (Service Objects, Form Objects, Query Objects)
20- Integrating Rails with modern frontend tools (Import Maps, esbuild, Vite)
21
22## Quick Start
23
24**Invoke this skill when:**
25- Building Rails 7+ apps with Hotwire/Turbo/Stimulus
26- Implementing real-time features (Turbo Streams, Action Cable)
27- Migrating legacy Rails to modern patterns
28- Building API-first Rails (JSON:API, GraphQL)
29- Optimizing performance (N+1, caching, eager loading)
30- Using Rails patterns (Service Objects, Form Objects, Query Objects)
31
32**Do NOT invoke when:**
33- Only frontend development needed → Use frontend-developer or react-specialist
34- Database-specific optimization → Use database-optimizer or postgres-pro
35- Pure API design without Rails → Use api-designer
36- DevOps/deployment only → Use devops-engineer
37
38## Core Capabilities
39
40### Rails 7+ Modern Features
41- **Hotwire**: Turbo, Stimulus, and dynamic HTML updates without JavaScript frameworks
42- **Import Maps**: JavaScript dependency management without build tools
43- **Rails 7 Action Text**: Rich text editing with modern UI
44- **Encrypted Credentials**: Enhanced security for sensitive data
45- **Async Query Loading**: Improved database query performance
46- **Multi-DB Support**: Primary/replica database configurations
47- **Parallel Testing**: Faster test execution across processes
48- **Async Action Mailer**: Non-blocking email delivery
49
50### Hotwire Stack
51- **Turbo Drive**: Faster page navigation with automatic page caching
52- **Turbo Frames**: Partial page updates without full reloads
53- **Turbo Streams**: Real-time updates over WebSocket or SSE
54- **Stimulus Controllers**: Structured client-side JavaScript behavior
55- **Turbo Morph**: Smart DOM diffing for minimal re-renders
56
57### Modern Rails Patterns
58- **Service Objects**: Extract business logic from controllers
59- **Query Objects**: Complex database queries as reusable objects
60- **Form Objects**: Handle complex form logic and validation
61- **Decorators**: Presentational logic separation
62- **View Components**: Reusable UI component architecture
63- **API Resources**: Consistent API response formatting
64
65## Decision Framework
66
67### Rails Feature Selection
68
69```
70Rails Development Decision
71├─ Need real-time updates
72│ ├─ User-specific updates → Turbo Streams + Action Cable
73│ ├─ Broadcast to multiple users → Action Cable channels
74│ └─ Simple form responses → Turbo Streams over HTTP
75│
76├─ Frontend architecture
77│ ├─ Minimal JS, server-rendered → Hotwire (Turbo + Stimulus)
78│ ├─ Complex client-side logic → Rails API + React/Vue
79│ └─ Hybrid approach → Turbo Frames for islands of interactivity
80│
81├─ Database strategy
82│ ├─ Read-heavy workload → Multi-DB with read replicas
83│ ├─ Complex queries → Query Objects + proper indexing
84│ └─ Caching needed → Russian doll caching + fragment caching
85│
86└─ Code organization
87 ├─ Fat models → Extract Service Objects
88 ├─ Complex validations → Form Objects
89 └─ Business logic in controllers → Move to services
90```
91
92### Performance Optimization Matrix
93
94| Issue | Solution | Implementation |
95|-------|----------|----------------|
96| N+1 queries | Eager loading | `includes(:association)` / `preload` |
97| Slow counts | Counter caches | `counter_cache: true` on associations |
98| Repeated queries | Fragment caching | `cache @object do` blocks |
99| Large datasets | Pagination | Kaminari / Pagy gems |
100| Slow API responses | JSON caching | `stale?` / `fresh_when` |
101
102## Best Practices
103
104### Rails 7+ Features
105- **Hotwire First**: Use Turbo/Stimulus before reaching for JS frameworks
106- **Import Maps**: Manage JS dependencies without complex bundlers
107- **Async Query Loading**: Leverage parallel query execution
108- **Multi-DB**: Use read replicas for read-heavy workloads
109
110### Code Organization
111- **Service Objects**: Extract business logic from controllers
112- **Query Objects**: Encapsulate complex database queries
113- **Form Objects**: Handle complex form validation logic
114- **View Components**: Create reusable, testable UI components
115
116### Performance
117- **Eager Loading**: Always use includes/preload for associations
118- **Counter Caches**: Pre-calculate counts for associations
119- **Caching Strategy**: Implement multi-level caching
120- **Database Indexes**: Add indexes based on query patterns
121
122### Testing
123- **System Tests**: Use for critical user journeys
124- **Component Tests**: Test View Components in isolation
125- **Request Tests**: Test API endpoints comprehensively
126- **Model Tests**: Test business logic at unit level
127
128## Anti-Patterns
129
130### Architecture Anti-Patterns
131- **Fat Controllers**: Business logic in controllers - use Service Objects and POROs
132- **Massive Models**: Models handling too many responsibilities - extract concerns
133- **Callback Spaghetti**: Complex callback chains - use service objects
134- **Skinny Controller, Fat Model**: All logic in model - balance distribution
135
136### Database Anti-Patterns
137- **N+1 Queries**: Not using eager loading - use includes/joins/preload
138- **Missing Indexes**: Slow queries without proper indexes - analyze and add
139- **Counter Cache Miss**: Repeated count queries - use counter caches
140- **Migrations Without Down**: Non-reversible migrations - ensure reversibility
141
142### Performance Anti-Patterns
143- **Eager Loading Excess**: Over-eager loading causing memory issues
144- **Missing Caching**: No caching strategy - implement appropriate levels
145- **Render Bloat**: Heavy view rendering - use fragments and caching
146- **Job Queue Backlog**: No background job processing - use Active Job
147
148## Additional Resources
149
150- **Detailed Technical Reference**: See [REFERENCE.md](REFERENCE.md)
151- **Code Examples & Patterns**: See [EXAMPLES.md](EXAMPLES.md)