carakan/dotfiles/service-patterns
Claude Code and agent skill by carakan/dotfiles
- community
Checking that the SKILL.md file is still in the repository.
Use when controller actions grow beyond simple CRUD, business logic spans multiple models, or operations involve external APIs or multi-step transactions. Also applies when deciding whether to extract a service object, form object, or query object. Covers the Callable concern, Result objects, and file organization patterns.
Install
npx vskill@latest install carakan/dotfiles/service-patternsSKILL.md
The same SKILL.md was published earlier as chaserx/cpc/service-patterns.
Rails Service Patterns
Extract business logic that spans multiple models or involves external systems into service objects to promote single responsibility, testability, and reusability.
When to Extract a Service
Indicators for service extraction:
- Business logic spans multiple models
- An operation involves external API calls
- Multi-step operations need transaction safety
- Logic violates single responsibility in a model
- Controller actions grow beyond simple CRUD
- The same logic is needed in multiple places (controller, job, rake task)
Keep logic in the model when:
- It naturally fits as a model concern (validations, scopes, associations)
- A single ActiveRecord operation is sufficient
- A model callback is more appropriate
Pattern Overview
| Pattern | Use When | Location | |
|---|---|---|---|
| Service Object | Multi-model business logic | app/services/ | |
| Transaction Service | Atomic multi-step operations | app/services/ | |
| External API Service | Third-party integrations | app/services/<provider>/ | |
| Query Object | Complex, reusable queries | app/queries/ | |
| Form Object | Multi-model form submissions | app/forms/ | |
| Result Object | Consistent service return type | app/services/result.rb |
Callable Concern
DRY up the repeated .call class method across services with a shared concern. See examples/callable.rb for the full implementation.
Include in every service to get MyService.call(args) delegation to new(args).call.
Basic Service Object
A minimal service with the Callable concern and Result return type:
See examples/create_post.rb for the full example.
File Organization
Testing Services
Test services through their .call interface. Assert on Result success/failure and side effects. Both RSpec and Minitest examples are available in examples/:
- `examples/create_post_spec.rb` — RSpec example
- `examples/create_post_test.rb` — Minitest example
Design Principles
- Single responsibility — One service does one thing
- Clear interface —
.callclass method with explicit parameters - Consistent return type — Always return a Result object
- Proper error handling — Rescue specific exceptions, never swallow errors
- Testability — Easy to test in isolation, injectable dependencies
- Immutability — Never modify input arguments
Additional Resources
Reference Files
For detailed implementations, patterns, and alternatives:
- `references/result-object.md` — Full Result implementation, Struct-based alternative, and
dry-monadsapproach - `references/transaction-services.md` — Transaction wrapping, nested transactions, and side-effect management
- `references/external-api-services.md` — API wrapper pattern with error handling, timeouts, and retry guidance
- `references/query-objects.md` — Query object pattern, composability, and when to prefer scopes
- `references/form-objects.md` — Multi-model forms with
ActiveModel, validations, and form builder integration
Example Files
Working code in examples/:
- `examples/callable.rb` — Callable concern to DRY up
.callboilerplate - `examples/create_post.rb` — Basic service object
- `examples/transfer_funds.rb` — Transaction service
- `examples/registration_form.rb` — Form object
- `examples/create_post_spec.rb` — RSpec test example
- `examples/create_post_test.rb` — Minitest test example
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/opencode/skills/service-patterns/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/carakan/dotfiles/service-patterns)