For engineers and contributors. User-facing documentation lives at /docs.

System Architecture Overview

Purpose

PMFKit v1 is a structured AI diagnostic engine: URL → evidence → PMF stage → recommendations. This doc describes the high-level flow, Evidence Layer, orchestration, single entry point, and dependency map.

High-Level Flow

  1. Crawl: Discovery → Product crawl + UI capture (parallel) → optional enrichment. Output persisted to company_crawls.
  2. Evidence Layer: Crawl output is normalized into tagged evidence categories (see evidence-taxonomy.md). Single artifact; all agents consume from here.
  3. CMO: Consumes Evidence Layer (and legacy page evidence for the current pipeline). Produces Report 1 (discovery verdict, component analyses, DRL).
  4. BD: Consumes Report 1 only. Produces Report 2 (context, quotes, cases).
  5. COO: Consumes Report 1 + Report 2. Produces Report 3 (strategies, next actions, one thing this week).
  6. CDO: Consumes Evidence Layer + UI captures. Produces design audit (UX blockers, design system, rewrite plan).

Conflict resolution: Stage and recommendation are owned by CMO (Report 1 discoveryVerdict). No other agent overwrites them. Orchestration respects Report 1 stage and does not override it.

Single Entry Point

  • runDiagnosis(input) in lib/pipeline/run-diagnosis.ts is the canonical orchestration entry.
  • Input: url (or crawlId/projectId), userId, supabase, addLog, flags includeBd, includeCoo, includeCdo, runCrawlFirst, enrichmentTier.
  • Output: DiagnosisResultstage, recommendation, finalDiagnosis (canonical FinalDiagnosisV1), evidenceLayer, report1, report2?, report3?, cdo?, crawlId, executionLog. The FinalDiagnosisV1 shape is the single contract for API, export, and UI single-diagnosis view (see lib/schemas/final-diagnosis-v1.ts, lib/pipeline/to-final-diagnosis-v1.ts). Public extract: generatePublicSummary(finalDiagnosis) in lib/public-summary.ts produces a compressed, tweet-ready summary (PMF stage, confidence, primary risk, one fix this week, short explanation max 120 words); no separate engine, transformation only.
  • Existing API routes (POST /api/roles/crawl, POST /api/roles/cmo, etc.) can call into this or continue to call shared crawl and report-from-crawl directly; the contract is that the data they pass is the same Evidence Layer / crawl output.

Dependency Map

ArtifactDepends on
Crawl
Evidence LayerCrawl
Report 1 (CMO)Evidence Layer
Report 2 (BD)Report 1
Report 3 (COO)Report 1, Report 2
CDO reportEvidence Layer, UI captures

Defined in code as DIAGNOSIS_DEPENDENCY_MAP in lib/pipeline/run-diagnosis.ts.

Key Modules

AreaPath
Evidence Layercore/evidence/ (types, normalize, index)
Crawllib/pipeline/run-shared-crawl.ts, core/crawlers/
Report from crawl (CMO path)lib/pipeline/run-report-from-crawl.ts
Orchestrationlib/pipeline/run-diagnosis.ts
Final diagnosis (canonical output)lib/schemas/final-diagnosis-v1.ts, lib/pipeline/to-final-diagnosis-v1.ts
Public summary (tweet-ready extract)lib/public-summary.ts
Agentscore/agents/ (cmo-agent, cdo-agent, bd-agent, coo-agent)
Persistencelib/persistence/company-crawls.ts, lib/persistence/snapshots.ts