# warma10032/cyber-doctor architecture

> Architecture diagram of the GitHub repository warma10032/cyber-doctor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/warma10032/cyber-doctor
- Repository: https://github.com/warma10032/cyber-doctor

## Overview

##### Project Type and Purpose
- This is a full-stack, multi-modal AI assistant (“cyber-doctor”) built in Python, using Gradio for UI.
- It integrates text, audio, image, document (PPT/Word) processing, RAG (Retrieval-Augmented Generation), knowledge-graph (Neo4j) queries, web search crawlers, and LLM API clients to offer medical-domain Q&A, diagnosis support, and content generation.

##### File Structure Analysis
- Top level:
- app.py – Gradio UI & orchestrator
- env.py, config/ – environment & YAML config
- client/ – LLM client factory & implementations (OpenAI, zhipuAI, Ollama, custom)
- Internet/, rag/, qa/, audio/, ppt_docx/ – feature modules (web search, RAG chain, Q&A pipeline, audio I/O, PPT/Word generation)
- model/ – RAG vector store & service implementations for Internet, KG, file-based retrieval
- kg/ – Neo4j graph access
- resource/ – static assets (images)
- Patterns:
- Orchestrator (app.py) ties UI inputs to module-specific “chains.”
- Each feature module implements a chain → calls into model/service → uses client to invoke LLM or external service.
- Services are layered: feature_chains → model_service → client → external APIs/datastores.

##### Key README Insights
- Uses Gradio for front-end, LangChain-style chains for orchestration.
- Supports multiple modalities (text, image, audio, file).
- External dependencies: OpenAI/ZhipuAI/etc. APIs, Neo4j graph DB, web search via crawler, edge-tts/whisper for STT/TTS.

