# anto5699/autoqa-prompt-optimizer architecture

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

- Interactive diagram: https://gitdiagram.com/anto5699/autoqa-prompt-optimizer
- Repository: https://github.com/anto5699/autoqa-prompt-optimizer

## Overview

AutoQA Prompt Optimizer turns labeled contact-center conversation CSVs and user-written evaluation rules into iteratively improved prompts, measured against an accuracy target. Users upload data, describe rules, answer clarifications, monitor optimization, and export evaluation CSVs, prompt CSVs, or a PDF report. The backend parses and audits labels, runs a LangGraph optimization loop, and serves session state and reports to the Angular workflow. The graph preserves documented audit and export capabilities; unsampled node and page implementations are represented only where the README or source index supports them.

Main entry points: [`backend/agents/graph.py`](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/graph.py) (Agent graph), [`frontend/src/app/core/services/session.service.ts`](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/core/services/session.service.ts) (Session service), [`backend/api/routes/sessions.py`](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/api/routes/sessions.py) (Session routes), [`frontend/src/app/pages/results/results.component.ts`](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/results/results.component.ts) (Results view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User workflow"]
  node_upload["Upload CSV"]
  node_descriptions["Rule descriptions"]
  node_clarification_ui["Clarification UI"]
  node_progress_ui["Progress view"]
  node_results_ui["Results view"]
  node_print_report["PDF report"]
  node_session_service["Session service<br/>[session.service.ts]"]
end

subgraph group_api["Session API"]
  node_sessions_api["Session routes<br/>[sessions.py]"]
  node_stream_api["Progress stream<br/>[stream.py]"]
  node_session_store[("Session store<br/>[session_store.py]")]
end

subgraph group_setup["Input and setup"]
  node_csv_parser["CSV parser<br/>[csv_parser.py]"]
  node_ingestion["Rule tracking setup<br/>[csv_ingestion.py]"]
  node_preflight_audit["Ground-truth pre-audit"]
  node_ambiguity["Ambiguity detection"]
  node_baseline["Baseline prompts"]
end

subgraph group_optimization["Optimization loop"]
  node_agent_graph{{"Agent graph<br/>[graph.py]"}}
  node_state["Optimization state<br/>[state.py]"]
  node_evaluator["Conversation evaluator<br/>[evaluator.py]"]
  node_rca["Failure analysis<br/>[rca_analyzer.py]"]
  node_alignment_audit["Label alignment audit"]
  node_mid_clarification["Mid-loop clarification"]
  node_optimizer["Prompt optimizer"]
end

subgraph group_results["Evaluation and results"]
  node_benchmark["Benchmarking<br/>[benchmarking.py]"]
  node_finalize["Report finalization<br/>[finalize.py]"]
end

node_user(("User"))
node_openai{{"OpenAI API"}}

node_user -->|"uploads data"| node_upload
node_user -->|"defines rules"| node_descriptions
node_user -->|"answers questions"| node_clarification_ui
node_user -->|"monitors run"| node_progress_ui
node_user -->|"views results"| node_results_ui
node_upload -.->|"starts session"| node_session_service
node_descriptions -.->|"submits rules"| node_session_service
node_clarification_ui -.->|"submits answers"| node_session_service
node_progress_ui -.->|"checks status"| node_session_service
node_results_ui -.->|"requests report"| node_session_service
node_results_ui -->|"opens print view"| node_print_report
node_session_service -->|"HTTP requests"| node_sessions_api
node_sessions_api -->|"parses upload"| node_csv_parser
node_sessions_api -->|"stores session"| node_session_store
node_sessions_api -->|"starts or resumes"| node_agent_graph
node_stream_api -->|"streams progress"| node_agent_graph
node_stream_api -->|"reads session"| node_session_store
node_agent_graph -->|"dispatches setup"| node_ingestion
node_agent_graph -->|"dispatches audit"| node_preflight_audit
node_agent_graph -->|"dispatches detection"| node_ambiguity
node_agent_graph -->|"dispatches generation"| node_baseline
node_agent_graph -->|"dispatches evaluation"| node_evaluator
node_agent_graph -->|"dispatches scoring"| node_benchmark
node_agent_graph -->|"dispatches analysis"| node_rca
node_agent_graph -->|"dispatches audit"| node_alignment_audit
node_agent_graph -->|"dispatches questions"| node_mid_clarification
node_agent_graph -->|"dispatches rewrite"| node_optimizer
node_agent_graph -->|"dispatches finalization"| node_finalize
node_benchmark -->|"routes below target"| node_rca
node_rca -->|"routes when stalled"| node_alignment_audit
node_rca -->|"routes otherwise"| node_mid_clarification
node_alignment_audit -->|"continues questions"| node_mid_clarification
node_mid_clarification -->|"continues rewrite"| node_optimizer
node_optimizer -->|"reevaluates prompts"| node_evaluator
node_benchmark -->|"routes at completion"| node_finalize
node_ingestion -->|"updates progress"| node_session_store
node_evaluator -.->|"evaluates conversations"| node_openai
node_optimizer -.->|"optimizes prompts"| node_openai
node_finalize -.->|"provides report"| node_results_ui

click node_upload "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/upload/upload.component.ts"
click node_descriptions "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/descriptions/descriptions.component.ts"
click node_clarification_ui "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/clarification/clarification.component.ts"
click node_progress_ui "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/progress/progress.component.ts"
click node_results_ui "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/results/results.component.ts"
click node_print_report "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/results/print-report.component.ts"
click node_session_service "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/core/services/session.service.ts"
click node_sessions_api "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/api/routes/sessions.py"
click node_stream_api "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/api/routes/stream.py"
click node_session_store "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/utils/session_store.py"
click node_csv_parser "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/utils/csv_parser.py"
click node_ingestion "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/csv_ingestion.py"
click node_preflight_audit "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/pre_flight_gt_audit.py"
click node_ambiguity "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/ambiguity_detection.py"
click node_baseline "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/baseline_prompt_generator.py"
click node_agent_graph "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/graph.py"
click node_state "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/state.py"
click node_evaluator "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/evaluator.py"
click node_benchmark "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/benchmarking.py"
click node_rca "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/rca_analyzer.py"
click node_alignment_audit "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/gt_alignment_audit.py"
click node_mid_clarification "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/mid_loop_clarification.py"
click node_optimizer "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/prompt_optimizer.py"
click node_finalize "https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/finalize.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_upload,node_descriptions,node_clarification_ui,node_progress_ui,node_results_ui,node_print_report,node_session_service,node_user toneBlue
class node_sessions_api,node_stream_api,node_session_store toneAmber
class node_csv_parser,node_ingestion,node_preflight_audit,node_ambiguity,node_baseline,node_openai toneMint
class node_agent_graph,node_state,node_evaluator,node_rca,node_alignment_audit,node_mid_clarification,node_optimizer toneRose
class node_benchmark,node_finalize toneIndigo
```

## Components

### User workflow

- [Upload CSV](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/upload/upload.component.ts): `frontend/src/app/pages/upload/upload.component.ts`
- [Rule descriptions](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/descriptions/descriptions.component.ts): `frontend/src/app/pages/descriptions/descriptions.component.ts`
- [Clarification UI](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/clarification/clarification.component.ts): `frontend/src/app/pages/clarification/clarification.component.ts`
- [Progress view](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/progress/progress.component.ts): `frontend/src/app/pages/progress/progress.component.ts`
- [Results view](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/results/results.component.ts): `frontend/src/app/pages/results/results.component.ts`
- [PDF report](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/pages/results/print-report.component.ts): `frontend/src/app/pages/results/print-report.component.ts`
- [Session service](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/frontend/src/app/core/services/session.service.ts): `frontend/src/app/core/services/session.service.ts`

### Session API

- [Session routes](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/api/routes/sessions.py): `backend/api/routes/sessions.py`
- [Progress stream](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/api/routes/stream.py): `backend/api/routes/stream.py`
- [Session store](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/utils/session_store.py): `backend/utils/session_store.py`

### Input and setup

- [CSV parser](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/utils/csv_parser.py): `backend/utils/csv_parser.py`
- [Rule tracking setup](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/csv_ingestion.py): `backend/agents/nodes/csv_ingestion.py`
- [Ground-truth pre-audit](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/pre_flight_gt_audit.py): `backend/agents/nodes/pre_flight_gt_audit.py`
- [Ambiguity detection](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/ambiguity_detection.py): `backend/agents/nodes/ambiguity_detection.py`
- [Baseline prompts](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/baseline_prompt_generator.py): `backend/agents/nodes/baseline_prompt_generator.py`

### Optimization loop

- [Agent graph](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/graph.py): `backend/agents/graph.py`
- [Optimization state](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/state.py): `backend/agents/state.py`
- [Conversation evaluator](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/evaluator.py): `backend/agents/nodes/evaluator.py`
- [Failure analysis](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/rca_analyzer.py): `backend/agents/nodes/rca_analyzer.py`
- [Label alignment audit](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/gt_alignment_audit.py): `backend/agents/nodes/gt_alignment_audit.py`
- [Mid-loop clarification](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/mid_loop_clarification.py): `backend/agents/nodes/mid_loop_clarification.py`
- [Prompt optimizer](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/prompt_optimizer.py): `backend/agents/nodes/prompt_optimizer.py`

### Evaluation and results

- [Benchmarking](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/benchmarking.py): `backend/agents/nodes/benchmarking.py`
- [Report finalization](https://github.com/anto5699/autoqa-prompt-optimizer/blob/main/backend/agents/nodes/finalize.py): `backend/agents/nodes/finalize.py`

### Other components

- **User**
- **OpenAI API**

## Connections

- User → Upload CSV: uploads data (evidence: `README.md`)
- User → Rule descriptions: defines rules (evidence: `README.md`)
- User → Clarification UI: answers questions (evidence: `README.md`)
- User → Progress view: monitors run (evidence: `README.md`)
- User → Results view: views results (evidence: `README.md`)
- Upload CSV → Session service: starts session
- Rule descriptions → Session service: submits rules
- Clarification UI → Session service: submits answers
- Progress view → Session service: checks status
- Results view → Session service: requests report
- Results view → PDF report: opens print view (evidence: `frontend/src/app/app.routes.ts`)
- Session service → Session routes: HTTP requests (evidence: `frontend/src/app/core/services/session.service.ts`)
- Session routes → CSV parser: parses upload (evidence: `backend/api/routes/sessions.py`)
- Session routes → Session store: stores session (evidence: `backend/api/routes/sessions.py`)
- Session routes → Agent graph: starts or resumes (evidence: `backend/api/routes/sessions.py`)
- Progress stream → Agent graph: streams progress (evidence: `backend/api/routes/stream.py`)
- Progress stream → Session store: reads session (evidence: `backend/api/routes/stream.py`)
- Agent graph → Rule tracking setup: dispatches setup (evidence: `backend/agents/graph.py`)
- Agent graph → Ground-truth pre-audit: dispatches audit (evidence: `backend/agents/graph.py`)
- Agent graph → Ambiguity detection: dispatches detection (evidence: `backend/agents/graph.py`)
- Agent graph → Baseline prompts: dispatches generation (evidence: `backend/agents/graph.py`)
- Agent graph → Conversation evaluator: dispatches evaluation (evidence: `backend/agents/graph.py`)
- Agent graph → Benchmarking: dispatches scoring (evidence: `backend/agents/graph.py`)
- Agent graph → Failure analysis: dispatches analysis (evidence: `backend/agents/graph.py`)
- Agent graph → Label alignment audit: dispatches audit (evidence: `backend/agents/graph.py`)
- Agent graph → Mid-loop clarification: dispatches questions (evidence: `backend/agents/graph.py`)
- Agent graph → Prompt optimizer: dispatches rewrite (evidence: `backend/agents/graph.py`)
- Agent graph → Report finalization: dispatches finalization (evidence: `backend/agents/graph.py`)
- Benchmarking → Failure analysis: routes below target (evidence: `backend/agents/graph.py`)
- Failure analysis → Label alignment audit: routes when stalled (evidence: `backend/agents/graph.py`)
- Failure analysis → Mid-loop clarification: routes otherwise (evidence: `backend/agents/graph.py`)
- Label alignment audit → Mid-loop clarification: continues questions (evidence: `backend/agents/graph.py`)
- Mid-loop clarification → Prompt optimizer: continues rewrite (evidence: `backend/agents/graph.py`)
- Prompt optimizer → Conversation evaluator: reevaluates prompts (evidence: `backend/agents/graph.py`)
- Benchmarking → Report finalization: routes at completion (evidence: `backend/agents/graph.py`)
- Rule tracking setup → Session store: updates progress (evidence: `backend/agents/nodes/csv_ingestion.py`)
- Conversation evaluator → OpenAI API: evaluates conversations (evidence: `README.md`)
- Prompt optimizer → OpenAI API: optimizes prompts (evidence: `README.md`)
- Report finalization → Results view: provides report (evidence: `README.md`)
