# Search Pattern Reference

Concrete grep/glob patterns for each discovery technique. Agents should adapt these to the actual framework detected in the codebase.

---

## Framework Detection (run first)

Identify the tech stack to select the right patterns:

| Check | Pattern | Means |
| --- | --- | --- |
| `package.json` contains `express` | `"express"` | Express backend |
| `package.json` contains `@temporalio` | `"@temporalio"` | Temporal workflows |
| `package.json` contains `bullmq` | `"bullmq"` | BullMQ job queues |
| `package.json` contains `@reduxjs/toolkit` | `"@reduxjs/toolkit"` | Redux state management |
| `package.json` contains `socket.io` | `"socket.io"` | WebSocket via Socket.IO |
| `app/workflows/` exists | glob `app/workflows/` | Workflow directory convention |
| `temporal/config/` exists | glob `temporal/config/` | Temporal config convention |
| Files matching `*.workflow.ts` | glob `**/*.workflow.*` | Workflow file convention |
| Files matching `*.queue.ts` | glob `**/*.queue.*` | Queue file convention |

---

## Route Harvesting Patterns

### Express

```
# Route definitions
grep: router\.(get|post|put|patch|delete)\(
glob: **/routes/**/*.{js,ts}, **/router/**/*.{js,ts}

# Route mounting
grep: app\.use\(.*/api
```

### Next.js App Router

```
glob: app/**/route.{js,ts}
grep: export (async )?function (GET|POST|PUT|PATCH|DELETE)
```

### Next.js Pages API

```
glob: pages/api/**/*.{js,ts}
grep: export default (async )?function handler
```

### Fastify

```
grep: fastify\.(get|post|put|patch|delete)\(
grep: (register|plugin).*routes
```

---

## Temporal Workflow Patterns

```
# Workflow definitions
grep: export async function \w+Workflow
glob: **/workflow.{js,ts}, **/*.workflow.{js,ts}

# Activity definitions
grep: export async function \w+Activity
glob: **/activities.{js,ts}, **/*.activities.{js,ts}

# Workflow registry
glob: **/workflowModules.{js,ts}
grep: workflows\s*=\s*\{

# Activity registry
glob: **/activityModules.{js,ts}
grep: activities\s*=\s*\{

# Workflow dispatch
grep: startWorkflow\(|startChild\(|executeChild\(

# Activity proxy
grep: proxyActivities\(

# Signals and queries
grep: defineSignal\(|defineQuery\(|setHandler\(

# Continue-as-new
grep: continueAsNew\(
```

---

## BullMQ Patterns

```
# Queue definitions
grep: new Queue\(|new FlowProducer\(
glob: **/queue.{js,ts}, **/*.queue.{js,ts}

# Worker definitions
grep: new Worker\(
glob: **/worker.{js,ts}, **/*.worker.{js,ts}

# Job dispatch
grep: \.add\(|\.addBulk\(|\.addFlow\(

# Job processing
grep: \.process\(|processor:
```

---

## Redux / Frontend Action Patterns

```
# Async thunks (dispatched actions that call APIs)
grep: createAsyncThunk\(
glob: **/*Slice.{js,ts}, **/*slice.{js,ts}, **/slices/**/*.{js,ts}

# API calls from frontend
grep: api\.(post|put|patch|delete)\(|axios\.(post|put|patch|delete)\(
glob: **/hooks/use*.{js,ts,jsx,tsx}, **/services/**/*.{js,ts}

# Dispatch sequences
grep: dispatch\(.*Actions?\.|dispatch\(.*thunk
```

---

## WebSocket Patterns

```
# Socket.IO server
grep: io\.on\(|socket\.on\(|socket\.emit\(
glob: **/socket/**/*.{js,ts}, **/ws/**/*.{js,ts}

# Socket.IO client
grep: socket\.on\(|socket\.emit\(|useSocket
glob: **/hooks/useSocket*.{js,ts,jsx,tsx}

# Native WebSocket
grep: new WebSocket\(|ws\.on\(
```

---

## Database Patterns

```
# Prisma
grep: prisma\.\w+\.(findMany|findFirst|findUnique|create|update|delete|upsert|aggregate|groupBy)
grep: \$transaction\(|\$executeRaw\(|\$queryRaw\(

# Sequelize
grep: \.findAll\(|\.findOne\(|\.create\(|\.update\(|\.destroy\(
grep: sequelize\.transaction\(

# Raw SQL
grep: \.query\(|\.execute\(|BEGIN|COMMIT|ROLLBACK
```

---

## External Service Patterns

```
# Outbound HTTP (to other services)
grep: axios\.(get|post|put|patch|delete)\(|fetch\(.*https?://
grep: got\.(get|post|put|patch|delete)\(|request\.(get|post|put|patch|delete)\(

# Git operations
grep: git.*push|git.*commit|createBlob|createTree|createCommit|updateRef
grep: octokit\.|@octokit/

# Email
grep: sendMail|transporter\.send|sgMail\.send|resend\.send

# File storage
grep: s3\.upload|s3\.putObject|uploadToS3|writeFile.*storage
```

---

## Workflow Complexity Indicators

Patterns that suggest a route is a real workflow (not simple CRUD):

```
# Async dispatch (work happens later)
grep: startWorkflow\(|\.add\(.*queue|emit\(|publish\(

# Multi-step (sequential calls)
# Look for functions with 3+ await statements to different services

# Transaction blocks
grep: \$transaction|\$executeRaw|BEGIN.*COMMIT|withTransaction

# Polling/status endpoints
grep: /status\?|workflowId|jobId|runId

# Version/conflict checks
grep: version.*conflict|optimistic|stale|409

# Retry/backoff
grep: maximumAttempts|retry|backoff|exponential

# Child/sub workflows
grep: startChild\(|spawnChild|fork\(

# Feature flags / conditional steps
grep: featureFlag|isEnabled|canAccess
```
