apply-stack-conventions
Skill26 starsChanged 4 months agoMITView on GitHub
Use when writing new Rails code for the PostgreSQL + Hotwire + Tailwind stack. Not for general architecture review. Trigger words: stack conventions, PostgreSQL, Hotwire, Tailwind, Turbo, Stimulus.
In this repository32 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- apply-code-conventionsSkill
- code-reviewSkill
- create-engine-installerSkill
- create-engineSkill
- document-engineSkill
- extract-engineSkill
- generate-api-collectionSkill
- implement-authorizationSkill
- implement-background-jobSkill
- implement-graphqlSkill
- implement-hotwireSkill
- load-contextSkill
- optimize-performanceSkill
- plan-testsSkill
- rails-featureSkill
- rails-maintenanceSkill
- rails-reviewSkill
- refactor-codeSkill
- release-engineSkill
- review-architectureSkill
- review-engineSkill
- review-migrationSkill
- security-checkSkill
- seed-databaseSkill
- setup-environmentSkill
- test-engineSkill
- test-serviceSkill
- upgrade-engineSkill
- version-apiSkill
- write-testsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
All new code must have its test written and validated before implementation.
- Distinctive: line 31
Write the spec file — show the full file content, not only the path
- Very specific: line 32
Run: bundle exec rspec spec/[path]_spec.rb — verify it FAILS (Observed RED output)
- Distinctive: line 33
Write the implementation code
- Distinctive: line 78
Style: If the project uses a linter, treat it as the source of truth for formatting.
- Distinctive: line 120
Every response must include these sections in order:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Apply Stack Conventions
Quick Reference
| Stack area | Default convention |
| Rails MVC | Thin controllers; move non-trivial business logic into service objects |
| PostgreSQL | Avoid N+1s with includes; use database constraints for integrity |
| Hotwire | Prefer Turbo Frames/Streams before Stimulus; only reach for Stimulus when Turbo cannot handle the interactivity |
| Tailwind | Use utilities in views; extract repeated UI into partials/components |
| Auth | Apply Devise authentication and Pundit authorization to every action that touches access-controlled resources |
HARD-GATE: TDD Cycle
All new code must have its test written and validated before implementation. Follow this exact cycle for every layer:
- Write the spec file — show the full file content, not only the path
- Run:
bundle exec rspec spec/[path]_spec.rb— verify it FAILS (Observed RED output) - Write the implementation code
- Re-run the same command — verify it PASSES (Observed GREEN output)
- Refactor if needed, keeping tests green
CRITICAL: Execute all test commands using your shell/terminal tools. Do not fabricate, mock, or simulate terminal output. Copy-paste the actual observed output. If the environment does not support running tests, stop and tell the user — do not proceed to implementation without verified RED output.
Red-Green Cycle Example
Spec file — spec/models/order_spec.rb
require 'rails_helper'
RSpec.describe Order, type: :model do
describe 'validations' do
it 'is invalid without a total' do
order = build(:order, total: nil)
expect(order).not_to be_valid
expect(order.errors[:total]).to include("can't be blank")
end
end
endRun command
bundle exec rspec spec/models/order_spec.rbObserved RED output — paste actual terminal output here (expect failure)
Model implementation — app/models/order.rb
class Order < ApplicationRecord
validates :total, presence: true
endObserved GREEN output — paste actual terminal output here (expect pass)
Core Process
Stack: Ruby on Rails, PostgreSQL, Hotwire (Turbo + Stimulus), Tailwind CSS.
Style: If the project uses a linter, treat it as the source of truth for formatting. For cross-cutting design principles (DRY, YAGNI, structured logging, rules by directory), use apply-code-conventions.
Feature Development Workflow
For a typical feature, compose stack patterns in this order:
- Model — add validations, associations, scopes; eager-load with
includesfor any association used in loops - Service object — extract non-trivial business logic from the controller (see create-service-object)
- Controller — keep actions thin; delegate to services; respond with
turbo_streamandhtmlformats - View / Turbo wiring — wrap dynamic sections in
<turbo-frame>tags; broadcastturbo_streamresponses from the controller - Stimulus — add a controller only when client-side interactivity cannot be handled by Turbo alone
- Tailwind — apply utility classes to the view; extract repeated patterns into partials or Stimulus targets
Each step should remain testable in isolation before wiring to the next layer. In the final artifact, include a Layer isolation section naming the focused spec or check for model/query, service, controller/request, view/Turbo, Stimulus, and Tailwind. If a layer is not changed, mark it "not applicable"; do not silently omit any layer.
Service Object Pattern
Controllers delegate to a service via .call; the service returns a result hash. See create-service-object and assets/snippets/service_object.rb for the full pattern and implementation details.
# app/controllers/orders_controller.rb
def create
result = CreateOrderService.call(order_params)
if result[:success]
redirect_to result[:record], notice: 'Order created.'
else
render :new, status: :unprocessable_entity
end
endFor eager loading patterns and N+1 fixes, see the Extended Resources section below.
Pitfalls to Avoid
| Issue | Correct approach |
| Controller action with 15+ lines of business logic | Extract to a service object using the .call pattern |
| Accessing a protected resource without an authorisation check | Apply a Pundit policy on every action that touches access-controlled data |
Output Style
Every response must include these sections in order:
- Stack decisions — which Rails, PostgreSQL, Hotwire, Stimulus, Tailwind, auth, and service-object conventions apply.
- Tests-first proof before implementation — follow the HARD-GATE cycle per layer (spec file content → RED output → implementation → GREEN output).
- Layer isolation — focused spec/check for each changed layer; mark unchanged layers "not applicable".
- Layered implementation — separate model/query, service, controller, view, Stimulus, and Tailwind changes.
- Performance and security checks — N+1 prevention, authorization policy use, unsafe params/content handling.
Extended Resources (Progressive Disclosure)
Load these files only when their specific content is needed:
- assets/snippets/eager_loading.rb — Use when applying eager loading patterns to fix N+1 queries
- assets/snippets/n_plus_one_fix_example.rb — Use when you need a complete N+1 fix example with before/after
- assets/snippets/service_object.rb — Use when extracting controller logic into a service object
- assets/snippets/turbo_frame.html.erb — Use when implementing Turbo Frame patterns
- assets/snippets/stimulus_controller.js — Use when adding Stimulus controllers
- assets/snippets/tailwind_component.html.erb — Use when building Tailwind-styled view components
Integration
| Skill | When to chain |
| apply-code-conventions | For design principles, structured logging, and path-specific rules |
| code-review | When reviewing existing code against these conventions |
| create-service-object | When extracting business logic into service objects |
| write-tests | For testing conventions and full red/green/refactor TDD cycle |
| review-architecture | For structural review beyond conventions |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

