# sujith-chowdary/hallucination-detection architecture

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

- Interactive diagram: https://gitdiagram.com/sujith-chowdary/hallucination-detection
- Repository: https://github.com/sujith-chowdary/hallucination-detection

## Overview

This is a web-based hallucination-verification system: users submit answers with supporting knowledge, the backend checks extracted claims, and the UI presents verdicts and revised answers. The documented workflow includes PDF/text ingestion, translation, short-answer expansion, claim extraction, hybrid retrieval, prioritized verification, optional web evidence, consensus, revision, and translation back. Authentication and saved knowledge bases form a supporting branch. The README documents several stages whose detailed implementation was not sampled; those links are cited to the README.

Main entry points: [`backend/main.py`](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/main.py) (API server), [`frontend/app_with_auth.py`](https://github.com/sujith-chowdary/hallucination-detection/blob/main/frontend/app_with_auth.py) (Web interface), [`backend/routes.py`](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/routes.py) (Auth and KB routes), [`backend/services/user_service.py`](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/services/user_service.py) (User service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User interface"]
  node_frontend["Web interface<br/>[app_with_auth.py]"]
  node_auth_ui["Auth views<br/>[auth_components.py]"]
end

subgraph group_verification["Verification pipeline"]
  node_api["API server<br/>[main.py]"]
  node_utilities["PDF and language tools<br/>[utils.py]"]
  node_expand["Answer expansion"]
  node_claims["Claim extraction"]
  node_retrieval["Hybrid retrieval<br/>[rag.py]"]
  node_check["Claim verification"]
  node_consensus["Verdict and revision"]
end

subgraph group_account["Accounts and knowledge"]
  node_routes["Auth and KB routes<br/>[routes.py]"]
  node_auth["Token authentication<br/>[auth.py]"]
  node_users["User service<br/>[user_service.py]"]
  node_knowledge_service["Knowledge service"]
end

subgraph group_infrastructure["Evidence and persistence"]
  node_search["Web search<br/>[utils.py]"]
  node_user_model["User records<br/>[user.py]"]
  node_knowledge_model["Knowledge records<br/>[knowledge_base.py]"]
  node_database[("PostgreSQL access<br/>[database.py]")]
end

node_user(("User"))
node_serpapi["SerpAPI"]

node_user -->|"submits input"| node_frontend
node_frontend -->|"sends requests"| node_api
node_api -->|"returns results"| node_frontend
node_frontend -->|"uses auth views"| node_auth_ui
node_api -->|"runs verification"| node_expand
node_expand -->|"expands answer"| node_claims
node_claims -->|"retrieves evidence"| node_retrieval
node_retrieval -->|"supplies evidence"| node_check
node_check -->|"provides verdicts"| node_consensus
node_consensus -->|"returns revised answer"| node_frontend
node_api -->|"uses processing tools"| node_utilities
node_utilities -.->|"translates input"| node_expand
node_api -->|"uses optional search"| node_search
node_search -.->|"queries"| node_serpapi
node_api -->|"registers routes"| node_routes
node_routes -->|"checks identity"| node_auth
node_routes -->|"delegates user actions"| node_users
node_routes -->|"delegates KB actions"| node_knowledge_service
node_users -->|"uses user schema"| node_user_model
node_users -->|"queries and writes"| node_database
node_knowledge_service -->|"uses KB schema"| node_knowledge_model
node_knowledge_service -->|"queries and writes"| node_database
node_api -->|"connects at startup"| node_database

click node_frontend "https://github.com/sujith-chowdary/hallucination-detection/blob/main/frontend/app_with_auth.py"
click node_auth_ui "https://github.com/sujith-chowdary/hallucination-detection/blob/main/frontend/auth_components.py"
click node_api "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/main.py"
click node_utilities "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/utils.py"
click node_expand "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py"
click node_claims "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py"
click node_retrieval "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/rag.py"
click node_check "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py"
click node_consensus "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py"
click node_search "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/utils.py"
click node_routes "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/routes.py"
click node_auth "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/auth.py"
click node_users "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/services/user_service.py"
click node_knowledge_service "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/services/knowledge_base_service.py"
click node_user_model "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/models/user.py"
click node_knowledge_model "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/models/knowledge_base.py"
click node_database "https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/database.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_frontend,node_auth_ui,node_user toneBlue
class node_api,node_utilities,node_expand,node_claims,node_retrieval,node_check,node_consensus toneAmber
class node_routes,node_auth,node_users,node_knowledge_service,node_serpapi toneMint
class node_search,node_user_model,node_knowledge_model,node_database toneRose
```

## Components

### User interface

- [Web interface](https://github.com/sujith-chowdary/hallucination-detection/blob/main/frontend/app_with_auth.py): `frontend/app_with_auth.py`
- [Auth views](https://github.com/sujith-chowdary/hallucination-detection/blob/main/frontend/auth_components.py): `frontend/auth_components.py`

### Verification pipeline

- [API server](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/main.py): `backend/main.py`
- [PDF and language tools](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/utils.py): `backend/core/utils.py`
- [Answer expansion](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py): `backend/core/self_correction_pipeline.py`
- [Claim extraction](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py): `backend/core/self_correction_pipeline.py`
- [Hybrid retrieval](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/rag.py): `backend/core/rag.py`
- [Claim verification](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py): `backend/core/self_correction_pipeline.py`
- [Verdict and revision](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/self_correction_pipeline.py): `backend/core/self_correction_pipeline.py`

### Accounts and knowledge

- [Auth and KB routes](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/routes.py): `backend/routes.py`
- [Token authentication](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/auth.py): `backend/auth.py`
- [User service](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/services/user_service.py): `backend/services/user_service.py`
- [Knowledge service](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/services/knowledge_base_service.py): `backend/services/knowledge_base_service.py`

### Evidence and persistence

- [Web search](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/core/utils.py): `backend/core/utils.py`
- [User records](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/models/user.py): `backend/models/user.py`
- [Knowledge records](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/models/knowledge_base.py): `backend/models/knowledge_base.py`
- [PostgreSQL access](https://github.com/sujith-chowdary/hallucination-detection/blob/main/backend/database.py): `backend/database.py`

### Other components

- **User**
- **SerpAPI**

## Connections

- User → Web interface: submits input (evidence: `README.md`)
- Web interface → API server: sends requests (evidence: `README.md`)
- API server → Web interface: returns results (evidence: `README.md`)
- Web interface → Auth views: uses auth views (evidence: `frontend/app_with_auth.py`)
- API server → Answer expansion: runs verification (evidence: `backend/main.py`)
- Answer expansion → Claim extraction: expands answer (evidence: `README.md`)
- Claim extraction → Hybrid retrieval: retrieves evidence (evidence: `README.md`)
- Hybrid retrieval → Claim verification: supplies evidence (evidence: `README.md`)
- Claim verification → Verdict and revision: provides verdicts (evidence: `README.md`)
- Verdict and revision → Web interface: returns revised answer (evidence: `README.md`)
- API server → PDF and language tools: uses processing tools (evidence: `backend/main.py`)
- PDF and language tools → Answer expansion: translates input (evidence: `README.md`)
- API server → Web search: uses optional search (evidence: `backend/main.py`)
- Web search → SerpAPI: queries (evidence: `README.md`)
- API server → Auth and KB routes: registers routes (evidence: `backend/main.py`)
- Auth and KB routes → Token authentication: checks identity (evidence: `backend/routes.py`)
- Auth and KB routes → User service: delegates user actions (evidence: `backend/routes.py`)
- Auth and KB routes → Knowledge service: delegates KB actions (evidence: `backend/routes.py`)
- User service → User records: uses user schema (evidence: `backend/services/user_service.py`)
- User service → PostgreSQL access: queries and writes (evidence: `backend/services/user_service.py`)
- Knowledge service → Knowledge records: uses KB schema (evidence: `backend/services/knowledge_base_service.py`)
- Knowledge service → PostgreSQL access: queries and writes (evidence: `backend/services/knowledge_base_service.py`)
- API server → PostgreSQL access: connects at startup (evidence: `backend/main.py`)
