rails-architecture
from thibautbaissac/rails_ai_agents
A collection of specialized AI agents for Rails 8.1 development, for AI driven-development and follow TDD best practices.
268 stars31 forksUpdated Jan 20, 2026
npx skills add https://github.com/thibautbaissac/rails_ai_agents --skill rails-architectureSKILL.md
Modern Rails 8 Architecture Patterns
Overview
Rails 8 follows "convention over configuration" with a layered architecture that separates concerns. This skill guides architectural decisions for clean, maintainable code.
Architecture Decision Tree
Where should this code go?
│
├─ Is it view/display formatting?
│ └─ → Presenter (see: rails-presenter skill)
│
├─ Is it complex business logic?
│ └─ → Service Object (see: rails-service-object skill)
│
├─ Is it a complex database query?
│ └─ → Query Object (see: rails-query-object skill)
│
├─ Is it shared behavior across models?
│ └─ → Concern (see: rails-concern skill)
│
├─ Is it authorization logic?
│ └─ → Policy (see: authorization-pundit skill)
│
├─ Is it reusable UI with logic?
│ └─ → ViewComponent (see: viewcomponent-patterns skill)
│
├─ Is it async/background work?
│ └─ → Job (see: solid-queue-setup skill)
│
├─ Is it a complex form (multi-model, wizard)?
│ └─ → Form Object (see: form-object-patterns skill)
│
├─ Is it a transactional email?
│ └─ → Mailer (see: action-mailer-patterns skill)
│
├─ Is it real-time/WebSocket communication?
│ └─ → Channel (see: action-cable-patterns skill)
│
├─ Is it data validation only?
│ └─ → Model (see: rails-model-generator skill)
│
└─ Is it HTTP request/response handling only?
└─ → Controller (see: rails-controller skill)
Layer Interaction Flow
┌─────────────────────────────────────────────────────────────┐
│ REQUEST │
└─────────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ CONTROLLER │
│ • Authenticate (Authentication concern) │
│ • Authorize (Policy) │
│ • Parse params │
│ • Delegate to Service/Query │
└──────────┬─────────────────────────────────┬────────────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ SERVICE │ │ QUERY │
│ • Business logic │ │ • Complex queries │
│ • Orchestration │ │ • Aggregations │
│ • Transactions │ │ • Reports │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ MODEL │
│ • Validations • Associations • Scopes • Callbacks │
└─────────────────────────┬───────────────────────────────────┘
│
┌──────────────┴──────────────┐
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ PRESENTER │ │ VIEW COMPONENT │
│ • Formatting │ │ • Reusable UI │
│ • Display logic │ │ • Encapsulated │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
└──────────────┬──────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ RESPONSE │
└─────────────────────────────────────────────────────────────┘
ASYNC FLOWS:
┌─────────────────────┐ ┌─────────────────────┐
│ JOB │ │ CHANNEL │
│ • Background work │ │ • Real-time │
│ • Solid Queue │ │ • WebSockets │
└─────────────────────┘ └─────────────────────┘
EMAIL FLOWS:
┌─────────────────────┐
│ MAILER │
│ • Transactional │
│ • Notifications │
└─────────────────────┘
See layer-interactions.md for detailed examples.
Layer Responsibilities
| Layer | Responsibility | Should NOT contain |
|---|---|---|
| Controller | HTTP, params, response | Business logic, queries |
| Model | Data, validations, relations | Display logic, HTTP |
| Service | Business logic, orchestration | HTTP, display logic |
| Query | Complex database queries | Business logic |
| Presenter | View formatting, badges | Business logic, queries |
| Policy | Authorization rules | Business logic |
| Component | Reusable UI encapsulation | Business logic |
| Job | Async processing | HTTP, display logic |
| Form | Complex form handling | Persistence logic |
| Mailer | Email composition | Business logic |
| Channel | WebSocket communication | Business logic |
Project Directory Structure
app/
├── channels/ # Action Cable channels
├── components/ # ViewComponents (UI +
...
Repository Stats
Stars268
Forks31
LicenseMIT License