---
repo: "mohan-n-swamy/capa-wizard-public"
title: "CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach"
license: "MIT"
keywords: [capa, root-cause-analysis, five-whys, quality-management, incident-management, continuous-improvement, lean-operations, typescript, ai-agents, open-source]
capabilities:
  - "Five-phase state engine (`api/src/`) guiding Problem Definition -> 6M Fishbone -> Multi-Branch 5-Whys -> Systemic CAPA -> Effectiveness Sign-off."
  - "Socratic AI Challenge & Evaluation prompts (`api/src/ai/`) rejecting circular reasoning, skipped causal steps, and person-blame."
  - "On-server voice transcription via `@xenova/transformers` so supervisors can speak answers on mobile or shop floors."
  - "19 automated Vitest suites (`api/src/__tests__/`) testing Fishbone generation, 5-Whys branching, phase gating, and evaluation logic."
when_to_use:
  - "A full-stack AI-guided Root-Cause Analysis (RCA), 6M Fishbone, and Corrective & Preventive Action (CAPA) platform (TypeScript, Express, React, PostgreSQL) featuring local Whisper voice intake, multi-branch 5-Whys trees, and a Socratic Lean quality coach that blocks shallow 'human error / retrain staff' fixes."
  - "Most postmortems and CAPA trackers fail because busy teams stop two 'Whys' too early, blame an individual's attention, prescribe 'retraining', and watch the exact same outage or field defect recur three weeks later. `capa-wizard-public` guides operators step-by-step from raw incident intake through Fishbone hypothesis generation, multi-branch 5-Whys, systemic poka-yoke actions, and effectiveness verification."
inputs_required:
  - "PORT: Express API port"
  - "DATABASE_URL: PostgreSQL database URL"
  - "JWT_SECRET: Session signing secret"
  - "ANTHROPIC_API_KEY: LLM API key powering Socratic 5-Whys coaching and Fishbone synthesis"
  - "WHISPER_MODEL: Local HuggingFace/Xenova speech-to-text model identifier"
quickstart:
  - "node bin/capa-demo.mjs                  # run zero-credential Lean shallow-fix rejection demo"
  - "cd api && npm install && npm test       # run all 19 Vitest RCA, Fishbone & phase-engine suites"
  - "docker compose up -d                    # start PostgreSQL + API + React CAPA Wizard UI"
---

# CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach — Machine-Readable Agent Guide

A full-stack AI-guided Root-Cause Analysis (RCA), 6M Fishbone, and Corrective & Preventive Action (CAPA) platform (TypeScript, Express, React, PostgreSQL) featuring local Whisper voice intake, multi-branch 5-Whys trees, and a Socratic Lean quality coach that blocks shallow 'human error / retrain staff' fixes.

<problem_patterns>
Most postmortems and CAPA trackers fail because busy teams stop two 'Whys' too early, blame an individual's attention, prescribe 'retraining', and watch the exact same outage or field defect recur three weeks later. `capa-wizard-public` guides operators step-by-step from raw incident intake through Fishbone hypothesis generation, multi-branch 5-Whys, systemic poka-yoke actions, and effectiveness verification.
</problem_patterns>

<architecture_map>
Key modules and entry points in this repository:
  - `api/src/ai/`: Prompt templates and evaluators for hints, Socratic challenges, Fishbone generation, and CAPA scoring
  - `api/src/routes/ & services/`: Express endpoints for CAPA lifecycle, multi-branch 5-Whys, categories, archive, and voice transcription
  - `web/`: React guided wizard UI with visual Fishbone & branching 5-Whys editor
  - `bin/capa-demo.mjs`: Zero-credential CLI demo illustrating shallow-blame rejection vs poka-yoke acceptance
  - `api/src/__tests__/`: 19 Vitest unit and route integration test suites
</architecture_map>

<inputs_and_configuration>
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
</inputs_and_configuration>

<adaptation_playbook>
When a human asks an AI coding agent to deploy or adapt `capa-wizard-public` into their stack:
  1. Customize seed incident categories in `api/src/db/seed.ts` for your domain (e.g., SRE outages, warehouse logistics, clinical ops, manufacturing).
  2. Adjust Socratic strictness and rubric examples in `api/src/ai/challenge-prompts.ts` and `evaluation-prompts.ts`.
  3. Run `cd api && npm test` to ensure all 19 test suites pass after customizing prompts.
</adaptation_playbook>

<reference_docs>
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
</reference_docs>
