Feature Extraction Prompt
Use this prompt to extract a feature from any Rails project into a portable folder structure that can be implemented elsewhere.
Instructions for AI Agent
You are a feature extraction specialist. Your task is to extract a complete, self-contained feature from a Rails project and organize it into a portable folder structure.
Your Objectives
- Analyze the attached files to understand the feature's functionality
- Identify missing dependencies - Look for related files that weren't attached but are crucial:
- Models referenced via
belongs_to,has_many,has_one - Concerns included in models/controllers
- Policies for authorization
- Jobs triggered by the feature
- Mailers used by the feature
- Channels for real-time features
- JavaScript/Stimulus controllers
- View partials and layouts
- Routes configuration
- Migrations for database schema
- Locale/translation files
- Configuration/initializers
- Models referenced via
- Create the extraction folder structure as specified below
- Generate ABOUT.md documenting how everything works
- List required gems with versions
Extraction Folder Structure
Create the following structure for the extracted feature:
extracted_features/
└── <feature_name>/
├── ABOUT.md # Feature documentation
├── GEMS.md # Required gems with versions
├── SCHEMA.md # Database schema/migrations
├── models/
│ ├── <model>.rb
│ └── concerns/
│ └── <concern>.rb
├── controllers/
│ └── <controller>.rb
├── views/
│ └── <resource>/
│ ├── index.html.erb
│ └── _partial.html.erb
├── javascript/
│ └── controllers/
│ └── <stimulus_controller>.js
├── jobs/
│ └── <job>.rb
├── mailers/
│ └── <mailer>.rb
├── channels/
│ └── <channel>.rb
├── policies/
│ └── <policy>.rb
├── helpers/
│ └── <helper>.rb
├── routes/
│ └── routes.rb # Extracted route definitions
├── migrations/
│ └── <migration>.rb
├── config/
│ └── initializers/
│ └── <initializer>.rb
└── locales/
└── en.yml
ABOUT.md Template
Generate the ABOUT.md with this structure:
# <Feature Name>
## Overview
Brief description of what this feature does.
## Architecture
### Data Model
Explain the database structure and relationships between models.
[Entity Relationship Diagram in text form]
### Key Components
#### Models
- `ModelName` - Purpose and responsibilities
#### Controllers
- `ControllerName` - Actions and their purposes
#### Views
- Key views and their functionality
#### JavaScript/Stimulus
- Controllers and their interactions
### Authorization
How permissions/policies work for this feature.
### Background Jobs
Any async processing and when it's triggered.
### Real-time Features
WebSocket/ActionCable usage if any.
## Flow Diagrams
### Main User Flow
- User does X
- System responds with Y
- … ```
Configuration
Any configuration options or environment variables needed.
Dependencies
- List of gem dependencies
- External service dependencies
Integration Points
How this feature connects with other parts of the application:
- Which models it expects to exist
- Which user/authentication system it expects
- Any callbacks or hooks
Testing
Key test scenarios to cover when implementing.
### GEMS.md Template
```markdown
# Required Gems
## Core Dependencies
```ruby
# Gemfile additions (versions are reference only - use target project's versions if gem exists)
gem 'gem_name'
Development/Test Dependencies
group :development, :test do
gem 'gem_name'
end
Notes
- Version Policy: If the gem already exists in the target project, use that version. Only specify versions for new gems.
- Gem-specific configuration requirements
- Any minimum version requirements for specific features ```
SCHEMA.md Template
# Database Schema
## Tables
### table_name
```ruby
create_table :table_name do |t|
t.string :column_name
t.references :association, foreign_key: true
t.timestamps
end
add_index :table_name, :column_name
Migrations (in order)
YYYYMMDDHHMMSS_create_table_name.rbYYYYMMDDHHMMSS_add_column_to_table.rb```
Feature to Extract
Feature Name
[FEATURE_NAME]
Feature Description
[FEATURE_DESCRIPTION]
Source Project Context
- Rails version:
- Ruby version:
- Key architectural patterns:
Attached Files
- File 1
- File 2
- …
Known Dependencies
- Gems:
- External services:
Extraction Checklist
Before completing the extraction, verify:
- All models have their associations' target models identified
- All concerns included in models/controllers are extracted
- All policies for authorization are included
- All background jobs are identified
- All mailers are included
- All ActionCable channels are included
- All Stimulus controllers are extracted
- All view partials are included
- Routes are documented
- Migrations/schema is documented
- Gems are listed with versions
- Configuration/initializers are included
- Locales/translations are included
- ABOUT.md fully documents the feature
- Integration points with external systems are documented
AI Agent: Begin Extraction
Once you have the feature description and attached files, proceed with:
- Analyze - Study all attached files and identify the feature's scope
- Discover - Find missing files by analyzing:
belongs_to,has_many,has_oneassociationsincludestatements for concernsauthorizecalls for policiesperform_latercalls for jobsdeliver_latercalls for mailersbroadcast_tocalls for channelsdata-controllerattributes for Stimulusrender partial:calls for partials- Route helpers used in controllers/views
- Request - Ask for any missing files that are critical
- Extract - Create the folder structure with all files
- Document - Generate comprehensive ABOUT.md, GEMS.md, SCHEMA.md
- Verify - Run through the extraction checklist