# nidhi752/project architecture

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

- Interactive diagram: https://gitdiagram.com/nidhi752/project
- Repository: https://github.com/nidhi752/project

## Overview

MediGenius is a medical-information assistant whose primary flow accepts a chat question, applies deterministic safety checks, runs a LangGraph multi-agent workflow, grounds and verifies the answer, then returns it with a disclaimer. The workflow includes retrieval, direct model fallback, symptom and medication handling, and session memory; flagged responses feed clinician review. The README documents several branches whose implementation was not sampled, so those relationships are cited to it; unshown wiring is omitted. The React excerpt shows session requests, but not enough chat-call detail to map every UI-to-API interaction.

Main entry points: [`backend/app/core/langgraph_workflow.py`](https://github.com/nidhi752/project/blob/main/backend/app/core/langgraph_workflow.py) (LangGraph workflow), [`backend/app/services/chat_service.py`](https://github.com/nidhi752/project/blob/main/backend/app/services/chat_service.py) (Chat orchestration), [`backend/app/agents/parallel_retrieval_agent.py`](https://github.com/nidhi752/project/blob/main/backend/app/agents/parallel_retrieval_agent.py) (Parallel retrieval), [`backend/app/services/database_service.py`](https://github.com/nidhi752/project/blob/main/backend/app/services/database_service.py) (Chat and audit service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_web_ui["Chat interface<br/>[App.jsx]"]
end

subgraph group_request["Request and safety"]
  node_api["API router<br/>[api.py]"]
  node_chat_endpoint["Chat endpoint<br/>[chat.py]"]
  node_chat_service["Chat orchestration<br/>[chat_service.py]"]
  node_safety["Safety gate<br/>[safety_router.py]"]
  node_dosage["Dosage grounding"]
end

subgraph group_agents["Agent workflow"]
  node_state["Agent state<br/>[state.py]"]
  node_workflow["LangGraph workflow"]
  node_supervisor["Medical supervisor"]
  node_symptoms["Symptom structuring"]
  node_drug_agent["Drug recognition"]
  node_executor["Answer synthesis<br/>[executor.py]"]
  node_llm["Direct LLM fallback<br/>[llm_agent.py]"]
  node_verification["Diagnosis verification"]
end

subgraph group_knowledge["Knowledge and memory"]
  node_retrieval["Parallel retrieval"]
  node_vector_store[("Medical vector store<br/>[vector_store.py]")]
  node_web_retrieval["Wikipedia and Tavily"]
  node_gateway["Model gateway<br/>[model_gateway.py]"]
  node_memory_agent["Session recall<br/>[memory.py]"]
  node_memory_store[("Semantic memory<br/>[memory_store.py]")]
end

subgraph group_operations["Persistence and review"]
  node_database_service["Chat and audit service"]
  node_chat_db[("Chat database<br/>[message.py]")]
  node_review_api["Clinician review API<br/>[review.py]"]
end

node_user(("Patient"))
node_reviewer(("Clinician"))
node_groq{{"LLM provider"}}
node_rxnav{{"RxNav service"}}

node_user -->|"asks question"| node_web_ui
node_web_ui -.->|"sends requests"| node_api
node_api -->|"registers routes"| node_chat_endpoint
node_chat_endpoint -.->|"handles chat"| node_chat_service
node_chat_service -->|"checks input"| node_safety
node_chat_service -->|"invokes workflow"| node_workflow
node_chat_service -->|"grounds answer"| node_dosage
node_chat_service -->|"persists messages"| node_database_service
node_chat_service -->|"stores exchanges"| node_memory_store
node_workflow -->|"shares state"| node_state
node_workflow -->|"routes questions"| node_supervisor
node_supervisor -->|"structures symptoms"| node_symptoms
node_supervisor -->|"checks medications"| node_drug_agent
node_drug_agent -->|"recognizes names"| node_rxnav
node_workflow -->|"retrieves evidence"| node_retrieval
node_retrieval -->|"queries RAG"| node_vector_store
node_retrieval -->|"fans out searches"| node_web_retrieval
node_retrieval -->|"supplies evidence"| node_executor
node_workflow -->|"synthesizes answer"| node_executor
node_workflow -->|"uses fallback"| node_llm
node_llm -->|"generates response"| node_gateway
node_gateway -->|"calls models"| node_groq
node_workflow -->|"verifies claims"| node_verification
node_workflow -->|"recalls context"| node_memory_agent
node_memory_agent -.->|"retrieves memories"| node_memory_store
node_database_service -->|"reads and writes"| node_chat_db
node_database_service -->|"deletes session memory"| node_memory_store
node_reviewer -->|"reviews flags"| node_review_api
node_review_api -->|"loads review queue"| node_database_service

click node_web_ui "https://github.com/nidhi752/project/blob/main/frontend/src/App.jsx"
click node_api "https://github.com/nidhi752/project/blob/main/backend/app/api/v1/api.py"
click node_chat_endpoint "https://github.com/nidhi752/project/blob/main/backend/app/api/v1/endpoints/chat.py"
click node_chat_service "https://github.com/nidhi752/project/blob/main/backend/app/services/chat_service.py"
click node_safety "https://github.com/nidhi752/project/blob/main/backend/app/core/safety_router.py"
click node_dosage "https://github.com/nidhi752/project/blob/main/backend/app/core/dosage_grounding.py"
click node_state "https://github.com/nidhi752/project/blob/main/backend/app/core/state.py"
click node_workflow "https://github.com/nidhi752/project/blob/main/backend/app/core/langgraph_workflow.py"
click node_supervisor "https://github.com/nidhi752/project/blob/main/backend/app/agents/medical_supervisor_agent.py"
click node_symptoms "https://github.com/nidhi752/project/blob/main/backend/app/agents/symptom_analysis_sub_agent.py"
click node_drug_agent "https://github.com/nidhi752/project/blob/main/backend/app/agents/drug_interaction_sub_agent.py"
click node_retrieval "https://github.com/nidhi752/project/blob/main/backend/app/agents/parallel_retrieval_agent.py"
click node_vector_store "https://github.com/nidhi752/project/blob/main/backend/app/tools/vector_store.py"
click node_web_retrieval "https://github.com/nidhi752/project/blob/main/backend/app/agents/parallel_retrieval_agent.py"
click node_executor "https://github.com/nidhi752/project/blob/main/backend/app/agents/executor.py"
click node_llm "https://github.com/nidhi752/project/blob/main/backend/app/agents/llm_agent.py"
click node_gateway "https://github.com/nidhi752/project/blob/main/backend/app/tools/model_gateway.py"
click node_verification "https://github.com/nidhi752/project/blob/main/backend/app/agents/diagnosis_verification_sub_agent.py"
click node_memory_agent "https://github.com/nidhi752/project/blob/main/backend/app/agents/memory.py"
click node_memory_store "https://github.com/nidhi752/project/blob/main/backend/app/tools/memory_store.py"
click node_database_service "https://github.com/nidhi752/project/blob/main/backend/app/services/database_service.py"
click node_chat_db "https://github.com/nidhi752/project/blob/main/backend/app/models/message.py"
click node_review_api "https://github.com/nidhi752/project/blob/main/backend/app/api/v1/endpoints/review.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_web_ui toneBlue
class node_api,node_chat_endpoint,node_chat_service,node_safety,node_dosage toneAmber
class node_state,node_workflow,node_supervisor,node_symptoms,node_drug_agent,node_executor,node_llm,node_verification toneMint
class node_retrieval,node_vector_store,node_web_retrieval,node_gateway,node_memory_agent,node_memory_store toneRose
class node_database_service,node_chat_db,node_review_api,node_user,node_reviewer,node_groq,node_rxnav toneIndigo
```

## Components

### User experience

- [Chat interface](https://github.com/nidhi752/project/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`

### Request and safety

- [API router](https://github.com/nidhi752/project/blob/main/backend/app/api/v1/api.py): `backend/app/api/v1/api.py`
- [Chat endpoint](https://github.com/nidhi752/project/blob/main/backend/app/api/v1/endpoints/chat.py): `backend/app/api/v1/endpoints/chat.py`
- [Chat orchestration](https://github.com/nidhi752/project/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`
- [Safety gate](https://github.com/nidhi752/project/blob/main/backend/app/core/safety_router.py): `backend/app/core/safety_router.py`
- [Dosage grounding](https://github.com/nidhi752/project/blob/main/backend/app/core/dosage_grounding.py): `backend/app/core/dosage_grounding.py`

### Agent workflow

- [Agent state](https://github.com/nidhi752/project/blob/main/backend/app/core/state.py): `backend/app/core/state.py`
- [LangGraph workflow](https://github.com/nidhi752/project/blob/main/backend/app/core/langgraph_workflow.py): `backend/app/core/langgraph_workflow.py`
- [Medical supervisor](https://github.com/nidhi752/project/blob/main/backend/app/agents/medical_supervisor_agent.py): `backend/app/agents/medical_supervisor_agent.py`
- [Symptom structuring](https://github.com/nidhi752/project/blob/main/backend/app/agents/symptom_analysis_sub_agent.py): `backend/app/agents/symptom_analysis_sub_agent.py`
- [Drug recognition](https://github.com/nidhi752/project/blob/main/backend/app/agents/drug_interaction_sub_agent.py): `backend/app/agents/drug_interaction_sub_agent.py`
- [Answer synthesis](https://github.com/nidhi752/project/blob/main/backend/app/agents/executor.py): `backend/app/agents/executor.py`
- [Direct LLM fallback](https://github.com/nidhi752/project/blob/main/backend/app/agents/llm_agent.py): `backend/app/agents/llm_agent.py`
- [Diagnosis verification](https://github.com/nidhi752/project/blob/main/backend/app/agents/diagnosis_verification_sub_agent.py): `backend/app/agents/diagnosis_verification_sub_agent.py`

### Knowledge and memory

- [Parallel retrieval](https://github.com/nidhi752/project/blob/main/backend/app/agents/parallel_retrieval_agent.py): `backend/app/agents/parallel_retrieval_agent.py`
- [Medical vector store](https://github.com/nidhi752/project/blob/main/backend/app/tools/vector_store.py): `backend/app/tools/vector_store.py`
- [Wikipedia and Tavily](https://github.com/nidhi752/project/blob/main/backend/app/agents/parallel_retrieval_agent.py): `backend/app/agents/parallel_retrieval_agent.py`
- [Model gateway](https://github.com/nidhi752/project/blob/main/backend/app/tools/model_gateway.py): `backend/app/tools/model_gateway.py`
- [Session recall](https://github.com/nidhi752/project/blob/main/backend/app/agents/memory.py): `backend/app/agents/memory.py`
- [Semantic memory](https://github.com/nidhi752/project/blob/main/backend/app/tools/memory_store.py): `backend/app/tools/memory_store.py`

### Persistence and review

- [Chat and audit service](https://github.com/nidhi752/project/blob/main/backend/app/services/database_service.py): `backend/app/services/database_service.py`
- [Chat database](https://github.com/nidhi752/project/blob/main/backend/app/models/message.py): `backend/app/models/message.py`
- [Clinician review API](https://github.com/nidhi752/project/blob/main/backend/app/api/v1/endpoints/review.py): `backend/app/api/v1/endpoints/review.py`

### Other components

- **Patient**
- **Clinician**
- **LLM provider**
- **RxNav service**

## Connections

- Patient → Chat interface: asks question
- Chat interface → API router: sends requests
- API router → Chat endpoint: registers routes (evidence: `backend/app/api/v1/api.py`)
- Chat endpoint → Chat orchestration: handles chat
- Chat orchestration → Safety gate: checks input (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → LangGraph workflow: invokes workflow (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Dosage grounding: grounds answer (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Chat and audit service: persists messages (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Semantic memory: stores exchanges (evidence: `backend/app/services/chat_service.py`)
- LangGraph workflow → Agent state: shares state (evidence: `backend/app/core/langgraph_workflow.py`)
- LangGraph workflow → Medical supervisor: routes questions (evidence: `backend/app/core/langgraph_workflow.py`)
- Medical supervisor → Symptom structuring: structures symptoms
- Medical supervisor → Drug recognition: checks medications
- Drug recognition → RxNav service: recognizes names
- LangGraph workflow → Parallel retrieval: retrieves evidence (evidence: `backend/app/core/langgraph_workflow.py`)
- Parallel retrieval → Medical vector store: queries RAG (evidence: `backend/app/agents/parallel_retrieval_agent.py`)
- Parallel retrieval → Wikipedia and Tavily: fans out searches (evidence: `backend/app/agents/parallel_retrieval_agent.py`)
- Parallel retrieval → Answer synthesis: supplies evidence
- LangGraph workflow → Answer synthesis: synthesizes answer (evidence: `backend/app/core/langgraph_workflow.py`)
- LangGraph workflow → Direct LLM fallback: uses fallback (evidence: `backend/app/core/langgraph_workflow.py`)
- Direct LLM fallback → Model gateway: generates response (evidence: `backend/app/agents/llm_agent.py`)
- Model gateway → LLM provider: calls models
- LangGraph workflow → Diagnosis verification: verifies claims (evidence: `backend/app/core/langgraph_workflow.py`)
- LangGraph workflow → Session recall: recalls context (evidence: `backend/app/core/langgraph_workflow.py`)
- Session recall → Semantic memory: retrieves memories
- Chat and audit service → Chat database: reads and writes (evidence: `backend/app/services/database_service.py`)
- Chat and audit service → Semantic memory: deletes session memory (evidence: `backend/app/services/database_service.py`)
- Clinician → Clinician review API: reviews flags (evidence: `backend/app/api/v1/endpoints/review.py`)
- Clinician review API → Chat and audit service: loads review queue (evidence: `backend/app/api/v1/endpoints/review.py`)
