rails-hyperdrive-layered-rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +30 -0
  3. data/README.md +89 -0
  4. data/UPSTREAM +4 -0
  5. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/SKILL.md.erb +315 -0
  6. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/authorization-to-policy.md +79 -0
  7. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/callbacks-to-service.md +72 -0
  8. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/complex-input-to-form-object.md +119 -0
  9. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/current-from-model.md +63 -0
  10. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/god-object-decomposition.md +81 -0
  11. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/implicit-to-explicit-state-machine.md +77 -0
  12. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/query-to-query-object.md +63 -0
  13. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/examples/view-logic-to-presenter.md +60 -0
  14. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/callbacks.md +114 -0
  15. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/concerns.md +92 -0
  16. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/helpers.md +66 -0
  17. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/jobs.md +71 -0
  18. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/layer-violations.md +176 -0
  19. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/service-objects.md +131 -0
  20. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/anti-patterns/testing.md +37 -0
  21. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/core/architecture-layers.md +204 -0
  22. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/core/extraction-signals.md +314 -0
  23. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/core/specification-test.md +229 -0
  24. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/action-policy.md +437 -0
  25. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/active-agent.md +275 -0
  26. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/active-delivery.md +221 -0
  27. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/active-job-performs.md +171 -0
  28. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/alba.md +257 -0
  29. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/anyway-config.md +212 -0
  30. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/rubanok.md +246 -0
  31. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/view-component.md +223 -0
  32. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/gems/workflow.md +305 -0
  33. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/collaborator-objects.md +209 -0
  34. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/concerns.md +381 -0
  35. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/filter-objects.md +222 -0
  36. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/form-objects.md +267 -0
  37. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/policy-objects.md +298 -0
  38. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/presenters.md +257 -0
  39. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/query-objects.md +208 -0
  40. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/repositories.md +382 -0
  41. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/serializers.md +256 -0
  42. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/service-objects.md +170 -0
  43. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/state-machines.md +368 -0
  44. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/patterns/value-objects.md +267 -0
  45. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/ai-integration.md +372 -0
  46. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/authorization.md +398 -0
  47. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/callbacks.md +336 -0
  48. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/configuration.md +383 -0
  49. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/current-attributes.md +307 -0
  50. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/instrumentation.md +386 -0
  51. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/notifications.md +373 -0
  52. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/references/topics/view-components.md +454 -0
  53. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/analyze-callbacks.md +255 -0
  54. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/analyze-gods.md +279 -0
  55. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/analyze-services.md +1444 -0
  56. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/analyze.md +376 -0
  57. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/plan.md +249 -0
  58. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/review.md +473 -0
  59. data/lib/rails-hyperdrive-layered-rails/hyperdrive/skills/layered-rails/workflows/spec-test.md +282 -0
  60. data/lib/rails-hyperdrive-layered-rails/version.rb +3 -0
  61. data/lib/rails-hyperdrive-layered-rails.rb +7 -0
  62. metadata +106 -0
