Practical prompts, templates, and examples for integrating AI into ARC workflows.
Pattern Extraction Prompts
Discovering Patterns from Existing Code
When you notice duplication across implementations, use AI to identify the underlying pattern:
Prompt:
I have these 3 implementations that do similar things:
[paste implementation 1]
[paste implementation 2]
[paste implementation 3]
Analyze them and:
- Identify what's common (the pattern)
- Identify what varies (the configuration)
- Propose a generic pattern that could replace all three
- Show how each original would become a configuration of the pattern
What good output looks like:
- Clear separation of structure vs. variation
- A base class/interface/function that captures the pattern
- Configuration objects for each specific case
- Migration path from current code to pattern
Validating Pattern Boundaries
Before investing in a pattern, validate it will actually work:
Prompt:
I'm considering extracting this pattern:
[describe the pattern]
Known use cases:
- [use case 1]
- [use case 2]
- [use case 3]
Potential future use cases: [speculative use case]
Questions:
- Does this pattern actually fit all known use cases, or am I forcing it?
- What edge cases might break the abstraction?
- Is this pattern too generic (will need constant extension) or too specific?
- What would make you recommend NOT extracting this pattern?
Red flags in AI response:
- "You might need to add special cases for..."
- "This assumes X, which may not always be true..."
- "The pattern would need significant modification for..."
These suggest the pattern boundary is wrong.
Structuring Context for AI
The Pattern Context Template
When asking AI to generate code that uses existing patterns, structure your context like this:
Template:
Project Context [1-2 sentences about what the system does]
Existing Patterns
Pattern: [PatternName]
- Purpose: [what problem it solves]
- Location: [file path or package name]
- Usage example: [minimal code example showing how to use it]
- Key rules: [rule 1], [rule 2]
Pattern: [PatternName2]
[same structure]
Current Task [what you want AI to build]
Constraints
- Must use [PatternName] for [specific aspect]
- Follow naming convention: [convention]
- [other constraints]
Example: DataIngestion Pattern Context
Project Context Analytics platform that ingests metrics from multiple business domains (ads, e-commerce, IoT).
Existing Patterns
Pattern: DataIngestion
- Purpose: Normalize data from any source into standard MetricEvent format
- Location: /packages/data-ingestion/
- Key rules: All sources must define a schema, transform functions are pure (no side effects), timestamps normalized to UTC, dimensions are always strings
Usage example:
const source = new DataIngestionSource({
name: 'ecommerce-transactions',
schema: TransactionSchema,
transform: (raw) => ({
timestamp: raw.created_at,
value: raw.amount,
dimensions: {
store_id: raw.store
}
})
});
Current Task Create a new ingestion source for IoT sensor data. Sensors send: { device_id, reading, ts, location: { lat, lng } }
Constraints
- Must use DataIngestion pattern
- Follow naming convention: [Domain][Type]Source (e.g., IoTSensorSource)
- Location dimensions should be formatted as "lat,lng" string
What to Include vs. Exclude
| Include | Exclude |
|---|---|
| Pattern interfaces/types | Full implementation details |
| Usage examples (minimal) | Entire codebase |
| Key rules and constraints | Historical context |
| Naming conventions | Why decisions were made |
| Current task specifics | Unrelated patterns |
Rule of thumb: Include enough for AI to generate correct code, not enough for it to get confused by irrelevant details.
Common AI Mistakes Without Patterns
Mistake 1: Inconsistent Structure
Without patterns:
// AI generates for ads:
function trackAdImpression(adId, ts, userId) {
db.insert('ad_events', {
ad_id: adId,
ts: ts,
user: userId
});
}
// AI generates for e-commerce:
async function logPurchase(data) {
await eventStore.save({
type: 'purchase',
payload: data,
createdAt: new Date()
});
}
Two completely different structures for the same conceptual operation.
With patterns:
// Both use DataIngestion pattern:
const adSource = new DataIngestionSource({
/* config */
});
const ecommerceSource = new DataIngestionSource({
/* config */
});
// Same structure, different configuration
Mistake 2: Reinventing Existing Solutions
Without patterns:
Prompt: "Create a function to validate user input for the checkout form"
AI generates: 400 lines of custom validation logic
With patterns:
Prompt: "Using our ValidationRules pattern, create validation config for checkout form fields"
AI generates: 30 lines of configuration using existing pattern
Mistake 3: Semantic Correctness, Structural Chaos
AI-generated code often:
- Compiles correctly
- Passes basic tests
- Does what was asked
But also:
- Uses different naming conventions
- Puts files in wrong locations
- Doesn't integrate with existing architecture
- Creates implicit dependencies
The pattern fix: Patterns constrain AI output to match existing architecture. The AI fills in the blanks rather than inventing structure.
AI-Assisted Pattern Workflows
Workflow: Pattern Discovery
- Build feature A (hardcoded) [human + AI]
- Build feature B (hardcoded) [human + AI]
- Notice similarity [human]
- Ask AI to analyze both and propose pattern [AI]
- Review and refine pattern boundary [human]
- Ask AI to implement pattern [human + AI]
- Ask AI to migrate A and B to pattern [AI]
- Review migrations [human]
Workflow: Pattern Application
- Identify which pattern applies [human]
- Provide pattern context to AI [human]
- AI generates implementation [AI]
- Review for semantic correctness [human]
- Ship [human]
Time comparison:
- Without pattern: 2 hours generation + 6 hours review/refactor
- With pattern: 10 minutes generation + 30 minutes review
Workflow: Pattern Evolution
- New requirement doesn't fit pattern [human]
- Ask AI how to modify pattern for X [AI]
- Review backward compatibility [human]
- Ask AI to implement pattern changes [human + AI]
- Ask AI to update all existing uses [AI]
- Review and test [human]
Prompt Templates
For Generating New Pattern Implementations
Using the [PatternName] pattern (context below), generate an implementation for [specific use case].
Pattern context: [paste pattern documentation or interface]
Requirements:
- [requirement 1]
- [requirement 2]
Constraints:
- [constraint 1]
- [constraint 2]
Expected output:
- Configuration/implementation file
- Any necessary type definitions
- Brief explanation of non-obvious choices
For Reviewing AI-Generated Code
Review this code against our patterns and standards:
[paste AI-generated code]
Check for:
- Does it correctly use [PatternName]?
- Does it follow our naming conventions?
- Are there any edge cases not handled?
- Does it introduce dependencies it shouldn't?
- Would a new developer understand this code?
If issues found, provide corrected version.
For Migrating Legacy Code to Patterns
Migrate this legacy code to use our [PatternName] pattern:
Legacy code: [paste legacy code]
Pattern interface: [paste pattern interface/documentation]
Requirements:
- Maintain exact same external behavior
- No changes to calling code
- Flag any behaviors that don't fit the pattern cleanly
Output:
- New code using the pattern
- List of behavioral differences (if any)
- Suggested tests to verify migration
The 90% vs 20% Success Rate
Throughout this book, we reference that AI achieves ~90% first-try success with patterns vs ~20% without. Here's what that means:
Without patterns (20% success):
- Code compiles: 95%
- Code runs without errors: 80%
- Code does what was asked: 60%
- Code fits existing architecture: 20%
That last 20% is what matters. The other 80% becomes refactoring work.
With patterns (90% success):
- Code compiles: 98%
- Code runs without errors: 95%
- Code does what was asked: 92%
- Code fits existing architecture: 90%
The difference: patterns constrain the solution space. AI can't invent incompatible structure when the structure is already defined.
When NOT to Use AI
Patterns help AI, but some work should remain human:
| Use AI | Keep Human |
|---|---|
| Generating pattern implementations | Deciding pattern boundaries |
| Migrating code to patterns | Reviewing semantic correctness |
| Boilerplate within patterns | Business logic edge cases |
| Documentation drafts | Architectural decisions |
| Test generation for patterns | Validating test coverage |
The rule: AI executes within patterns. Humans define patterns and validate meaning.