Pattern Analysis
Purpose
Audit the codebase for existing patterns and conventions, then evaluate proposed changes for consistency.
Scope Constraints
- Covers file naming, directory structure, component patterns, data fetching, state management, error handling, and type conventions.
- Does not cover test strategy design or coverage targets — hand off to testing-strategy.
- Does not cover high-level architectural decisions or system decomposition — hand off to architect department.
Inputs
- Codebase or directory to audit
- Proposed changes or new code to evaluate (if applicable)
- Specific concerns or areas of focus (if any)
- Known tech stack and framework conventions
Input Sanitization
No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.
Procedure
Step 1: Scan Structural Patterns
- File naming conventions:
- kebab-case, PascalCase, camelCase, snake_case
- Suffix conventions (.utils.ts, .types.ts, .test.ts, .stories.tsx)
- Directory organization:
- Feature-based (feature/components, feature/hooks, feature/utils)
- Layer-based (components/, hooks/, utils/, types/)
- Hybrid approaches
- Module export patterns:
- Barrel files (index.ts re-exports)
- Direct imports
- Default vs named exports
Step 2: Identify Code Patterns
- Component patterns:
- Server vs client components (React Server Components)
- Composition patterns (render props, compound components, HOCs)
- Prop drilling vs context vs stores
- Data fetching patterns:
- Custom hooks (useQuery, useSWR, custom fetch hooks)
- Server actions
- API routes
- Direct fetch in server components
- State management patterns:
- Local state (useState, useReducer)
- Context (React Context, providers)
- External stores (Zustand, Jotai, Redux)
- URL state (search params, pathname)
- Error handling patterns:
- try/catch blocks
- Result/Either types
- Error boundaries
- Toast notifications
- Type patterns:
- interfaces vs type aliases
- Generic patterns and utility types
- Zod schemas vs manual types
- Shared type files vs co-located types
Step 3: Catalog Existing Conventions
Document discovered conventions:
| Category |
Convention |
Example File |
Frequency |
| File naming |
... |
... |
... |
| Component style |
... |
... |
... |
| Data fetching |
... |
... |
... |
| State management |
... |
... |
... |
| Error handling |
... |
... |
... |
| Type definitions |
... |
... |
... |
| Import ordering |
... |
... |
... |
| Comment style |
... |
... |
... |
| Testing patterns |
... |
... |
... |
Step 4: Evaluate Proposed Changes
For each proposed change, check:
- Does it follow existing naming conventions? (files, variables, functions, components)
- Does it follow existing structural patterns? (directory placement, export style)
- Does it reuse existing utilities/helpers? (don't reinvent what exists)
- Does it introduce a new pattern? If so:
- Is the new pattern justified? (existing pattern inadequate, new requirement)
- Is it better enough to warrant migration? Or just different?
- Will it cause confusion having two patterns for the same thing?
- Does it create inconsistency with similar existing code? (same feature, neighboring files)
Step 5: Produce Recommendations
- Follow these patterns (with file references as examples):
- Pattern A: See
src/components/ExampleComponent.tsx
- Pattern B: See
src/hooks/useExampleHook.ts
- Avoid these patterns (with rationale):
- Anti-pattern X: Because [reason]
- Deprecated pattern Y: Replaced by [alternative]
- Consider refactoring (if new patterns are genuinely better):
- Migrate pattern A to pattern B across [scope]
- Estimated scope: [number of files affected]
Compaction resilience: If context is compacted mid-task, re-read this Procedure section and continue from the next incomplete step.
Handoff
- If the pattern audit reveals test convention inconsistencies or missing test coverage, hand off to testing-strategy for a comprehensive test plan.
- If patterns suggest deeper architectural issues such as unclear module boundaries or circular dependencies, hand off to architect department for structural analysis.
Output Format
Pattern Inventory
| Category |
Pattern |
Example File |
Frequency |
Status |
| File naming |
kebab-case components |
src/components/team-card.tsx |
High |
Standard |
| Data fetching |
useQuery hooks |
src/hooks/use-teams.ts |
High |
Standard |
| ... |
... |
... |
... |
... |
Consistency Report
| Proposed Change |
Existing Pattern |
Match? |
Recommendation |
| ... |
... |
Yes/No |
... |
Recommendations
- Follow: [pattern] — see [file reference]
- Avoid: [anti-pattern] — because [rationale]
- Refactor: [migration suggestion] — [scope and effort]
Quality Checks
Evolution Notes
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: pattern-analysis3description: Use when auditing codebase patterns or evaluating proposed changes for convention consistency. Covers file naming, component patterns, data fetching, state management, and type conventions. Do not use for test plan design or coverage targets (use testing-strategy).4---56# Pattern Analysis78## Purpose910Audit the codebase for existing patterns and conventions, then evaluate proposed changes for consistency.1112## Scope Constraints1314- Covers file naming, directory structure, component patterns, data fetching, state management, error handling, and type conventions.15- Does not cover test strategy design or coverage targets — hand off to testing-strategy.16- Does not cover high-level architectural decisions or system decomposition — hand off to architect department.1718## Inputs1920- Codebase or directory to audit21- Proposed changes or new code to evaluate (if applicable)22- Specific concerns or areas of focus (if any)23- Known tech stack and framework conventions2425## Input Sanitization2627No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.2829## Procedure3031### Step 1: Scan Structural Patterns3233- **File naming conventions:**34 - kebab-case, PascalCase, camelCase, snake_case35 - Suffix conventions (.utils.ts, .types.ts, .test.ts, .stories.tsx)36- **Directory organization:**37 - Feature-based (feature/components, feature/hooks, feature/utils)38 - Layer-based (components/, hooks/, utils/, types/)39 - Hybrid approaches40- **Module export patterns:**41 - Barrel files (index.ts re-exports)42 - Direct imports43 - Default vs named exports4445### Step 2: Identify Code Patterns4647- **Component patterns:**48 - Server vs client components (React Server Components)49 - Composition patterns (render props, compound components, HOCs)50 - Prop drilling vs context vs stores51- **Data fetching patterns:**52 - Custom hooks (useQuery, useSWR, custom fetch hooks)53 - Server actions54 - API routes55 - Direct fetch in server components56- **State management patterns:**57 - Local state (useState, useReducer)58 - Context (React Context, providers)59 - External stores (Zustand, Jotai, Redux)60 - URL state (search params, pathname)61- **Error handling patterns:**62 - try/catch blocks63 - Result/Either types64 - Error boundaries65 - Toast notifications66- **Type patterns:**67 - interfaces vs type aliases68 - Generic patterns and utility types69 - Zod schemas vs manual types70 - Shared type files vs co-located types7172### Step 3: Catalog Existing Conventions7374Document discovered conventions:7576| Category | Convention | Example File | Frequency |77|----------|-----------|--------------|-----------|78| File naming | ... | ... | ... |79| Component style | ... | ... | ... |80| Data fetching | ... | ... | ... |81| State management | ... | ... | ... |82| Error handling | ... | ... | ... |83| Type definitions | ... | ... | ... |84| Import ordering | ... | ... | ... |85| Comment style | ... | ... | ... |86| Testing patterns | ... | ... | ... |8788### Step 4: Evaluate Proposed Changes8990For each proposed change, check:91- **Does it follow existing naming conventions?** (files, variables, functions, components)92- **Does it follow existing structural patterns?** (directory placement, export style)93- **Does it reuse existing utilities/helpers?** (don't reinvent what exists)94- **Does it introduce a new pattern?** If so:95 - Is the new pattern justified? (existing pattern inadequate, new requirement)96 - Is it better enough to warrant migration? Or just different?97 - Will it cause confusion having two patterns for the same thing?98- **Does it create inconsistency with similar existing code?** (same feature, neighboring files)99100### Step 5: Produce Recommendations101102- **Follow these patterns** (with file references as examples):103 - Pattern A: See `src/components/ExampleComponent.tsx`104 - Pattern B: See `src/hooks/useExampleHook.ts`105- **Avoid these patterns** (with rationale):106 - Anti-pattern X: Because [reason]107 - Deprecated pattern Y: Replaced by [alternative]108- **Consider refactoring** (if new patterns are genuinely better):109 - Migrate pattern A to pattern B across [scope]110 - Estimated scope: [number of files affected]111112> **Compaction resilience:** If context is compacted mid-task, re-read this Procedure section and continue from the next incomplete step.113114## Handoff115116- If the pattern audit reveals test convention inconsistencies or missing test coverage, hand off to **testing-strategy** for a comprehensive test plan.117- If patterns suggest deeper architectural issues such as unclear module boundaries or circular dependencies, hand off to **architect department** for structural analysis.118119## Output Format120121### Pattern Inventory122123| Category | Pattern | Example File | Frequency | Status |124|----------|---------|--------------|-----------|--------|125| File naming | kebab-case components | `src/components/team-card.tsx` | High | Standard |126| Data fetching | useQuery hooks | `src/hooks/use-teams.ts` | High | Standard |127| ... | ... | ... | ... | ... |128129### Consistency Report130131| Proposed Change | Existing Pattern | Match? | Recommendation |132|----------------|-----------------|--------|----------------|133| ... | ... | Yes/No | ... |134135### Recommendations1361371. **Follow:** [pattern] — see [file reference]1382. **Avoid:** [anti-pattern] — because [rationale]1393. **Refactor:** [migration suggestion] — [scope and effort]140141## Quality Checks142143- [ ] At least 3 file/code categories audited (naming, structure, data fetching, state, errors)144- [ ] Naming conventions documented with examples145- [ ] Data fetching pattern identified and documented146- [ ] State management pattern identified and documented147- [ ] New code evaluated against each discovered pattern148- [ ] Example files referenced for each pattern149- [ ] Anti-patterns identified with rationale150- [ ] Recommendations are actionable (not vague)151152## Evolution Notes153<!-- Observations appended after each use -->154155---156> Converted and distributed by [TomeVault](https://tomevault.io/claim/dtsong) — claim your Tome and manage your conversions.157<!-- tomevault:4.0:skill_md:2026-04-13 -->