##### Main Components
a. Frontend (Gradio)
b. Orchestrator / API Layer (app.py)
c. Feature Modules (QA, RAG Chain, Internet Chain, Audio I/O, PPT/Word Generation)
d. Model & Service Layer (model/*, kg/Graph)
e. Client Layer (client factory & specific clients)
f. External Dependencies:
- LLM APIs (OpenAI, ZhipuAI, Ollama, custom)
- Neo4j (Knowledge Graph)
- Web (crawler)
- STT/TTS Services
g. Configuration (.env, config-web.yaml)

##### Relationships & Data Flow
- User Interaction → Gradio UI
- UI input → app.py selects feature chain based on input type
- Feature chain calls corresponding “service” in model/ or module/
- Service may:
- Query vector store (RAG) or Neo4j (KG)
- Invoke Internet crawler
- Extract/generate audio
- Generate PPT/Word content
- Services call clientfactory → instantiate LLM client → call external LLM API
- External API returns text or embeddings → propagate back up
- app.py aggregates responses → UI output (text, audio, file)

##### Architectural Patterns & Principles
- Chain-of-Responsibility (LangChain style) for modular pipelines
- Factory Pattern for LLM client instantiation
- Layered Architecture: UI → Orchestrator → Feature Modules → Services → Clients → External
- Separation of concerns: each module handles a single modality or retrieval method
- Configurable via .env and config-web.yaml for extensibility

## Diagram (Mermaid)

```mermaid
graph TB
    %% UI & Orchestrator Layer
    subgraph "UI & Orchestrator"
        UI["Gradio UI"]:::ui
        Orchestrator["Orchestrator (app.py)"]:::ui
    end
    click Orchestrator "https://github.com/warma10032/cyber-doctor/blob/main/app.py"

    Config["Config (.env, YAML)"]:::ui
    click Config "https://github.com/warma10032/cyber-doctor/blob/main/env.py"
    click Config "https://github.com/warma10032/cyber-doctor/blob/main/config/config-web.yaml"
    click Config "https://github.com/warma10032/cyber-doctor/blob/main/config/config.py"

    UI -->|"user input"| Orchestrator
    Config --> Orchestrator

    %% Feature Modules Layer
    subgraph "Feature Modules" 
        QAChain["Q&A Chain"]:::feature
        RAGChain["RAG Chain"]:::feature
        InternetChain["Internet Chain"]:::feature
        AudioModule["Audio I/O Module"]:::feature
        PPTModule["PPT/Word Module"]:::feature
    end

    click InternetChain "https://github.com/warma10032/cyber-doctor/blob/main/Internet/Internet_chain.py"
    click RAGChain "https://github.com/warma10032/cyber-doctor/blob/main/rag/rag_chain.py"
    click QAChain "https://github.com/warma10032/cyber-doctor/blob/main/qa/answer.py"
    click AudioModule "https://github.com/warma10032/cyber-doctor/blob/main/audio/audio_extract.py"
    click PPTModule "https://github.com/warma10032/cyber-doctor/blob/main/ppt_docx/docx_content.py"

    Orchestrator -->|"invoke QA"| QAChain
    Orchestrator -->|"invoke RAG"| RAGChain
    Orchestrator -->|"invoke Internet"| InternetChain
    Orchestrator -->|"invoke Audio"| AudioModule
    Orchestrator -->|"invoke PPT/Doc"| PPTModule

    %% Model & Service Layer
    subgraph "Model & Service Layer"
        ModelBase["Common Base (model_base.py)"]:::model
        InternetService["Internet Service"]:::model
        KGService["KG Service"]:::model
        RAGService["RAG Service"]:::model
    end

    click ModelBase "https://github.com/warma10032/cyber-doctor/blob/main/model/model_base.py"
    click InternetService "https://github.com/warma10032/cyber-doctor/blob/main/model/Internet/Internet_service.py"
    click KGService "https://github.com/warma10032/cyber-doctor/blob/main/model/KG/search_service.py"
    click RAGService "https://github.com/warma10032/cyber-doctor/blob/main/model/RAG/retrieve_service.py"

    QAChain -->|"Cypher query/text"| KGService
    RAGChain -->|"embeddings query"| RAGService
    InternetChain -->|"web request"| InternetService
    AudioModule -->|"audio stream"| AudioModule
    PPTModule -->|"content payload"| PPTModule

    %% Client Layer
    subgraph "Client Layer"
        ClientFactory["LLM ClientFactory"]:::external
        LLMBase["LLMClientBase"]:::external
        LLMGeneric["LLMClientGeneric"]:::external
        OurAPI["OurAPI Client"]:::external
        Zhipu["ZhipuAI Client"]:::external
    end

    click ClientFactory "https://github.com/warma10032/cyber-doctor/blob/main/client/clientfactory.py"
    click LLMBase "https://github.com/warma10032/cyber-doctor/blob/main/client/LLMclientbase.py"
    click LLMGeneric "https://github.com/warma10032/cyber-doctor/blob/main/client/LLMclientgeneric.py"
    click OurAPI "https://github.com/warma10032/cyber-doctor/blob/main/client/ourAPI/client.py"
    click Zhipu "https://github.com/warma10032/cyber-doctor/blob/main/client/zhipuAPI/client.py"

    InternetService -->|"calls client"| ClientFactory
    KGService -->|"calls client"| ClientFactory
    RAGService -->|"calls client"| ClientFactory

    ClientFactory --> LLMBase
    ClientFactory --> LLMGeneric
    ClientFactory --> OurAPI
    ClientFactory --> Zhipu

    %% Data Stores & External Services
    subgraph "Data Stores & External"
        Neo4j["Neo4j (KG)"]:::model
        VectorStore["Vector Store"]:::model
        Web["Web (Crawler)"]:::external
        STT_TTS["STT/TTS Services"]:::external
        LLM_API["External LLM APIs"]:::external
    end

    click Neo4j "https://github.com/warma10032/cyber-doctor/blob/main/kg/Graph.py"

    InternetService --> Web
    KGService --> Neo4j
    RAGService --> VectorStore
    AudioModule --> STT_TTS
    ClientFactory --> LLM_API

    %% Styles
    classDef ui fill:#e0f7e0,stroke:#333,stroke-width:1px
    classDef feature fill:#e0e7ff,stroke:#333,stroke-width:1px
    classDef model fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef external fill:#ffcccc,stroke:#333,stroke-width:1px
```
