# gyanendra0/denial-appeal-agent architecture

> Architecture diagram of the GitHub repository gyanendra0/denial-appeal-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gyanendra0/denial-appeal-agent
- Repository: https://github.com/gyanendra0/denial-appeal-agent

## Overview

This is a denial-and-appeal backend: an uploaded denial is extracted, assessed for appeal-worthiness, researched against evidence, and drafted into a letter for human review rather than automatic sending. The graph preserves the documented workflow and the product’s API, data preparation, model, evidence, and review capabilities. Some paths and handoffs are supported only by the README or SOURCE INDEX; unsampled implementation details are not inferred beyond those references.

Main entry points: [`src/db/models.py`](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/db/models.py) (PostgreSQL Store), [`src/agent/loop.py`](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/agent/loop.py) (Appeal Agent), [`src/jobs/run.py`](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/jobs/run.py) (Upload Job), [`src/drafting/drafter.py`](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/drafting/drafter.py) (Letter Drafting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["API and Jobs"]
  node_api["Web API<br/>[app.py]"]
  node_job["Upload Job<br/>[run.py]"]
end

subgraph group_casework["Appeal Casework"]
  node_extract["Denial Extraction<br/>[extractor.py]"]
  node_agent["Appeal Agent<br/>[loop.py]"]
  node_draft["Letter Drafting<br/>[drafter.py]"]
end

subgraph group_knowledge["Evidence and Data"]
  node_corpus["Evidence Ingestion<br/>[evidence_corpus.py]"]
  node_embed["Evidence Embedding<br/>[embedding_run.py]"]
  node_retrieve["Evidence Retrieval<br/>[retrieval.py]"]
  node_dataingest["Claims Data Loading<br/>[claims_sample.py]"]
end

subgraph group_models["Prediction and Rules"]
  node_label["Proxy Labels<br/>[labels.py]"]
  node_train["Win Model Training<br/>[training.py]"]
  node_inference["Win Prediction<br/>[inference.py]"]
  node_rules["Appeal Rules<br/>[evaluate.py]"]
end

subgraph group_platform["Persistence and Models"]
  node_gateway["LLM Gateway<br/>[gateway.py]"]
  node_database[("PostgreSQL Store<br/>[models.py]")]
end

subgraph group_oversight["Review and Evaluation"]
  node_review["Draft Review<br/>[review_store.py]"]
  node_reviewscore["Review Scoring<br/>[review_score.py]"]
end

node_claimant(("Uploader"))
node_human(("Human Reviewer"))
node_provider["LLM Provider"]

node_claimant -->|"uploads denial"| node_api
node_api -->|"queues job"| node_job
node_job -->|"extracts fields"| node_extract
node_job -->|"runs casework"| node_agent
node_agent -->|"scores appeal"| node_inference
node_agent -->|"evaluates case"| node_rules
node_agent -->|"requests draft"| node_draft
node_draft -->|"finds evidence"| node_retrieve
node_draft -->|"generates letter"| node_gateway
node_retrieve -->|"embeds question"| node_gateway
node_embed -->|"embeds chunks"| node_gateway
node_gateway -->|"calls model"| node_provider
node_corpus -.->|"stores evidence"| node_database
node_embed -->|"stores vectors"| node_database
node_retrieve -->|"searches vectors"| node_database
node_job -->|"stores job results"| node_database
node_agent -->|"stores trace"| node_database
node_draft -->|"awaits approval"| node_human
node_human -->|"reviews draft"| node_review
node_review -->|"reads drafts"| node_database
node_human -->|"scores review"| node_reviewscore
node_dataingest -.->|"loads claims"| node_database
node_label -.->|"stores proxy labels"| node_database
node_train -->|"reads training data"| node_database
node_inference -->|"loads saved model"| node_train

click node_api "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/api/app.py"
click node_job "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/jobs/run.py"
click node_extract "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/extraction/extractor.py"
click node_agent "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/agent/loop.py"
click node_draft "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/drafting/drafter.py"
click node_review "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/evaluation/review_store.py"
click node_reviewscore "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/evaluation/review_score.py"
click node_corpus "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ingest/evidence_corpus.py"
click node_embed "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/rag/embedding_run.py"
click node_retrieve "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/rag/retrieval.py"
click node_label "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ml/labels.py"
click node_train "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ml/training.py"
click node_inference "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ml/inference.py"
click node_rules "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/rules/evaluate.py"
click node_gateway "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/llm/gateway.py"
click node_database "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/db/models.py"
click node_dataingest "https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ingest/claims_sample.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_api,node_job,node_human toneBlue
class node_extract,node_agent,node_draft toneAmber
class node_corpus,node_embed,node_retrieve,node_dataingest toneMint
class node_label,node_train,node_inference,node_rules toneRose
class node_gateway,node_database,node_claimant,node_provider toneIndigo
class node_review,node_reviewscore toneTeal
```

## Components

### API and Jobs

- [Web API](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/api/app.py): `src/api/app.py`
- [Upload Job](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/jobs/run.py): `src/jobs/run.py`

### Appeal Casework

- [Denial Extraction](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/extraction/extractor.py): `src/extraction/extractor.py`
- [Appeal Agent](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/agent/loop.py): `src/agent/loop.py`
- [Letter Drafting](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/drafting/drafter.py): `src/drafting/drafter.py`

### Evidence and Data

- [Evidence Ingestion](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ingest/evidence_corpus.py): `src/ingest/evidence_corpus.py`
- [Evidence Embedding](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/rag/embedding_run.py): `src/rag/embedding_run.py`
- [Evidence Retrieval](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/rag/retrieval.py): `src/rag/retrieval.py`
- [Claims Data Loading](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ingest/claims_sample.py): `src/ingest/claims_sample.py`

### Prediction and Rules

- [Proxy Labels](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ml/labels.py): `src/ml/labels.py`
- [Win Model Training](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ml/training.py): `src/ml/training.py`
- [Win Prediction](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/ml/inference.py): `src/ml/inference.py`
- [Appeal Rules](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/rules/evaluate.py): `src/rules/evaluate.py`

### Persistence and Models

- [LLM Gateway](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/llm/gateway.py): `src/llm/gateway.py`
- [PostgreSQL Store](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/db/models.py): `src/db/models.py`

### Review and Evaluation

- [Draft Review](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/evaluation/review_store.py): `src/evaluation/review_store.py`
- [Review Scoring](https://github.com/gyanendra0/denial-appeal-agent/blob/main/src/evaluation/review_score.py): `src/evaluation/review_score.py`

### Other components

- **Uploader**
- **Human Reviewer**
- **LLM Provider**

## Connections

- Uploader → Web API: uploads denial (evidence: `README.md`)
- Web API → Upload Job: queues job (evidence: `src/api/app.py`)
- Upload Job → Denial Extraction: extracts fields (evidence: `src/jobs/run.py`)
- Upload Job → Appeal Agent: runs casework (evidence: `src/jobs/run.py`)
- Appeal Agent → Win Prediction: scores appeal (evidence: `src/agent/loop.py`)
- Appeal Agent → Appeal Rules: evaluates case (evidence: `src/agent/loop.py`)
- Appeal Agent → Letter Drafting: requests draft (evidence: `src/agent/loop.py`)
- Letter Drafting → Evidence Retrieval: finds evidence (evidence: `src/drafting/drafter.py`)
- Letter Drafting → LLM Gateway: generates letter (evidence: `src/drafting/drafter.py`)
- Evidence Retrieval → LLM Gateway: embeds question (evidence: `src/rag/retrieval.py`)
- Evidence Embedding → LLM Gateway: embeds chunks (evidence: `src/rag/embedding_run.py`)
- LLM Gateway → LLM Provider: calls model (evidence: `src/llm/gateway.py`)
- Evidence Ingestion → PostgreSQL Store: stores evidence
- Evidence Embedding → PostgreSQL Store: stores vectors (evidence: `src/rag/embedding_run.py`)
- Evidence Retrieval → PostgreSQL Store: searches vectors (evidence: `src/rag/retrieval.py`)
- Upload Job → PostgreSQL Store: stores job results (evidence: `src/jobs/run.py`)
- Appeal Agent → PostgreSQL Store: stores trace (evidence: `src/agent/loop.py`)
- Letter Drafting → Human Reviewer: awaits approval (evidence: `README.md`)
- Human Reviewer → Draft Review: reviews draft (evidence: `README.md`)
- Draft Review → PostgreSQL Store: reads drafts (evidence: `src/evaluation/review_store.py`)
- Human Reviewer → Review Scoring: scores review (evidence: `src/evaluation/review_score.py`)
- Claims Data Loading → PostgreSQL Store: loads claims
- Proxy Labels → PostgreSQL Store: stores proxy labels (evidence: `src/ml/labels.py`)
- Win Model Training → PostgreSQL Store: reads training data (evidence: `src/ml/training.py`)
- Win Prediction → Win Model Training: loads saved model (evidence: `src/ml/inference.py`)
