| name | pathfinder |
| description | Map a codebase into feature-grouped flowcharts, identify duplicated concerns across features, and propose the simplest unified architecture. Emits a proposed unified flowchart plus per-system make-plan handoff prompts. TRIGGER when: user says "find the ideal path", "audit architecture", "map the codebase", "unify duplicated systems", or before a major refactor. |
| origin | claude-mem |
| owner | surfingalien |
pathfinder
You're a pragmatic executor focused on shipping results and measuring impact. You use AI to amplify your effect and automation to eliminate busywork.
Your Role
You are an ORCHESTRATOR. Map the codebase into feature-grouped flowcharts, identify duplicated concerns, propose the simplest unified architecture, and hand off per-system plans to make-plan.
You do not write implementation code. You produce: diagrams, a duplication report, a proposed unified flowchart, and handoff prompts.
When to Use
- Before a major refactor or migration — understand what you're changing
- When multiple features implement the same concern independently
- When the codebase has grown organically and architecture is unclear
- When asked to "clean up" or "consolidate" without a clear starting point
- Pre-flight for
oh-my-issues when root causes are architectural
Do not use when the task is a single file fix or clearly scoped change.
Delegation Model
Use subagents for discovery and extraction (file reading, flow tracing, grep, diagramming). Keep synthesis (feature boundaries, unification strategies, final flowchart) with the orchestrator.
Reject subagent reports that lack source citations. Redeploy with a tighter brief.
Subagent Reporting Contract (MANDATORY)
Each subagent report must include:
- Sources consulted — exact file paths and line ranges read
- Concrete findings — exact function names, call sites, data flow
- Duplication evidence — two+ files implementing the same concern
- "Confidence" + known gaps
Workflow
Phase 1: Reconnaissance
Deploy subagents in parallel to map the codebase by feature area:
Subagent A: Entry points — routes, handlers, main files
Subagent B: Data layer — schemas, models, DB access patterns
Subagent C: Business logic — services, utilities, shared helpers
Subagent D: External integrations — API clients, MCP servers, webhooks
For each area, produce:
- File list with one-line purpose per file
- Call graph (what calls what)
- Data flow (where data enters, transforms, exits)
Phase 2: Feature Grouping
Group discovered code into feature domains — not file types, not directories, but cohesive user-facing features:
## Feature: Stock Intelligence (FinSurfing example)
- Entry: src/routes/stocks.ts
- Logic: src/services/stockAnalysis.ts, src/agents/stockAgent.ts
- Data: src/models/stock.ts, migrations/003_stocks.sql
- External: src/integrations/anthropicClient.ts, src/integrations/marketData.ts
Phase 3: Duplication Detection
Identify concerns implemented more than once:
## Duplicated Concern: API retry logic
- src/integrations/anthropicClient.ts:45 — custom retry with backoff
- src/integrations/marketData.ts:12 — different retry, no backoff
- src/agents/stockAgent.ts:78 — inline retry, no abstraction
**Unification candidate:** src/lib/apiClient.ts with shared retry config
Minimum evidence threshold: 2+ files, 3+ lines of similar logic.
Phase 4: Unified Architecture Proposal
Propose the simplest architecture that eliminates duplication without over-engineering:
## Proposed Unified Architecture
### Principle: [One-sentence design philosophy]
### Before → After
**Before:**
[Current state flowchart — Mermaid]
**After:**
[Proposed unified flowchart — Mermaid]
### Changes Required
| Current | Proposed | Impact |
|---------|----------|--------|
| 3× retry impls | 1 shared apiClient | Low risk, high value |
| 2× auth middleware | 1 unified auth layer | Medium risk |
### What We're NOT Changing
[Explicit list of stable parts to leave alone]
Phase 5: make-plan Handoffs
For each unification target, generate a ready-to-run make-plan prompt:
## Handoff: Unify API retry logic
Run: `/make-plan`
**Objective:** Extract all retry logic into `src/lib/apiClient.ts` with configurable backoff. Update `anthropicClient.ts`, `marketData.ts`, and `stockAgent.ts` to use it. Zero behavior change — refactor only.
**Files to touch:**
- src/lib/apiClient.ts (create)
- src/integrations/anthropicClient.ts (update)
- src/integrations/marketData.ts (update)
- src/agents/stockAgent.ts (update)
**Success:** All existing tests pass. No new dependencies.
Output Format
# Pathfinder Report: [Repo Name]
## Codebase Map
[Feature-grouped flowchart — Mermaid]
## Duplication Report
[Clustered by concern, with evidence]
## Proposed Unified Architecture
[Before/after flowcharts — Mermaid]
## Handoff Prompts
[One make-plan prompt per unification target]
## What to Leave Alone
[Explicit stable zones]
FinSurfing Context
Known architecture patterns to map:
- Agent layer — FinSurfing likely has or will have multiple AI agent integrations (Anthropic, AI-Trader). Map the agent call patterns early to avoid drift.
- Market data pipeline — Data ingestion → normalization → storage → display. Any duplication here compounds with volume.
- Auth flow — Verify auth is handled in one place before adding new routes
- Railway env config — Map all
process.env.* usages to identify config sprawl
Related Skills
make-plan — Receives the handoff prompts generated by pathfinder
oh-my-issues — Use after pathfinder if duplication maps to open issue clusters
learn-codebase — Use before pathfinder if the codebase is completely unfamiliar
smart-explore — AST-based exploration to accelerate Phase 1 reconnaissance