AI: refactoring & extraction
This course reads a Rails app's Layer Contract against the app's own files. Services and query objects there return Result = Data.define(...) through a self.call class method. It starts with an audit of three controllers, which turn out to be thin already. It then reads a single-responsibility service, a service that orchestrates other objects inside one transaction, and query objects that answer cross-domain questions. The last lessons cover prompting an AI tool for an extraction that follows the app's conventions, and reviewing the result before it ships.
What you'll learn
- ✓Auditing controller actions to separate HTTP orchestration from business decisions
- ✓The Result = Data.define and self.call convention for services and query objects
- ✓Single-responsibility services with an injected dependency and a bounded rescue
- ✓Orchestrating other objects inside one transaction with an idempotent XP award
- ✓Namespacing query objects by the business question they answer
- ✓Writing specified extraction prompts and reviewing AI output against the app's conventions
What extraction means in this app
This project's MEMORY.md states its architecture as a Layer Contract. Business logic lives in services, which return Result = Data.define(...). Read-only, cross-model questions live in query objects, which return the same kind of Result. Models keep validations, scopes and associations, with no…
Read the full lesson free →Curriculum
7 lessonsWhat extraction means in this app
Defines extraction through the app's Layer Contract and the Result and self.call shape most services share.
Auditing this app's controllers for extraction candidates
Audits three controllers line by line and finds that each one already delegates its decisions to services.
The anatomy of a well-extracted service
Reads FetchSiteIconService: its Result contract, named constants, injected HTTP client, array-ordered icon rule and bounded rescue.
Orchestration and composition in services
Shows how SubmitQuizService computes the score and delegates the attempt, XP and unlocks to other objects in one transaction.
Cross-domain query objects in practice
Explains why LeaderboardQuery and UserGamificationQuery live in Enrollment and how they compose policies and other queries.
Prompting AI for an extraction
Compares vague and specified extraction prompts and reviews AI output against the app's Result convention.
Putting it together: from audit to extraction
Joins the audit, reading, prompting and review steps, then sets a challenge to extract level-progress math.