@@ -0,0 +1,473 @@
1
+ ---
2
+ lint-skip:
3
+ - rule: reference.one-level-deep
4
+ reason: "Review workflow defers service classification to the service-layer audit workflow; the deep-link anchors (Phase 2.2, §3.6.x) are the authoritative procedure being delegated to, and routing them through SKILL.md would lose precision and indirection users would have to chase."
5
+ ---
6
+
7
+ # Layered Rails Review Workflow
8
+
9
+ Code review applying layered architecture principles to Rails diffs, files, or branches.
10
+
11
+ ## Contents
12
+
13
+ - [Philosophy](#philosophy)
14
+ - [Process](#process)
15
+ - [Review Principles](#review-principles)
16
+ - [Review Checklist](#review-checklist)
17
+ - [Resolving Violations](#resolving-violations)
18
+ - [Reviewing Test Files](#reviewing-test-files)
19
+ - [Output Format](#output-format)
20
+ - [Severity Levels](#severity-levels)
21
+ - [Example Review](#example-review)
22
+ - [Related](#related)
23
+
24
+ ## Philosophy
25
+
26
+ This review evaluates code against the principles from "Layered Design for Ruby on Rails Applications":
27
+
28
+ - **Favor extraction over complication** — when code grows complex, extract to the appropriate layer
29
+ - **Patterns before abstractions** — let code age before extracting; premature abstraction is worse than duplication
30
+ - **Services as waiting room** — `app/services` is temporary residence until proper abstractions emerge
31
+ - **Domain logic stays in models** — avoid anemic models; services orchestrate, models know business rules
32
+ - **Explicit over implicit** — prefer explicit parameters over Current attributes
33
+ - **Lower layers never depend on higher layers** — no reverse dependencies
34
+
35
+ ## Process
36
+
37
+ 1. **Identify changed files** (from git diff or provided paths)
38
+ 2. **Determine layers touched** by the changes
39
+ 3. **Apply layer boundary checks**
40
+ - Grep for `Current.*` in models
41
+ - Check service parameters for request/params objects
42
+ - Look for business logic in controllers
43
+ 4. **Apply the service-layer audit's classification rules** when the diff touches:
44
+ - `app/services/`, `app/agents/`, `app/clients/`, `app/operations/`, `app/notifiers/`, or other application-layer specializations
45
+ - Any **new non-AR class under `app/models/`** (service-shaped POROs, `*Extractor`/`*Suggester`/`*Writer`/`*Checker`/`*Merger`/`*Filler`/`*Enricher` files), or
46
+ - HTTP/SDK/LLM SDK calls anywhere in the diff (`RubyLLM`, `OpenAI`, `Anthropic`, `Stripe::`, `Net::HTTP`, `ActionCable.server.broadcast`, etc.)
47
+
48
+ For each such file, run the [service-layer audit's classification rule (Phase 2.2, "purpose first, regex second")](analyze-services.md#22-cluster-classification-promote-vs-demote) and the misplaced-code checks (§3.6.1–§3.6.5). Do **not** improvise a classification from layered-rails principles alone — the audit is the authority. In particular:
49
+
50
+ - **LLM/AI SDK calls** are not domain calculators; they're agent-layer (§3.6.5 + Phase 2.1 cluster table → `app/agents/`).
51
+ - **Non-AR class under `app/models/` that wraps HTTP/SDK/broadcast** → promote to `app/services/` or a specialization layer (§3.6.4). The `app/services/` self-separation gate (§3.6.1) does **not** apply.
52
+ - **Thin SDK/broadcast wrappers** with no value-add → delete or hoist to a concern (§3.6.5). Verify with the SDK's docs whether the wrapper adds anything the SDK already provides.
53
+ - **"Models-first" is not a permission slip.** A single application-shaped class under `app/models/` makes the verdict **Mixed**, not "Mature decomposition (models-first variant)". Recommend introducing `app/services/` for the leaks — see Phase 1.3's decision gate and "What 'models-first' actually means".
54
+ 5. **Run the [specification test](../references/core/specification-test.md)** on key files
55
+ 6. **Check for extraction signals**
56
+ - Score callbacks
57
+ - Assess concern health
58
+ - Check god-object indicators
59
+ 7. **Generate review report** with prioritized issues
60
+
61
+ ## Review Principles
62
+
63
+ ### 1. Layer Boundary Enforcement
64
+
65
+ Check for violations of the four architecture rules:
66
+
67
+ - **No reverse dependencies** — models don't use Current; services don't accept request objects
68
+ - **Abstraction boundaries** — each abstraction belongs to exactly one layer
69
+ - **Unidirectional data flow** — data flows top-to-bottom only
70
+ - **Minimal connections** — avoid unnecessary coupling between layers
71
+
72
+ **Flag:**
73
+ - `Current.*` usage in models
74
+ - Request/params objects passed to services
75
+ - Mailers called from model callbacks
76
+ - SQL queries in controllers
77
+ - Business calculations in views
78
+
79
+ ### 2. Specification Test Application
80
+
81
+ Evaluate whether code responsibilities match the layer:
82
+
83
+ - **Controllers** should only handle HTTP concerns (auth, params, response)
84
+ - **Services** should orchestrate domain objects, not contain domain logic
85
+ - **Models** should contain business rules and domain logic
86
+ - **Views** should only format data for display
87
+
88
+ **Ask:**
89
+ - Would testing this require HTTP setup when it shouldn't?
90
+ - Is this test verifying the right layer's responsibility?
91
+ - Could this logic be tested with a simpler, lower-layer test?
92
+
93
+ ### 3. Extraction Signal Detection
94
+
95
+ Identify code that should be extracted:
96
+
97
+ **Callback scoring:**
98
+ | Type | Score | Action |
99
+ |------|-------|--------|
100
+ | Transformer (compute values) | 5/5 | Keep |
101
+ | Normalizer (sanitize input) | 4/5 | Keep |
102
+ | Utility (counter caches) | 4/5 | Keep |
103
+ | Observer (side effects) | 2/5 | Review |
104
+ | Operation (business steps) | 1/5 | Extract |
105
+
106
+ **Concern health:**
107
+ - Behavioral concerns (shared across models) → good
108
+ - Code-slicing concerns (grouping by artifact type) → extract or inline
109
+
110
+ **God-object indicators:**
111
+ - Many methods (50+)
112
+ - High churn (frequently modified)
113
+ - Mixed responsibilities (persistence + presentation + notifications)
114
+
115
+ ### 4. Current Attributes Audit
116
+
117
+ Flag all `Current` usage and evaluate by layer:
118
+
119
+ - **Controllers:** OK (write location)
120
+ - **Services:** review (should it pass explicitly?)
121
+ - **Models:** violation (extract to parameter)
122
+ - **Jobs:** risk (context will be nil)
123
+
124
+ ### 5. Service Object Critique
125
+
126
+ Prevent anemic models:
127
+
128
+ - Does this service contain logic that belongs in the model?
129
+ - Is the service just a thin wrapper around model methods?
130
+ - Are there established conventions (base class, naming, interface)?
131
+
132
+ Identify decomposition opportunities:
133
+
134
+ - Is `app/services` growing unbounded?
135
+ - Do services share patterns that could become abstractions?
136
+ - Are there 3+ services doing similar things?
137
+
138
+ ### 6. Anemic Job Detection
139
+
140
+ Flag job classes that just delegate to model methods:
141
+
142
+ ```ruby
143
+ # BAD: Anemic job
144
+ class NotifyRecipientsJob < ApplicationJob
145
+ def perform(record)
146
+ record.notify_recipients # Single delegation = anemic
147
+ end
148
+ end
149
+ ```
150
+
151
+ **Signals:**
152
+ - Job's `perform` is single line calling method on argument
153
+ - Model has `*_later` method that just calls `SomeJob.perform_later(self)`
154
+ - `app/jobs` has many similar thin wrappers
155
+
156
+ **Recommendation:** Use `active_job-performs` gem:
157
+
158
+ ```ruby
159
+ # GOOD: No separate job file
160
+ class Post < ApplicationRecord
161
+ performs def notify_recipients
162
+ # Logic here
163
+ end
164
+ end
165
+ ```
166
+
167
+ ### 7. Abstraction Assessment
168
+
169
+ Evaluate pattern choices:
170
+
171
+ - Is this the right pattern for the problem?
172
+ - Is there a simpler solution?
173
+ - Does it follow established conventions?
174
+ - Is this premature abstraction?
175
+
176
+ ## Review Checklist
177
+
178
+ ### Layer Violations (Critical)
179
+ - [ ] Models don't access Current attributes
180
+ - [ ] Services don't accept request/params objects
181
+ - [ ] Controllers don't contain business calculations
182
+ - [ ] Views don't query database directly (beyond simple associations)
183
+ - [ ] Mailers aren't called from model callbacks
184
+ - [ ] **Non-AR classes under `app/models/` don't call HTTP/SDK clients, LLM SDKs, `*Job.perform_later`, `*Mailer.deliver_later`, or `ActionCable.server.broadcast`** — those belong in `app/services/` / `app/agents/` / `app/clients/` (see [analyze-services §3.6.4](analyze-services.md#364-application-shaped-classes-under-appmodels--promote-up))
185
+ - [ ] **LLM/AI SDK callers (`RubyLLM`, `OpenAI`, `Anthropic`, …) live in `app/agents/`** — not under `app/models/` as "calculators" (see [analyze-services §3.6.5](analyze-services.md#365-thin-sdk--broadcast-wrappers--delete-hoist-or-promote-in-that-order) + Phase 2.1 cluster table)
186
+ - [ ] **No thin SDK / broadcast wrappers** — a class whose only job is to forward to `ActionCable.server.broadcast` / `RubyLLM.chat` / etc. without policy is dead weight; check the SDK's docs (RubyLLM ships its own retries, ActionCable's broadcast is already the public API)
187
+
188
+ ### Callback Health (Warning)
189
+ - [ ] New callbacks score 4+ on the scale
190
+ - [ ] No operation callbacks (business process steps)
191
+ - [ ] No callback control flags (`skip_*`, `unless: :flag`)
192
+
193
+ ### Concern Health (Warning)
194
+ - [ ] Concerns are behavioral (can be tested in isolation)
195
+ - [ ] No code-slicing (grouping by artifact type)
196
+ - [ ] Concerns aren't overgrown (50+ lines)
197
+
198
+ ### Service Health (Suggestion)
199
+ - [ ] Services follow established conventions
200
+ - [ ] Domain logic remains in models (no anemic models)
201
+ - [ ] Services aren't just thin wrappers
202
+
203
+ ### Model Health (Suggestion)
204
+ - [ ] No god-object indicators (high churn × complexity)
205
+ - [ ] Clear separation of concerns
206
+ - [ ] Reasonable method count
207
+
208
+ ## Resolving Violations
209
+
210
+ When identifying a layer violation (e.g., model triggering notification):
211
+
212
+ ### 1. Trace the Call Chain
213
+
214
+ Find who calls the violating code:
215
+ ```
216
+ Controller/Job → Service → Model (violation here)
217
+ ```
218
+
219
+ ### 2. Identify Existing Orchestrators
220
+
221
+ Look for services, forms, or controllers already coordinating this flow. Check:
222
+ - `app/services/` for related services
223
+ - `app/forms/` for form objects handling this operation
224
+ - Controllers that initiate the action
225
+
226
+ ### 3. Recommend Moving to Orchestrator
227
+
228
+ If an orchestrator exists, recommend moving the side effect there:
229
+
230
+ ```ruby
231
+ # BAD: Model triggers notification
232
+ class License < ApplicationRecord
233
+ def prolong
234
+ update!(status: :active, expires_at: 1.year.from_now)
235
+ LicenseDelivery.with(license: self).purchased.deliver_later # Violation
236
+ end
237
+ end
238
+
239
+ # GOOD: Service orchestrates, model stays pure
240
+ class StripeEventManager
241
+ def handle_invoice_paid(invoice)
242
+ # ... find license, create payment record ...
243
+ license.prolong
244
+ LicenseDelivery.with(license:).purchased.deliver_later
245
+ end
246
+ end
247
+
248
+ class License < ApplicationRecord
249
+ def prolong
250
+ update!(status: :active, expires_at: 1.year.from_now)
251
+ end
252
+ end
253
+ ```
254
+
255
+ ### 4. No Clear Orchestrator
256
+
257
+ If no existing orchestrator, list options without being prescriptive:
258
+ - Move to controller (if called from a single controller action)
259
+ - Create service object (if complex orchestration needed)
260
+ - Create form object (if user input involved)
261
+
262
+ Let the user decide based on their context.
263
+
264
+ ## Reviewing Test Files
265
+
266
+ When reviewing test files, apply these principles:
267
+
268
+ ### Never Recommend Testing Private Methods via `send`
269
+
270
+ Private methods are private for a reason — they're implementation details. Never suggest:
271
+
272
+ ```ruby
273
+ # BAD — testing private steps via send
274
+ processor.send(:parse_json!)
275
+ processor.send(:import_board)
276
+ processor.send(:import_columns)
277
+ ```
278
+
279
+ If private methods need isolated testing, that's a signal the class should be decomposed into smaller public objects. Say that instead.
280
+
281
+ ### Expensive Operations: Combine Assertions Over One-Per-Test Dogma
282
+
283
+ When a test setup is expensive (e.g., importing hundreds of records from a fixture), running it N times for N single-assertion tests is wasteful. Without RSpec + `before_all` (TestProf), Minitest has no way to share expensive state across tests.
284
+
285
+ The pragmatic answer: **combine assertions in fewer tests**. This is better than the alternatives (slow suite, or testing privates via `send`):
286
+
287
+ ```ruby
288
+ # GOOD — run import once, assert everything
289
+ test "import creates board with columns, cards, tags, and comments" do
290
+ processor = TrelloImport::Processor.new(@import)
291
+ processor.import
292
+
293
+ # Board
294
+ assert_equal "HR Manager", @import.board.name
295
+
296
+ # Columns (only open lists)
297
+ assert_equal 3, @import.board.columns.count
298
+ assert @import.board.columns.exists?(name: "Inbox")
299
+
300
+ # Cards
301
+ assert_equal 5, @import.cards_count
302
+ card = @import.board.cards.find_by(title: "First task")
303
+ assert card.published?
304
+
305
+ # Tags
306
+ assert_equal 1, Current.account.tags.where(title: "account").count
307
+
308
+ # Comments
309
+ assert @import.comments_count > 0
310
+ end
311
+ ```
312
+
313
+ Keep separate tests only for genuinely independent scenarios (error paths, edge cases with different fixtures).
314
+
315
+ ### Removing Duplicate Tests: Show What Replaces Them
316
+
317
+ Never recommend simply deleting tests without showing what takes their place. When a higher-layer test duplicates a lower-layer test (e.g., TrelloImport tests duplicating Processor tests), replace the duplicates with a **delegation test** that verifies the lower layer is invoked correctly:
318
+
319
+ ```ruby
320
+ # INSTEAD OF deleting these and leaving nothing:
321
+ # "process imports board"
322
+ # "process imports columns"
323
+ # "process imports cards"
324
+ # ...
325
+
326
+ # REPLACE WITH a delegation test:
327
+ test "process delegates to Processor and tracks status" do
328
+ import = TrelloImport.create!(account: Current.account, user: @user, file: uploaded_file)
329
+
330
+ mock_processor = Minitest::Mock.new
331
+ mock_processor.expect(:import, nil)
332
+ TrelloImport::Processor.stub(:new, mock_processor) do
333
+ import.process
334
+ end
335
+ mock_processor.verify
336
+
337
+ assert import.completed?
338
+ assert_not_nil import.completed_at
339
+ end
340
+ ```
341
+
342
+ This proves TrelloImport delegates to Processor without re-testing all of Processor's behavior.
343
+
344
+ ## Output Format
345
+
346
+ Default review output shape:
347
+
348
+ ```markdown
349
+ ## Layered Rails Review
350
+
351
+ ### Files Reviewed
352
+ - path/to/file.rb (Presentation|Application|Domain|Infrastructure)
353
+
354
+ ### Layer Analysis
355
+ - **Layers touched:** [list]
356
+ - **Data flow:** OK | Violation detected
357
+
358
+ ### Findings
359
+
360
+ 🔴 **Critical: [Issue Type]**
361
+ Location: `path/to/file.rb:line`
362
+ ` ` `ruby
363
+ # Problematic code
364
+ ` ` `
365
+ **Problem:** ...
366
+ **Fix:** ...
367
+
368
+ ⚠️ **Warning: [Issue Type]**
369
+ Location: `path/to/file.rb:line`
370
+ **Problem:** ...
371
+ **Recommendation:** ...
372
+
373
+ 💡 **Suggestion: [Issue Type]**
374
+ [Description with alternative approach]
375
+
376
+ ### Summary
377
+
378
+ **Good:** [what's working]
379
+ **Needs Attention:** [prioritized list]
380
+ **Priority:** [what to address first]
381
+ ```
382
+
383
+ If there are no findings, say so explicitly and note any residual risks or missing verification.
384
+
385
+ ## Severity Levels
386
+
387
+ ### 🔴 Critical (must fix)
388
+ - Layer violation (reverse dependency)
389
+ - Current in models used for business logic
390
+ - Request objects in services
391
+ - Business logic in controllers doing domain calculations
392
+
393
+ ### ⚠️ Warning (should fix)
394
+ - Low-scoring callbacks (1-2/5)
395
+ - Code-slicing concerns
396
+ - Anemic-model risk
397
+ - Missing service conventions
398
+
399
+ ### 💡 Suggestion (consider)
400
+ - Extraction opportunity
401
+ - Pattern alternative
402
+ - Convention improvement
403
+ - Test layer mismatch
404
+
405
+ ## Example Review
406
+
407
+ ```markdown
408
+ ## Layered Rails Review
409
+
410
+ ### Files Reviewed
411
+ - app/controllers/orders_controller.rb (Presentation)
412
+ - app/models/order.rb (Domain)
413
+ - app/services/process_order_service.rb (Application)
414
+
415
+ ### Layer Analysis
416
+ - **Layers touched:** Presentation, Application, Domain
417
+ - **Data flow:** Violation detected
418
+
419
+ ### Findings
420
+
421
+ 🔴 **Critical: Layer Violation**
422
+ Location: `app/models/order.rb:45`
423
+ ` ` `ruby
424
+ def complete!
425
+ self.completed_by = Current.user
426
+ save!
427
+ end
428
+ ` ` `
429
+ **Problem:** Model depends on Current (presentation context). This will fail silently in background jobs.
430
+ **Fix:** Accept user as explicit parameter:
431
+ ` ` `ruby
432
+ def complete!(by:)
433
+ self.completed_by = by
434
+ save!
435
+ end
436
+ ` ` `
437
+
438
+ ⚠️ **Warning: Operation Callback**
439
+ Location: `app/models/order.rb:12`
440
+ ` ` `ruby
441
+ after_commit :sync_to_warehouse, on: :update
442
+ ` ` `
443
+ **Problem:** This is a business operation (score 1/5), not a model concern.
444
+ **Recommendation:** Move to controller or use event-driven approach with Active Support Notifications.
445
+
446
+ 💡 **Suggestion: Anemic Model Risk**
447
+ Location: `app/services/calculate_order_total_service.rb`
448
+ **Problem:** This calculation (`items.sum(&:subtotal) * discount_rate`) is domain logic that belongs in the Order model.
449
+ **Recommendation:** Move `#calculate_total` to Order model. Services should orchestrate, not contain domain logic.
450
+
451
+ ### Summary
452
+
453
+ **Good:**
454
+ - Clean controller structure
455
+ - Proper use of strong parameters
456
+
457
+ **Needs Attention:**
458
+ 1. 🔴 Fix Current.user in Order model (will break in background jobs)
459
+ 2. ⚠️ Move domain logic from service to model
460
+ 3. ⚠️ Extract warehouse sync callback
461
+
462
+ **Priority:** Address layer violation first, then refactor service/model boundary.
463
+ ```
464
+
465
+ ## Related
466
+
467
+ - [Service-layer audit](analyze-services.md) — authoritative source for service classification (Phase 2.2), misplaced-code checks (§3.6.1–§3.6.5), and the "models-first variant" verdict criteria
468
+ - [Specification test](../references/core/specification-test.md)
469
+ - [Layer violations](../references/anti-patterns/layer-violations.md)
470
+ - [Callbacks anti-patterns](../references/anti-patterns/callbacks.md)
471
+ - [Service Objects anti-patterns](../references/anti-patterns/service-objects.md)
472
+ - [AI Integration](../references/topics/ai-integration.md) — the `app/agents/` layer destination for LLM-backed classes
473
+ - [Current attributes](../references/topics/current-attributes.md)