agentleFS
komlukkomluk/scaffolding/skills/pattern-recognition/SKILL.md

pattern-recognition

Skill16 starsChanged 4 days agoMITView on GitHub

Identify and apply existing codebase patterns for consistency. TRIGGER when: writing new code that should match conventions, or reviewing code for pattern drift. SKIP: language-specific patterns (use python-patterns or react-patterns); security review (use security-review-checklists); should this exist (use necessity-first).

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before writing new code

    line 12
  2. Distinctive:

    When implementing similar features

    line 13
  3. Distinctive:

    Grep before creating: - Search shared modules for an existing function before writing a new one

    line 194

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Pattern Recognition Skill

Standards for identifying and applying existing codebase patterns to maintain consistency.

When to Apply

  • Before writing new code
  • When implementing similar features
  • Code review for pattern consistency
  • Refactoring decisions

Pattern Detection Process

Step 1: Scan Existing Code

ActionPurpose
Find similar modules/componentsMatch structure and naming
Find similar functions/hooksMatch return types and patterns
Find similar servicesMatch error handling and API patterns
Check shared-types locationMatch how the project centralizes types

Step 2: Extract Patterns

ElementWhat to Look For
Module/component structureImports, signature, body order
State managementLocal-vs-shared state decisions
Error handlingTry/catch style, error messages
Naming conventionsFiles, functions, types
File organizationDirectory structure

Step 3: Apply Consistently

RuleDescription
Match existing styleNew code follows established patterns
Document deviationsIf pattern changes, document why
Refactor if neededUpdate old code to match new pattern

Example: React + TypeScript conventions (illustrative)

Illustrative — the naming, component, hook, service, and type conventions below are one team's React/TypeScript catalog shown as a concrete example. The reusable skill is the process above (scan → extract → apply existing conventions). Substitute your stack's actual conventions; the value of this skill is matching whatever your codebase already does, not adopting these specific rules.

Naming Conventions

File Naming

TypeConventionExample
ComponentPascalCaseAnnotationCard.tsx
HookcamelCase with useuseVisualization.ts
ServicecamelCaseapiService.ts
TypescamelCase or indextypes/index.ts
StorecamelCase with StoreprojectStore.ts
UtilitycamelCaseformatters.ts

Code Naming

TypeConventionExample
ComponentPascalCaseAnnotationCard
FunctioncamelCase verbfetchProjects, handleClick
HookcamelCase with useuseVisualization
Type/InterfacePascalCaseProjectType, ButtonProps
ConstantUPPER_SNAKEAPI_BASE_URL, MAX_SIZE
VariablecamelCaseisLoading, userName

Component Patterns

Standard Component Structure

SectionOrderRequired
Imports1stYes
Props interface2ndYes
Component function3rdYes
Hooks declarationsInside, topYes
Event handlersInside, after hooksAs needed
Return JSXInside, lastYes

Component Organization by Type

TypeLocationPurpose
Page componentspages/Route entry points
Feature componentscomponents/[feature]/Feature-specific UI
Common componentscomponents/common/Reusable across features
Layout componentscomponents/layout/Page structure

Hook Patterns

Custom Hook Standards

ElementRequirement
Nameuse prefix + descriptive name
ReturnObject with named values
Statedata, loading, error pattern
DependenciesAll external values in dependency array

Hook Return Pattern

Return TypeUse Case
{ data, loading, error }Data fetching hooks
{ value, setValue, reset }Form/input hooks
{ isOpen, open, close, toggle }Toggle hooks

Service Patterns

API Service Standards

ElementRequirement
Async/awaitAll API calls use async/await
Error handlingTry/catch with console.error
Error format[ServiceName] Error description:
Return typePromise with typed response

Error Handling Pattern

ElementStandard
Log formatconsole.error('[Context] Message:', error)
User messageGeneric, no technical details
RethrowAfter logging for upstream handling

Type Patterns

Type Location Rules

RuleDescription
CentralizedAll shared types in types/index.ts
Import styleUse import type for type-only imports
Export styleUse export type for type exports
No interfacesPrefer type over interface for consistency

Type Naming

CategoryPatternExample
Entity[Entity]TypeProjectType, UserType
Props[Component]PropsButtonProps, CardProps
State[Domain]StateProjectState, UIState
API Response[Endpoint]ResponseProjectsResponse

Anti-Patterns

Anti-PatternProblemSolution
Props drillingHard to maintainUse a shared store or context
Large componentsHard to test/readExtract sub-components
Inline stylesInconsistentUse your styling system's tokens
any typeLoses type safetyDefine proper types
Barrel exportsCircular dependenciesUse direct imports
Mixed conventionsConfusingFollow established patterns

Code Reuse Protocol

The universal rule: before writing ANY new utility, grep the codebase for an existing one. Map your project's shared modules and reuse them instead of creating parallel helpers, exception hierarchies, or clients.

Example: a backend core/ layout (illustrative)

Illustrative — one team's shared-module layout. Substitute your project's actual shared modules. The reusable rule is "search before you create".

ModuleContainsExample
core/utils/datetime, validation, paths, formatters, file, languageutc_now(), validate_uuid(), ensure_dir()
core/exceptions.pyBase exceptions: AppError, NotFoundError, CreationError, GitHubErrorInherit, don't create parallel hierarchies
core/http_client.pySingleton async HTTP client with connection poolingget_http_client() for all HTTP calls
core/config.pyApp configuration and settingsCentralized env var access
*/service.pyDomain service layerMatch existing service patterns
*/schemas.pyValidation models per domainFollow existing schema structure

Rules

  1. Grep before creating - Search shared modules for an existing function before writing a new one
  2. Inherit base exceptions - New domain errors must extend the project's base error type
  3. Use shared clients - Reuse the project's shared HTTP/DB client, never spin up a new one ad hoc
  4. Follow service pattern - New services should match the structure of existing services

Pattern Compliance Checklist

Before Submitting Code

  • Follows existing component structure
  • Uses established naming conventions
  • Types defined in types/index.ts
  • Error handling matches project style
  • Uses import type where appropriate
  • File location matches pattern
  • Hooks follow return pattern
  • Services follow error handling pattern

Pattern Documentation

When to Document New Pattern

SituationAction
New architectural decisionDocument in ADR
Repeated pattern emergesAdd to skill documentation
Pattern deviation neededDocument reason in code comment
Breaking changeUpdate all related documentation

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.