All chapters
Appendix6 min read

AI + ARC in Practice

A cookbook for pattern-driven AI collaboration

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:

  1. Identify what's common (the pattern)
  2. Identify what varies (the configuration)
  3. Propose a generic pattern that could replace all three
  4. 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:

  1. [use case 1]
  2. [use case 2]
  3. [use case 3]

Potential future use cases: [speculative use case]

Questions:

  1. Does this pattern actually fit all known use cases, or am I forcing it?
  2. What edge cases might break the abstraction?
  3. Is this pattern too generic (will need constant extension) or too specific?
  4. 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

IncludeExclude
Pattern interfaces/typesFull implementation details
Usage examples (minimal)Entire codebase
Key rules and constraintsHistorical context
Naming conventionsWhy decisions were made
Current task specificsUnrelated 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

  1. Build feature A (hardcoded) [human + AI]
  2. Build feature B (hardcoded) [human + AI]
  3. Notice similarity [human]
  4. Ask AI to analyze both and propose pattern [AI]
  5. Review and refine pattern boundary [human]
  6. Ask AI to implement pattern [human + AI]
  7. Ask AI to migrate A and B to pattern [AI]
  8. Review migrations [human]

Workflow: Pattern Application

  1. Identify which pattern applies [human]
  2. Provide pattern context to AI [human]
  3. AI generates implementation [AI]
  4. Review for semantic correctness [human]
  5. Ship [human]

Time comparison:

  • Without pattern: 2 hours generation + 6 hours review/refactor
  • With pattern: 10 minutes generation + 30 minutes review

Workflow: Pattern Evolution

  1. New requirement doesn't fit pattern [human]
  2. Ask AI how to modify pattern for X [AI]
  3. Review backward compatibility [human]
  4. Ask AI to implement pattern changes [human + AI]
  5. Ask AI to update all existing uses [AI]
  6. 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:

  1. Does it correctly use [PatternName]?
  2. Does it follow our naming conventions?
  3. Are there any edge cases not handled?
  4. Does it introduce dependencies it shouldn't?
  5. 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:

  1. New code using the pattern
  2. List of behavioral differences (if any)
  3. 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 AIKeep Human
Generating pattern implementationsDeciding pattern boundaries
Migrating code to patternsReviewing semantic correctness
Boilerplate within patternsBusiness logic edge cases
Documentation draftsArchitectural decisions
Test generation for patternsValidating test coverage

The rule: AI executes within patterns. Humans define patterns and validate meaning.