# CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach — Complete AI & LLM Reference Corpus (`llms-full.txt`)
- Repository: https://github.com/mohan-n-swamy/capa-wizard-public
- Web Discovery URL: https://mohan-n-swamy.github.io/repos/capa-wizard-public/
- License: MIT
- Keywords: capa, root-cause-analysis, five-whys, quality-management, incident-management, continuous-improvement, lean-operations, typescript, ai-agents, open-source
---
## File: `AI-README.md` — AI-README.md
---
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.
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.
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
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.
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.
- 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`
---
## File: `.env.example` — Environment Contract (.env.example)
```ini
# capa-wizard-public — AI-Guided 5-Whys RCA, Fishbone & CAPA Workflow Platform
PORT=3005
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/capa_wizard
JWT_SECRET=replace_with_32_byte_random_secret
GOOGLE_CLIENT_ID=optional_google_oauth_client_id
ANTHROPIC_API_KEY=replace_with_llm_api_key
WHISPER_MODEL=Xenova/whisper-tiny.en
```
---
## File: `AGENTS.md` — AGENTS.md
# AGENTS.md — CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach
Read this file first before modifying `capa-wizard-public`.
## Purpose
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.
## Commands
```bash
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
```
## Module Map
- `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
## Invariants
1. Keep all organization names, credentials, domains, and thresholds in `.env` or external config files. Never hardcode company names, host IPs, or secrets in source files.
2. Deterministic business logic belongs in code and lookup tables, not inside LLM prompts.
3. Update `docs/HLD.md`, `docs/LLD.md`, and `.env.example` in the same commit whenever an interface or environment variable changes.
4. Run the repository smoke check and secret scan before opening a pull request.
---
## File: `docs/PRD.md` — Product Requirements Document (docs/PRD.md)
# Product Requirements Document — CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach
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.
## 1. Problem
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.
## 2. Users and Jobs-to-be-Done
| Persona | Job-to-be-Done |
|---|---|
| Operations / Manufacturing / Clinical Quality Lead | Ensure every P0/P1 incident produces a genuine systemic preventive mechanism rather than 'retrain team' theater. |
| Shift Supervisor / On-Call Lead | Dictate an incident by voice in 60 seconds and get guided Socratic prompts to uncover the true process gap. |
| Engineering / VoC Platform Owner | Trigger structured CAPA investigations automatically via REST API from `voc-control-tower-public` or incident alerts. |
## 3. Core 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.
## 4. Configurable Inputs
Adopters configure the system for their own organization without editing core application logic:
| Variable | Default / Example | Purpose |
|---|---|---|
| `PORT` | `3005` | Express API port |
| `DATABASE_URL` | `postgresql://postgres:postgres@localhost:5432/capa_wizard` | PostgreSQL database URL |
| `JWT_SECRET` | `replace_me` | Session signing secret |
| `ANTHROPIC_API_KEY` | `sk-ant-...` | LLM API key powering Socratic 5-Whys coaching and Fishbone synthesis |
| `WHISPER_MODEL` | `Xenova/whisper-tiny.en` | Local HuggingFace/Xenova speech-to-text model identifier |
## 5. Phasing and Stability Exit Criteria
1. **Phase 1 (Local Synthetic Run):** Clone the repository, copy `.env.example` to `.env`, and run the quickstart commands against synthetic seed data. Exit criterion: smoke checks pass with zero external credentials.
2. **Phase 2 (Read-Only Shadow Wiring):** Connect read-only credentials or webhook listeners in shadow/dry-run mode. Exit criterion: 100 consecutive events or queries reconcile cleanly against source records.
3. **Phase 3 (Production Cutover):** Enable live writes, alerts, or routing behind bounded retry and idempotency guards.
## 6. Non-Goals
- Shipping organization-specific business rules hardcoded in application source.
- Storing credentials, personal customer records, or tenant URLs inside version control.
- Replacing deterministic validation or arithmetic with unconstrained model prompts.
---
## File: `docs/PR-FAQ.md` — Working-Backwards PR-FAQ (docs/PR-FAQ.md)
# Working-Backwards PR-FAQ — CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach
**Release Summary:** `capa-wizard-public` gives engineering and operations teams a self-hosted, open-source implementation of CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach that configures via `.env` and runs on standard infrastructure in minutes.
## Press Release
Operations and engineering teams often rebuild the same internal workflows behind closed doors or pay per-seat SaaS markups for rigid tools that cannot match their field reality. `capa-wizard-public` open-sources a battle-tested implementation of CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach, stripped of all single-company assumptions and packaged with clear adapter boundaries, synthetic demo data, and machine-readable agent documentation.
Any team can fork `capa-wizard-public`, supply their own `.env` inputs and taxonomy config, and deploy locally or in production with Docker, Python, or Node. AI coding assistants such as Claude Code, Codex, and Cursor can read `AI-README.md` and `llms.txt` to wire custom ERP, CRM, or warehouse adapters in a single session.
## External Adopter FAQ
**Q1: How long does it take to run locally after cloning?**
Under five minutes. Copy `.env.example` to `.env` and run the quickstart commands in `README.md`. Synthetic fixtures let you inspect the workflow before connecting live credentials.
**Q2: Do I need to rewrite source files to use my own company name, channels, or rules?**
No. Organization names, endpoints, thresholds, and credentials sit in `.env` and declarative config files. External system specifics live behind narrow adapter modules documented in `docs/LLD.md`.
**Q3: What license governs this repository?**
MIT License. You can fork, modify, self-host, and use it commercially without restriction.
## Internal Engineering & Security FAQ
**Q4: How do we prevent tenant or employer data from ever entering a public fork?**
The repository starts from a clean git history, excludes raw exports and binary dumps, validates every commit through `gitleaks`, and ships only synthetic fixtures.
**Q5: What happens when an upstream API or model provider is slow or unavailable?**
Inbound webhooks persist raw payloads before processing, outbound writes carry idempotency keys with bounded exponential backoff, and model-backed paths fail open to deterministic rules or explicit human queues.
---
## File: `docs/HLD.md` — High-Level Design (docs/HLD.md)
# High-Level Design (HLD) — CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach
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.
## 1. System Topology
```mermaid
flowchart LR
Intake["Voice / Text Incident"] --> Problem["Phase 1: Scoped Problem"]
Problem --> Fishbone["Phase 2: 6M Fishbone Hypotheses"]
Fishbone --> Why["Phase 3: Multi-Branch 5-Whys"]
Why --> Coach{"Lean Coach Gate"}
Coach -->|"Blames human / shallow"| Why
Coach -->|"Systemic mechanism"| CAPA["Phase 4-5: CAPA & Effectiveness Check"]
```
## 2. Architectural Decisions and Rejected Alternatives
| Decision | Why It Holds | Rejected Alternative |
|---|---|---|
| Hard phase engine + Socratic challenge gate | Prevents users from jumping straight from an incident title to a pre-conceived 'retrain staff' action. | Unstructured single-page postmortem Markdown templates |
| Multi-branch 5-Whys data model | Captures compound failures (e.g., missing software validation AND ambiguous SOP) without forcing a fake single chain. | Flat 5-row form (`why1..why5` columns) |
| Local `@xenova/transformers` audio transcription | Eliminates external audio API setup and keeps sensitive internal incident recordings on-host. | Mandatory third-party cloud speech APIs |
## 3. Data Flow and Failure Boundaries
1. **Configuration Boundary:** Startup validates `.env` variables and declarative config schemas before accepting traffic or running scheduled jobs.
2. **Adapter Boundary:** External services (databases, chat channels, HRMS, warehouses, or LLM providers) sit behind explicit adapter modules so failures stay isolated and testable with local mocks.
3. **Observability and Audit:** State transitions and job executions emit structured logs and deterministic status records rather than mutating state silently.
## 4. Scaling Notes
- **1x to 10x load:** Single-node Docker Compose or process supervisor handles standard team workloads with indexed database queries and bounded worker concurrency.
- **First bottleneck at 10x+:** High-frequency webhook or batch ingestion queues; mitigate by separating the stateless HTTP receiver from background worker processes sharing Redis or PostgreSQL locks.
---
## File: `docs/LLD.md` — Low-Level Design & Runbook (docs/LLD.md)
# Low-Level Design (LLD) & Operations Runbook — CAPA Wizard — AI-Guided 5-Whys Root-Cause Analysis & Lean Quality Coach
This document defines the module responsibilities, environment contract, and operational procedures for `capa-wizard-public`.
## 1. Module and File Inventory
| Path | Responsibility |
|---|---|
| `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 |
## 2. Environment Variable Contract
| Variable | Default / Example | Required | Description |
|---|---|---|---|
| `PORT` | `3005` | Yes | Express API port |
| `DATABASE_URL` | `postgresql://postgres:postgres@localhost:5432/capa_wizard` | Yes | PostgreSQL database URL |
| `JWT_SECRET` | `replace_me` | Yes | Session signing secret |
| `ANTHROPIC_API_KEY` | `sk-ant-...` | Yes | LLM API key powering Socratic 5-Whys coaching and Fishbone synthesis |
| `WHISPER_MODEL` | `Xenova/whisper-tiny.en` | Yes | Local HuggingFace/Xenova speech-to-text model identifier |
## 3. Extension Recipe
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.
## 4. Operations Runbook
### 1. Run all 19 Vitest suites
```bash
cd api && npm test
```
### 2. Run database migrations & seed categories
```bash
cd api && npm run migrate && npm run seed
```
### 3. Test Lean shallow-fix gate from CLI
```bash
node bin/capa-demo.mjs
```
---
## File: `docs/RESEARCH-2026.md` — 2026 Research & Landscape Notes (docs/RESEARCH-2026.md)
# 2026 Quality Management (QMS) & AI-Guided 5-Whys CAPA Research
Enterprise QMS suites (MasterControl, TrackWise, Greenlight Guru) act as passive compliance form-fillers: they store PDF signatures for ISO 9001 / 21 CFR Part 820 audits, but happily accept `"Root Cause: Human error; Corrective Action: Retrained operator"` — the single weakest intervention on the hierarchy of controls.
`capa-wizard-public` brings **Toyota-style Socratic Lean coaching** into an open-source web + API workflow:
1. **Active Challenge Prompts (`api/src/ai/challenge-prompts.ts`):** Evaluates each `Why -> Because` link for causal sufficiency and flags person-blame or symptom restatements before advancing phases.
2. **Multi-Branch Ishikawa + 5-Whys:** Real incidents rarely have a single linear cause; supervisors select active bones from a 6M Fishbone diagram and drill down parallel 5-Why branches.
3. **Privacy-Preserving Local Voice Intake:** Uses `@xenova/transformers` Whisper locally so operations managers can dictate incidents hands-free without third-party audio retention.