# mobility-smglab/rca_agent architecture

> Architecture diagram of the GitHub repository mobility-smglab/rca_agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mobility-smglab/rca_agent
- Repository: https://github.com/mobility-smglab/rca_agent

## Overview

RCA Intellect accepts manufacturing failure context, logs, and optional defect imagery; its analysis pipeline retrieves historical evidence, detects visual and telemetry defects, dynamically selects causal analyses, and produces structured findings and a consolidated report. A FastAPI dashboard supports uploads, run monitoring, downloads, and interactive knowledge-base management. The graph preserves documented analysis capabilities and sampled module relationships; some orchestration details are based on README statements because the relevant portions of main.py were not shown.

Main entry points: [`main.py`](https://github.com/mobility-smglab/rca_agent/blob/main/main.py) (RCA pipeline), [`rag_service.py`](https://github.com/mobility-smglab/rca_agent/blob/main/rag_service.py) (RAG service), [`schemas/models.py`](https://github.com/mobility-smglab/rca_agent/blob/main/schemas/models.py) (Output schemas), [`server.py`](https://github.com/mobility-smglab/rca_agent/blob/main/server.py) (FastAPI API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Web experience"]
  node_dashboard["Dashboard UI<br/>[app.js]"]
  node_api["FastAPI API<br/>[server.py]"]
end

subgraph group_analysis["RCA analysis"]
  node_pipeline["RCA pipeline<br/>[main.py]"]
  node_image["Image analysis<br/>[image_analysis.py]"]
  node_anomaly["Anomaly detection"]
  node_orchestration["Analysis selection<br/>[main.py]"]
  node_fivewhy["5-Why analysis<br/>[five_why.py]"]
  node_ishikawa["Ishikawa analysis<br/>[ishikawa.py]"]
  node_pareto["Pareto analysis<br/>[pareto.py]"]
  node_evidence["Evidence graph<br/>[evidence_graph.py]"]
end

subgraph group_knowledge["Knowledge retrieval"]
  node_rag["RAG service<br/>[rag_service.py]"]
  node_ragtool["RAG agent tool<br/>[rag_tool.py]"]
  node_vectorstore[("Qdrant store")]
  node_ncringest["NCR ingestion<br/>[ingest_ncr.py]"]
  node_capaingest["CAPA ingestion<br/>[ingest_capa.py]"]
end

subgraph group_reporting["Reports and schemas"]
  node_schemas["Output schemas<br/>[models.py]"]
  node_fivegen["5-Why report"]
  node_ishgen["Fishbone report"]
  node_paretogen["Pareto report"]
  node_evgen["Evidence report"]
  node_finalreport["Merged RCA PDF<br/>[main.py]"]
end

node_user(("Engineer"))
node_browser(("Web browser"))
node_azure{{"Azure OpenAI"}}
node_qdrant[("Qdrant")]

node_user -->|"uses"| node_dashboard
node_browser -->|"requests"| node_api
node_dashboard -.->|"submits runs"| node_api
node_api -->|"triggers run"| node_pipeline
node_pipeline -->|"retrieves NCR evidence"| node_rag
node_pipeline -->|"analyzes imagery"| node_image
node_pipeline -->|"analyzes logs"| node_anomaly
node_pipeline -->|"selects analyses"| node_orchestration
node_orchestration -->|"dispatches"| node_fivewhy
node_orchestration -->|"dispatches"| node_ishikawa
node_orchestration -->|"dispatches"| node_pareto
node_orchestration -->|"dispatches"| node_evidence
node_image -->|"queries vision model"| node_azure
node_anomaly -->|"queries model"| node_azure
node_pipeline -->|"validates outputs"| node_schemas
node_image -->|"returns typed result"| node_schemas
node_anomaly -->|"returns typed result"| node_schemas
node_fivewhy -->|"returns typed result"| node_schemas
node_ishikawa -->|"returns typed result"| node_schemas
node_pareto -->|"returns typed result"| node_schemas
node_evidence -->|"returns typed result"| node_schemas
node_pipeline -->|"generates report"| node_fivegen
node_pipeline -->|"generates report"| node_ishgen
node_pipeline -->|"generates report"| node_paretogen
node_pipeline -->|"generates report"| node_evgen
node_pipeline -->|"merges PDFs"| node_finalreport
node_ragtool -->|"searches"| node_rag
node_pipeline -.->|"uses search"| node_ragtool
node_rag -->|"queries and updates"| node_qdrant
node_rag -.->|"persists vectors"| node_vectorstore
node_ncringest -->|"ingests documents"| node_rag
node_capaingest -->|"ingests documents"| node_rag
node_api -->|"queries and manages"| node_rag
node_api -.->|"serves interface"| node_dashboard

click node_dashboard "https://github.com/mobility-smglab/rca_agent/blob/main/static/app.js"
click node_api "https://github.com/mobility-smglab/rca_agent/blob/main/server.py"
click node_pipeline "https://github.com/mobility-smglab/rca_agent/blob/main/main.py"
click node_image "https://github.com/mobility-smglab/rca_agent/blob/main/agents/image_analysis.py"
click node_anomaly "https://github.com/mobility-smglab/rca_agent/blob/main/agents/anomaly_detection.py"
click node_orchestration "https://github.com/mobility-smglab/rca_agent/blob/main/main.py"
click node_fivewhy "https://github.com/mobility-smglab/rca_agent/blob/main/agents/five_why.py"
click node_ishikawa "https://github.com/mobility-smglab/rca_agent/blob/main/agents/ishikawa.py"
click node_pareto "https://github.com/mobility-smglab/rca_agent/blob/main/agents/pareto.py"
click node_evidence "https://github.com/mobility-smglab/rca_agent/blob/main/agents/evidence_graph.py"
click node_schemas "https://github.com/mobility-smglab/rca_agent/blob/main/schemas/models.py"
click node_rag "https://github.com/mobility-smglab/rca_agent/blob/main/rag_service.py"
click node_ragtool "https://github.com/mobility-smglab/rca_agent/blob/main/tools/rag_tool.py"
click node_vectorstore "https://github.com/mobility-smglab/rca_agent/tree/main/data/qdrant_db"
click node_ncringest "https://github.com/mobility-smglab/rca_agent/blob/main/ingest_ncr.py"
click node_capaingest "https://github.com/mobility-smglab/rca_agent/blob/main/ingest_capa.py"
click node_fivegen "https://github.com/mobility-smglab/rca_agent/blob/main/tools/fivewhy_generator.py"
click node_ishgen "https://github.com/mobility-smglab/rca_agent/blob/main/tools/ishikawa_generator.py"
click node_paretogen "https://github.com/mobility-smglab/rca_agent/blob/main/tools/pareto_generator.py"
click node_evgen "https://github.com/mobility-smglab/rca_agent/blob/main/tools/evidence_graph_generator.py"
click node_finalreport "https://github.com/mobility-smglab/rca_agent/blob/main/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard,node_api,node_browser toneBlue
class node_pipeline,node_image,node_anomaly,node_orchestration,node_fivewhy,node_ishikawa,node_pareto,node_evidence,node_qdrant toneAmber
class node_rag,node_ragtool,node_vectorstore,node_ncringest,node_capaingest toneMint
class node_schemas,node_fivegen,node_ishgen,node_paretogen,node_evgen,node_finalreport toneRose
class node_user,node_azure toneIndigo
```

## Components

### Web experience

- [Dashboard UI](https://github.com/mobility-smglab/rca_agent/blob/main/static/app.js): `static/app.js`
- [FastAPI API](https://github.com/mobility-smglab/rca_agent/blob/main/server.py): `server.py`

### RCA analysis

- [RCA pipeline](https://github.com/mobility-smglab/rca_agent/blob/main/main.py): `main.py`
- [Image analysis](https://github.com/mobility-smglab/rca_agent/blob/main/agents/image_analysis.py): `agents/image_analysis.py`
- [Anomaly detection](https://github.com/mobility-smglab/rca_agent/blob/main/agents/anomaly_detection.py): `agents/anomaly_detection.py`
- [Analysis selection](https://github.com/mobility-smglab/rca_agent/blob/main/main.py): `main.py`
- [5-Why analysis](https://github.com/mobility-smglab/rca_agent/blob/main/agents/five_why.py): `agents/five_why.py`
- [Ishikawa analysis](https://github.com/mobility-smglab/rca_agent/blob/main/agents/ishikawa.py): `agents/ishikawa.py`
- [Pareto analysis](https://github.com/mobility-smglab/rca_agent/blob/main/agents/pareto.py): `agents/pareto.py`
- [Evidence graph](https://github.com/mobility-smglab/rca_agent/blob/main/agents/evidence_graph.py): `agents/evidence_graph.py`

### Knowledge retrieval

- [RAG service](https://github.com/mobility-smglab/rca_agent/blob/main/rag_service.py): `rag_service.py`
- [RAG agent tool](https://github.com/mobility-smglab/rca_agent/blob/main/tools/rag_tool.py): `tools/rag_tool.py`
- [Qdrant store](https://github.com/mobility-smglab/rca_agent/tree/main/data/qdrant_db): `data/qdrant_db`
- [NCR ingestion](https://github.com/mobility-smglab/rca_agent/blob/main/ingest_ncr.py): `ingest_ncr.py`
- [CAPA ingestion](https://github.com/mobility-smglab/rca_agent/blob/main/ingest_capa.py): `ingest_capa.py`

### Reports and schemas

- [Output schemas](https://github.com/mobility-smglab/rca_agent/blob/main/schemas/models.py): `schemas/models.py`
- [5-Why report](https://github.com/mobility-smglab/rca_agent/blob/main/tools/fivewhy_generator.py): `tools/fivewhy_generator.py`
- [Fishbone report](https://github.com/mobility-smglab/rca_agent/blob/main/tools/ishikawa_generator.py): `tools/ishikawa_generator.py`
- [Pareto report](https://github.com/mobility-smglab/rca_agent/blob/main/tools/pareto_generator.py): `tools/pareto_generator.py`
- [Evidence report](https://github.com/mobility-smglab/rca_agent/blob/main/tools/evidence_graph_generator.py): `tools/evidence_graph_generator.py`
- [Merged RCA PDF](https://github.com/mobility-smglab/rca_agent/blob/main/main.py): `main.py`

### Other components

- **Engineer**
- **Web browser**
- **Azure OpenAI**
- **Qdrant**

## Connections

- Engineer → Dashboard UI: uses (evidence: `README.md`)
- Web browser → FastAPI API: requests (evidence: `README.md`)
- Dashboard UI → FastAPI API: submits runs
- FastAPI API → RCA pipeline: triggers run (evidence: `server.py`)
- RCA pipeline → RAG service: retrieves NCR evidence (evidence: `main.py`)
- RCA pipeline → Image analysis: analyzes imagery (evidence: `README.md`)
- RCA pipeline → Anomaly detection: analyzes logs (evidence: `README.md`)
- RCA pipeline → Analysis selection: selects analyses (evidence: `README.md`)
- Analysis selection → 5-Why analysis: dispatches (evidence: `README.md`)
- Analysis selection → Ishikawa analysis: dispatches (evidence: `README.md`)
- Analysis selection → Pareto analysis: dispatches (evidence: `README.md`)
- Analysis selection → Evidence graph: dispatches (evidence: `README.md`)
- Image analysis → Azure OpenAI: queries vision model (evidence: `README.md`)
- Anomaly detection → Azure OpenAI: queries model (evidence: `agents/anomaly_detection.py`)
- RCA pipeline → Output schemas: validates outputs (evidence: `main.py`)
- Image analysis → Output schemas: returns typed result (evidence: `agents/image_analysis.py`)
- Anomaly detection → Output schemas: returns typed result (evidence: `agents/anomaly_detection.py`)
- 5-Why analysis → Output schemas: returns typed result (evidence: `agents/five_why.py`)
- Ishikawa analysis → Output schemas: returns typed result (evidence: `agents/ishikawa.py`)
- Pareto analysis → Output schemas: returns typed result (evidence: `agents/pareto.py`)
- Evidence graph → Output schemas: returns typed result (evidence: `agents/evidence_graph.py`)
- RCA pipeline → 5-Why report: generates report (evidence: `main.py`)
- RCA pipeline → Fishbone report: generates report (evidence: `main.py`)
- RCA pipeline → Pareto report: generates report (evidence: `main.py`)
- RCA pipeline → Evidence report: generates report (evidence: `main.py`)
- RCA pipeline → Merged RCA PDF: merges PDFs (evidence: `README.md`)
- RAG agent tool → RAG service: searches (evidence: `tools/rag_tool.py`)
- RCA pipeline → RAG agent tool: uses search
- RAG service → Qdrant: queries and updates (evidence: `rag_service.py`)
- RAG service → Qdrant store: persists vectors
- NCR ingestion → RAG service: ingests documents (evidence: `ingest_ncr.py`)
- CAPA ingestion → RAG service: ingests documents (evidence: `ingest_capa.py`)
- FastAPI API → RAG service: queries and manages (evidence: `server.py`)
- FastAPI API → Dashboard UI: serves interface
