Skip to content

/extract-patterns ​

Extract reusable patterns and best practices from your existing codebase.

Overview ​

The /extract-patterns prompt analyzes your codebase to identify recurring patterns, architectural decisions, and implementation approaches. It helps you document what's working well and creates reusable templates for consistency.

When to Use ​

Use /extract-patterns when you want to:

  • Document existing patterns before scaling the team
  • Create consistency across your codebase
  • Onboard new developers with actual patterns from your code
  • Identify both good patterns and anti-patterns
  • Build a library of reusable solutions
  • Prepare for refactoring by understanding current patterns

Syntax ​

/extract-patterns [focus-area]

Arguments ​

  • focus-area (optional): Specific area to analyze (e.g., "authentication", "API design", "error handling")
    • If omitted, analyzes the entire codebase

Examples ​

Full Codebase Analysis ​

/extract-patterns

Focused Analysis ​

/extract-patterns authentication
/extract-patterns API endpoints
/extract-patterns database queries
/extract-patterns error handling
/extract-patterns state management

What It Does ​

  1. Scans Codebase: Searches for recurring patterns in your code
  2. Categorizes Patterns: Groups findings by type:
    • Architecture patterns
    • Implementation patterns
    • Security patterns
    • Testing patterns
    • Error handling patterns
  3. Documents Patterns: Creates detailed documentation in .orchestre/patterns/
  4. Identifies Anti-patterns: Flags problematic patterns to avoid
  5. Provides Examples: Shows actual code from your project
  6. Suggests Improvements: Recommends enhancements to existing patterns

Output Structure ​

Pattern Documentation ​

Each discovered pattern includes:

markdown
# Pattern: [Pattern Name]

## Description
What this pattern does and why it's used

## When to Use
Specific scenarios where this pattern applies

## Implementation
Code example from your codebase

## Benefits
- Why this pattern works well
- Problems it solves

## Considerations
- Trade-offs
- When not to use it

## Examples in Codebase
- `src/auth/middleware.ts` - Authentication middleware
- `src/api/users.ts` - User API implementation

Pattern Categories ​

Patterns are organized into categories:

Architecture Patterns ​

  • Component structure
  • Module organization
  • Dependency injection
  • Service layers

Implementation Patterns ​

  • Data fetching
  • State management
  • Form handling
  • Validation

Security Patterns ​

  • Authentication
  • Authorization
  • Input sanitization
  • API security

Testing Patterns ​

  • Test structure
  • Mocking strategies
  • Test data management

Files Created ​

The command creates pattern documentation in:

.orchestre/patterns/
├── discovered/
│   ├── architecture/
│   ├── implementation/
│   ├── security/
│   └── testing/
├── anti-patterns.md
└── pattern-index.md

Integration with Templates ​

Extracted patterns can be:

  • Used as templates for new features
  • Referenced by /execute-task for consistency
  • Shared across teams
  • Evolved into best practices

Best Practices ​

  1. Run Regularly: Extract patterns after major features
  2. Review Anti-patterns: Address problematic patterns
  3. Document Decisions: Add context to why patterns exist
  4. Share Knowledge: Use patterns for onboarding
  5. Evolve Patterns: Update as better approaches emerge

Pattern Evolution ​

Track how patterns evolve:

  1. Initial discovery with /extract-patterns
  2. Documentation with /document-feature
  3. Refinement through code reviews
  4. Standardization across the codebase

Common Focus Areas ​

API Patterns ​

/extract-patterns REST API
/extract-patterns GraphQL resolvers
/extract-patterns error responses

Frontend Patterns ​

/extract-patterns component structure
/extract-patterns hooks
/extract-patterns state management

Backend Patterns ​

/extract-patterns database access
/extract-patterns business logic
/extract-patterns background jobs

Testing Patterns ​

/extract-patterns test structure
/extract-patterns test utilities
/extract-patterns mocking

Advanced Usage ​

Comparative Analysis ​

Extract patterns from different parts of your app:

/extract-patterns old-module
/extract-patterns new-module

Then compare approaches to standardize.

Pre-refactoring Analysis ​

Before major refactoring:

/extract-patterns legacy-code

Understand existing patterns before changing them.

Team Alignment ​

Extract patterns from different team members' code:

/extract-patterns src/features/team-a
/extract-patterns src/features/team-b

Identify inconsistencies and align approaches.

  • /discover-context - Analyze project structure and dependencies
  • /research - Research best practices for discovered patterns
  • /document-feature - Document pattern usage in features
  • /orchestrate - Plan standardization of patterns
  • /review - Review code against established patterns

Built with ❤️ for the AI Coding community, by Praney Behl