Spaces:
Running
Running
RagBot API - Architecture Diagrams
System Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RagBot API Server β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ ββββββββββββββββββββββββββββ β
β β Cloud LLM API ββββββββββββββββ€ FastAPI Server β β
β β (Groq/Gemini) β LLM Calls β Port: 8000 β β
β β β β β β
β β Models: β β Endpoints: β β
β β - LLaMA 3.3-70Bβ β - /api/v1/health β β
β β - Gemini Flash β β - /api/v1/biomarkers β β
β β (or Ollama) β β - /api/v1/analyze/* β β
β βββββββββββββββββββ βββββββββββββ¬βββββββββββββββ β
β β β
β βββββββββββββΌβββββββββββββββ β
β β RagBot Core System β β
β β (Imported Package) β β
β β β β
β β - 6 Specialist Agents β β
β β - LangGraph Workflow β β
β β - FAISS Vector Store β β
β β - 2,609 medical chunks β β
β ββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β²
β
HTTP Requests (JSON)
β
β
βββββββββββββ΄βββββββββββββ
β Your Backend Server β
β (Node.js/Python/etc) β
β Port: 3000 β
β β
β - Receives frontend β
β requests β
β - Calls RagBot API β
β - Returns results β
βββββββββββββ¬βββββββββββββ
β
β
βββββββββββββΌβββββββββββββ
β Your Frontend β
β (React/Vue/etc) β
β β
β - User inputs data β
β - Displays results β
β - Shows analysis β
ββββββββββββββββββββββββββ
π‘ Request Flow
Natural Language Analysis Flow
User Types:
"My glucose is 185 and HbA1c is 8.2"
β
βΌ
ββββββββββββββββββββββ
β Frontend (React) β
β User Interface β
βββββββββββ¬βββββββββββ
β POST /api/analyze
βΌ
ββββββββββββββββββββββ
β Your Backend β
β (Express/Flask) β
βββββββββββ¬βββββββββββ
β POST /api/v1/analyze/natural
βΌ
βββββββββββββββββββββββββββββββββββββββ
β RagBot API (FastAPI) β
β β
β 1. Receive request β
β {"message": "glucose 185..."} β
β β
β 2. Extract biomarkers β
β ββββββββββββββββββββ β
β β Extraction β β
β β Service β β
β β (LLM: llama3.1) β β
β ββββββββββ¬ββββββββββ β
β βΌ β
β {"Glucose": 185, "HbA1c": 8.2} β
β β
β 3. Predict disease β
β ββββββββββββββββββββ β
β β Rule-based β β
β β Predictor β β
β ββββββββββ¬ββββββββββ β
β βΌ β
β {"disease": "Diabetes", ...} β
β β
β 4. Run RAG Workflow β
β ββββββββββββββββββββ β
β β RagBot Service β β
β β (6 agents) β β
β ββββββββββ¬ββββββββββ β
β βΌ β
β Full analysis response β
β β
β 5. Format response β
β - Biomarker flags β
β - Safety alerts β
β - Recommendations β
β - Disease explanation β
β - Conversational summary β
β β
βββββββββββ¬ββββββββββββββββββββββββββββ
β JSON Response
βΌ
ββββββββββββββββββββββ
β Your Backend β
β Processes data β
βββββββββββ¬βββββββββββ
β JSON Response
βΌ
ββββββββββββββββββββββ
β Frontend β
β Displays results β
ββββββββββββββββββββββ
π Component Interaction
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Application β
β (app/main.py) β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββ β
β β Route Handlers β β
β β β β
β β /health /biomarkers /analyze/* β β
β β β β β β β
β ββββββΌββββββββββββββββΌβββββββββββββββΌββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββ βββββββββββ ββββββββββββββββ β
β β Health β βBiomarkerβ β Analyze β β
β β Route β β Route β β Route β β
β βββββββββββ βββββββββββ ββββββββ¬ββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββ β
β β Services Layer β β
β β β β
β β βββββββββββββββββ β β
β β β Extraction β β β
β β β Service β β β
β β βββββββββ¬ββββββββ β β
β β β β β
β β βββββββββΌββββββββ β β
β β β RagBot β β β
β β β Service β β β
β β βββββββββ¬ββββββββ β β
β ββββββββββββΌββββββββββ β
β β β
βββββββββββββββββββββββββββββββββββββββΌββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β RagBot Core System β
β (src/workflow.py) β
β β
β ββββββββββββββββββββ β
β β 6 Agent Workflow β β
β β (LangGraph) β β
β ββββββββββββββββββββ β
β β
β ββββββββββββββββββββ β
β β Vector Store β β
β β (FAISS) β β
β ββββββββββββββββββββ β
ββββββββββββββββββββββββββ
π Data Flow
Request β Response Journey
1. INPUT (from user)
βββββββββββββββββββββββββββββββββββ
β "My glucose is 185 and HbA1c β
β is 8.2, I'm 52 years old" β
βββββββββββββββββββββββββββββββββββ
β
βΌ
2. EXTRACTION (LLM Processing)
βββββββββββββββββββββββββββββββββββ
β Biomarkers: β
β - Glucose: 185.0 β
β - HbA1c: 8.2 β
β Context: β
β - age: 52 β
βββββββββββββββββββββββββββββββββββ
β
βΌ
3. PREDICTION (Rule-based)
βββββββββββββββββββββββββββββββββββ
β Disease: Diabetes β
β Confidence: 0.87 (87%) β
β Probabilities: β
β - Diabetes: 87% β
β - Heart Disease: 8% β
β - Others: 5% β
βββββββββββββββββββββββββββββββββββ
β
βΌ
4. WORKFLOW (6 Agents Execute)
βββββββββββββββββββββββββββββββββββ
β Agent 1: Biomarker Analyzer β
β β Validates 2 biomarkers β
β β Flags: 2 out of range β
β β Alerts: 2 critical β
βββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββ
β Agent 2: Disease Explainer (RAG)β
β β Retrieved 5 medical docs β
β β Citations: 5 sources β
β β Pathophysiology explained β
βββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββ
β Agent 3: Biomarker Linker (RAG) β
β β Linked 2 key drivers β
β β Evidence from literature β
βββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββ
β Agent 4: Guidelines (RAG) β
β β Retrieved 3 guidelines β
β β Recommendations: 5 actions β
βββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββ
β Agent 5: Confidence Assessor β
β β Reliability: MODERATE β
β β Evidence: STRONG β
β β Limitations: 2 noted β
βββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββ
β Agent 6: Response Synthesizer β
β β Compiled all findings β
β β Structured output β
β β Conversational summary β
βββββββββββββββββββββββββββββββββββ
β
βΌ
5. OUTPUT (to user)
βββββββββββββββββββββββββββββββββββ
β Full JSON Response: β
β β
β - prediction β
β - biomarker_flags β
β - safety_alerts β
β - key_drivers β
β - disease_explanation β
β - recommendations β
β - confidence_assessment β
β - agent_outputs β
β - conversational_summary β
β β
β Processing time: 3.5 seconds β
βββββββββββββββββββββββββββββββββββ
π― API Endpoint Map
RagBot API Root: http://localhost:8000
β
βββ / GET API info
β
βββ /docs GET Swagger UI
β
βββ /redoc GET ReDoc
β
βββ /api/v1/
β
βββ /health GET System status
β Returns: {
β status: "healthy",
β ollama_status: "connected",
β vector_store_loaded: true
β }
β
βββ /biomarkers GET List all biomarkers
β Returns: {
β biomarkers: [...],
β total_count: 24
β }
β
βββ /analyze/
β
βββ /natural POST Natural language
β Input: {
β message: "glucose 185...",
β patient_context: {...}
β }
β Output: Full analysis
β
βββ /structured POST Direct biomarkers
β Input: {
β biomarkers: {...},
β patient_context: {...}
β }
β Output: Full analysis
β
βββ /example GET Demo case
Output: Full analysis
π Integration Points
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application Stack β
ββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Frontend (React/Vue/Angular) β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β User inputs: "glucose 185, HbA1c 8.2" β β
β β Button click: "Analyze" β β
β ββββββββββββββββ¬ββββββββββββββββββββββββββββ β
β β HTTP POST β
β βΌ β
β Backend (Node.js/Python/Java) β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β Endpoint: POST /api/analyze β β
β β β β
β β Code: β β
β β const result = await fetch( β β
β β 'http://localhost:8000/api/v1/ β β
β β analyze/natural', β β
β β {body: {message: userInput}} β β
β β ); β β
β β β β
β β return result.data; β β
β ββββββββββββββββ¬ββββββββββββββββββββββββββββ β
β β HTTP POST β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β RagBot API (localhost:8000) ββββΌβ This is what we built!
β β β β
β β - Extracts biomarkers β β
β β - Runs analysis β β
β β - Returns JSON β β
β ββββββββββββββββ¬ββββββββββββββββββββββββββββ β
β β JSON Response β
β βΌ β
β Backend processes and returns to frontend β
β β β
β βΌ β
β Frontend displays results to user β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββ
πΎ File Structure
api/
β
βββ app/ # Application code
β βββ __init__.py
β βββ main.py # FastAPI app (entry point)
β β
β βββ models/ # Data schemas
β β βββ __init__.py
β β βββ schemas.py # Pydantic models
β β
β βββ routes/ # API endpoints
β β βββ __init__.py
β β βββ health.py # Health check
β β βββ biomarkers.py # List biomarkers
β β βββ analyze.py # Analysis endpoints
β β
β βββ services/ # Business logic
β βββ __init__.py
β βββ extraction.py # Natural language extraction
β βββ ragbot.py # Workflow orchestration
β
βββ .env # Configuration
βββ .env.example # Template
βββ .gitignore # Git ignore rules
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container image
βββ docker-compose.yml # Deployment config
β
βββ Documentation/
βββ README.md # Complete guide
βββ GETTING_STARTED.md # Quick start
βββ QUICK_REFERENCE.md # Cheat sheet
βββ ARCHITECTURE.md # This file
Created: November 23, 2025
Purpose: Visual guide to RagBot API architecture
For: Understanding system design and integration points