# zgsddzwj/intelligent_consultation architecture

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

- Interactive diagram: https://gitdiagram.com/zgsddzwj/intelligent_consultation
- Repository: https://github.com/zgsddzwj/intelligent_consultation

## Overview

This is an AI-powered medical consultation platform with a React frontend and FastAPI backend. The main user journey is patient chat through the API to LangGraph agent orchestration, then specialist agents use LLM and medical knowledge services to produce cited, risk-aware responses. Separate capabilities include clinician and admin workspaces, image and speech features, and knowledge-graph exploration. The graph combines README-documented architecture with source-index references and excerpts; unsampled endpoint and subsystem internals are represented at their existing directory paths, without asserting undocumented call links.

Main entry points: [`frontend/src/services/api.ts`](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/services/api.ts) (API Client), [`backend/app/agents`](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/agents) (Specialist Agents), [`backend/app/services/llm_service.py`](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/llm_service.py) (LLM Service), [`backend/app/main.py`](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/main.py) (FastAPI Entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User Experience"]
  node_web["Patient Portal<br/>[PatientPortal.tsx]"]
  node_clinician["Doctor Dashboard"]
  node_adminui["Admin Workspace<br/>[AdminPanel.tsx]"]
  node_graphui["Graph Explorer<br/>[KnowledgeGraph.tsx]"]
  node_chattypes["Chat Contracts<br/>[chat.ts]"]
  node_webapi["API Client<br/>[api.ts]"]
  node_auth["Authentication<br/>[auth.ts]"]
end

subgraph group_api["API and Orchestration"]
  node_fastapi["FastAPI Entry<br/>[main.py]"]
  node_routes["API Routes"]
  node_deps["Service Factory<br/>[dependencies.py]"]
  node_orchestrator["Agent Orchestrator<br/>[orchestrator.py]"]
  node_image["Image Analysis<br/>[image_analysis.py]"]
  node_speech["Speech Services<br/>[asr_service.py]"]
end

subgraph group_intelligence["Medical Intelligence"]
  node_agentbase["Agent Runtime<br/>[base.py]"]
  node_specialists["Specialist Agents"]
  node_ragtool["RAG Tool<br/>[rag_tool.py]"]
  node_rag["Hybrid RAG"]
  node_kg["Medical Graph"]
  node_ml["ML Knowledge"]
  node_llm["LLM Service<br/>[llm_service.py]"]
end

subgraph group_platform["Data and Operations"]
  node_pg[("PostgreSQL")]
  node_redis[("Redis")]
  node_milvus[("Milvus")]
  node_neo4j[("Neo4j")]
  node_objectstore[("Object Storage<br/>[object_storage.py]")]
  node_middleware["API Middleware"]
  node_monitoring["Monitoring<br/>[monitoring.py]"]
  node_cache["Cache Service<br/>[cache_service.py]"]
  node_session["Database Session<br/>[session.py]"]
  node_logging["Logging and Tracing<br/>[tracing.py]"]
  node_config["Configuration<br/>[config.py]"]
end

node_patient(("Patient"))

node_patient -->|"uses"| node_web
node_web -->|"submits consultation"| node_webapi
node_web -->|"uses contracts"| node_chattypes
node_webapi -->|"calls API"| node_fastapi
node_webapi -->|"clears tokens"| node_auth
node_auth -->|"posts login"| node_webapi
node_fastapi -->|"applies"| node_middleware
node_fastapi -->|"routes requests"| node_routes
node_routes -.->|"dispatches consultations"| node_orchestrator
node_fastapi -->|"initializes services"| node_deps
node_deps -->|"provides"| node_orchestrator
node_orchestrator -->|"dispatches agents"| node_specialists
node_specialists -->|"inherit runtime"| node_agentbase
node_specialists -->|"uses retrieval"| node_ragtool
node_ragtool -->|"retrieves context"| node_rag
node_specialists -->|"queries diseases"| node_kg
node_specialists -->|"recognizes entities"| node_ml
node_specialists -->|"generates responses"| node_llm
node_agentbase -->|"uses service"| node_llm
node_agentbase -->|"uses tracing"| node_logging
node_rag -->|"searches vectors"| node_milvus
node_kg -->|"queries graph"| node_neo4j
node_middleware -->|"accesses business data"| node_pg
node_middleware -->|"uses cache"| node_redis
node_llm -->|"reports metrics"| node_monitoring
node_llm -->|"checks semantic cache"| node_cache
node_deps -->|"provides sessions"| node_session
node_session -->|"reads settings"| node_config
node_llm -->|"reads settings"| node_config
node_clinician -.->|"uses API"| node_webapi
node_adminui -.->|"uses API"| node_webapi
node_graphui -->|"loads graph data"| node_webapi
node_routes -.->|"serves analysis"| node_image
node_routes -.->|"serves speech"| node_speech
node_image -.->|"stores files"| node_objectstore
node_fastapi -->|"exports metrics"| node_monitoring
node_llm -->|"traces calls"| node_logging

click node_web "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/PatientPortal.tsx"
click node_clinician "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/DoctorDashboard.tsx"
click node_adminui "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/AdminPanel.tsx"
click node_graphui "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/KnowledgeGraph.tsx"
click node_chattypes "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/types/chat.ts"
click node_webapi "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/services/api.ts"
click node_auth "https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/services/auth.ts"
click node_fastapi "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/main.py"
click node_routes "https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/api/v1"
click node_deps "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/dependencies.py"
click node_orchestrator "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/agents/orchestrator.py"
click node_agentbase "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/agents/base.py"
click node_specialists "https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/agents"
click node_ragtool "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/agents/tools/rag_tool.py"
click node_rag "https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/knowledge/rag"
click node_kg "https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/knowledge/graph"
click node_ml "https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/knowledge/ml"
click node_llm "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/llm_service.py"
click node_objectstore "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/object_storage.py"
click node_middleware "https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/api/middleware"
click node_monitoring "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/infrastructure/monitoring.py"
click node_cache "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/cache_service.py"
click node_session "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/database/session.py"
click node_logging "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/common/tracing.py"
click node_config "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/config.py"
click node_image "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/api/v1/image_analysis.py"
click node_speech "https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/asr_service.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,node_clinician,node_adminui,node_graphui,node_chattypes,node_webapi,node_auth toneBlue
class node_fastapi,node_routes,node_deps,node_orchestrator,node_image,node_speech toneAmber
class node_agentbase,node_specialists,node_ragtool,node_rag,node_kg,node_ml,node_llm toneMint
class node_pg,node_redis,node_milvus,node_neo4j,node_objectstore,node_middleware,node_monitoring,node_cache,node_session,node_logging,node_config toneRose
class node_patient toneIndigo
```

## Components

### User Experience

- [Patient Portal](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/PatientPortal.tsx): `frontend/src/pages/PatientPortal.tsx`
- [Doctor Dashboard](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/DoctorDashboard.tsx): `frontend/src/pages/DoctorDashboard.tsx`
- [Admin Workspace](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/AdminPanel.tsx): `frontend/src/pages/AdminPanel.tsx`
- [Graph Explorer](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/pages/KnowledgeGraph.tsx): `frontend/src/pages/KnowledgeGraph.tsx`
- [Chat Contracts](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/types/chat.ts): `frontend/src/types/chat.ts`
- [API Client](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [Authentication](https://github.com/zgsddzwj/intelligent_consultation/blob/main/frontend/src/services/auth.ts): `frontend/src/services/auth.ts`

### API and Orchestration

- [FastAPI Entry](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/main.py): `backend/app/main.py`
- [API Routes](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/api/v1): `backend/app/api/v1`
- [Service Factory](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/dependencies.py): `backend/app/dependencies.py`
- [Agent Orchestrator](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/agents/orchestrator.py): `backend/app/agents/orchestrator.py`
- [Image Analysis](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/api/v1/image_analysis.py): `backend/app/api/v1/image_analysis.py`
- [Speech Services](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/asr_service.py): `backend/app/services/asr_service.py`

### Medical Intelligence

- [Agent Runtime](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/agents/base.py): `backend/app/agents/base.py`
- [Specialist Agents](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/agents): `backend/app/agents`
- [RAG Tool](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/agents/tools/rag_tool.py): `backend/app/agents/tools/rag_tool.py`
- [Hybrid RAG](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/knowledge/rag): `backend/app/knowledge/rag`
- [Medical Graph](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/knowledge/graph): `backend/app/knowledge/graph`
- [ML Knowledge](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/knowledge/ml): `backend/app/knowledge/ml`
- [LLM Service](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/llm_service.py): `backend/app/services/llm_service.py`

### Data and Operations

- **PostgreSQL**
- **Redis**
- **Milvus**
- **Neo4j**
- [Object Storage](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/object_storage.py): `backend/app/services/object_storage.py`
- [API Middleware](https://github.com/zgsddzwj/intelligent_consultation/tree/main/backend/app/api/middleware): `backend/app/api/middleware`
- [Monitoring](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/infrastructure/monitoring.py): `backend/app/infrastructure/monitoring.py`
- [Cache Service](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/services/cache_service.py): `backend/app/services/cache_service.py`
- [Database Session](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [Logging and Tracing](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/common/tracing.py): `backend/app/common/tracing.py`
- [Configuration](https://github.com/zgsddzwj/intelligent_consultation/blob/main/backend/app/config.py): `backend/app/config.py`

### Other components

- **Patient**

## Connections

- Patient → Patient Portal: uses
- Patient Portal → API Client: submits consultation (evidence: `frontend/src/pages/PatientPortal.tsx`)
- Patient Portal → Chat Contracts: uses contracts (evidence: `frontend/src/pages/PatientPortal.tsx`)
- API Client → FastAPI Entry: calls API
- API Client → Authentication: clears tokens (evidence: `frontend/src/services/api.ts`)
- Authentication → API Client: posts login (evidence: `frontend/src/services/auth.ts`)
- FastAPI Entry → API Middleware: applies (evidence: `backend/app/main.py`)
- FastAPI Entry → API Routes: routes requests (evidence: `backend/app/main.py`)
- API Routes → Agent Orchestrator: dispatches consultations
- FastAPI Entry → Service Factory: initializes services (evidence: `backend/app/main.py`)
- Service Factory → Agent Orchestrator: provides (evidence: `backend/app/dependencies.py`)
- Agent Orchestrator → Specialist Agents: dispatches agents
- Specialist Agents → Agent Runtime: inherit runtime (evidence: `backend/app/agents/customer_service_agent.py`)
- Specialist Agents → RAG Tool: uses retrieval (evidence: `backend/app/agents/health_manager_agent.py`)
- RAG Tool → Hybrid RAG: retrieves context (evidence: `backend/app/agents/tools/rag_tool.py`)
- Specialist Agents → Medical Graph: queries diseases (evidence: `backend/app/agents/health_manager_agent.py`)
- Specialist Agents → ML Knowledge: recognizes entities (evidence: `backend/app/agents/health_manager_agent.py`)
- Specialist Agents → LLM Service: generates responses (evidence: `backend/app/agents/base.py`)
- Agent Runtime → LLM Service: uses service (evidence: `backend/app/agents/base.py`)
- Agent Runtime → Logging and Tracing: uses tracing (evidence: `backend/app/agents/base.py`)
- Hybrid RAG → Milvus: searches vectors
- Medical Graph → Neo4j: queries graph
- API Middleware → PostgreSQL: accesses business data
- API Middleware → Redis: uses cache
- LLM Service → Monitoring: reports metrics (evidence: `backend/app/services/llm_service.py`)
- LLM Service → Cache Service: checks semantic cache (evidence: `backend/app/services/llm_service.py`)
- Service Factory → Database Session: provides sessions (evidence: `backend/app/dependencies.py`)
- Database Session → Configuration: reads settings (evidence: `backend/app/database/session.py`)
- LLM Service → Configuration: reads settings (evidence: `backend/app/services/llm_service.py`)
- Doctor Dashboard → API Client: uses API
- Admin Workspace → API Client: uses API
- Graph Explorer → API Client: loads graph data (evidence: `frontend/src/pages/KnowledgeGraph.tsx`)
- API Routes → Image Analysis: serves analysis
- API Routes → Speech Services: serves speech
- Image Analysis → Object Storage: stores files
- FastAPI Entry → Monitoring: exports metrics (evidence: `backend/app/main.py`)
- LLM Service → Logging and Tracing: traces calls (evidence: `backend/app/services/llm_service.py`)
