sanjeevani-api / docs /PROJECT_AUDIT.md
Sivaneshakumar's picture
V1
151ec26
|
Raw History Blame Contribute Delete
9.75 kB
# SanjeevaniAI β€” Comprehensive Project Audit
**Audit Date:** August 18, 2026
**Auditor:** Lead Software Architect & ML/DevOps Engineer
**Project Path:** `D:\SanjeevaniAI`
**Repository State:** Initialized with pretrained ML models and clinical datasets; core application layers (Frontend, FastAPI Backend, Database, Auth, APIs) require development.
---
## 1. Executive Summary
SanjeevaniAI is an AI-powered healthcare intelligence and decision-support platform designed to assist clinicians and patients with biomedical named entity recognition (NER), medical document analysis, clinical summarization, health profiling, and interactive AI consultation.
An in-depth audit of `D:\SanjeevaniAI` reveals high-value pretrained machine learning assetsβ€”most notably a locally verified `tner/roberta-large-bc5cdr` biomedical NER model and extensive clinical/pharmacological datasetsβ€”alongside an empty application scaffold (`app/`, `clinical_engine/`, `rag/`, `evaluation/`).
This document details the existing state, inventory of models and datasets, technical debt, and provides an actionable blueprint for constructing a production-grade, HIPAA/privacy-conscious, modular healthcare system.
---
## 2. Directory Structure & Asset Inventory
```
D:\SanjeevaniAI\
β”œβ”€β”€ .venv/ # Python 3.11.9 Virtual Environment with PyTorch & Transformers
β”œβ”€β”€ checkpoints/ # TrOCR training checkpoints (epoch 1-3)
β”œβ”€β”€ datasets/ # Rich clinical and NLP datasets
β”‚ β”œβ”€β”€ clinical/
β”‚ β”‚ β”œβ”€β”€ ddi/ # Drug-Drug Interaction dataset (CSV)
β”‚ β”‚ β”œβ”€β”€ ddi_severity/ # DDI Database with severity ratings (JSON)
β”‚ β”‚ β”œβ”€β”€ medicines_250k/ # 250,000+ Medicine dataset (CSV)
β”‚ β”‚ └── mid/ # Medical Information Database & Therapeutic class counts (XLSX)
β”‚ β”œβ”€β”€ intent/ # CLINC150 Intent Classification data
β”‚ β”œβ”€β”€ ner/
β”‚ β”‚ └── bc5cdr/ # BC5CDR BioCreative V CDR Corpus data & loader
β”‚ β”œβ”€β”€ ocr/ # Prescription & medical text OCR samples
β”‚ β”œβ”€β”€ speech/ # Audio speech samples for medical transcription
β”‚ └── translation/ # Parallel translation benchmarks
β”œβ”€β”€ models/ # Pretrained & fine-tuned model store
β”‚ β”œβ”€β”€ bc5cdr-ner/ # ⭐ Verified Local RoBERTa-large BC5CDR NER Model
β”‚ β”‚ β”œβ”€β”€ config.json # RobertaForTokenClassification (Chemical & Disease tags)
β”‚ β”‚ β”œβ”€β”€ pytorch_model.bin # Pretrained PyTorch weights (~1.4 GB)
β”‚ β”‚ β”œβ”€β”€ merges.txt, vocab.json # BPE Tokenizer assets
β”‚ β”‚ β”œβ”€β”€ tokenizer_config.json
β”‚ β”‚ └── eval/ # Metric files (F1: 88.4%, Chemical F1: 92.6%, Disease F1: 83.4%)
β”‚ β”œβ”€β”€ gguf/ # Quantized LLM weights store
β”‚ β”œβ”€β”€ pretrained/ # Base Hugging Face model repositories
β”‚ β”‚ β”œβ”€β”€ biomedbert/ # Microsoft BiomedNLP-BiomedBERT-base-uncased
β”‚ β”‚ β”œβ”€β”€ indictrans_en_indic/ # IndicTrans2 English to Indic translation
β”‚ β”‚ β”œβ”€β”€ indictrans_indic_indic/# IndicTrans2 Indic to Indic translation
β”‚ β”‚ β”œβ”€β”€ intent/ # DistilBERT for intent classification
β”‚ β”‚ β”œβ”€β”€ sapbert/ # SapBERT biomedical entity representation
β”‚ β”‚ β”œβ”€β”€ trocr/ # Microsoft TrOCR base printed
β”‚ β”‚ └── whisper/ # OpenAI Whisper base speech-to-text
β”‚ └── trained/ # Custom fine-tuned weights output directory
β”œβ”€β”€ app/ # [EMPTY] Target directory for FastAPI modular backend
β”œβ”€β”€ clinical_engine/ # [EMPTY] Clinical decision support engine
β”œβ”€β”€ evaluation/ # [EMPTY] ML evaluation scripts
β”œβ”€β”€ rag/ # [EMPTY] Retrieval-Augmented Generation subsystem
β”œβ”€β”€ scripts/ # Maintenance & training utilities
β”‚ β”œβ”€β”€ download_models.py # Hugging Face snapshot downloader
β”‚ β”œβ”€β”€ prepare_mobile_ocr.py # Mobile OCR preprocessing pipeline
β”‚ β”œβ”€β”€ test_models.py # Integrity checker for model weights
β”‚ β”œβ”€β”€ test_trocr_load.py # TrOCR loading script
β”‚ └── train_trocr.py # TrOCR fine-tuning workflow
β”œβ”€β”€ training/ # Training scripts
β”‚ β”œβ”€β”€ intent/ # Intent classification fine-tuning
β”‚ β”œβ”€β”€ ner/ # Token classification fine-tuning (train_ner.py)
β”‚ └── ocr/ # TrOCR training and evaluation
β”œβ”€β”€ README.md # [EMPTY - 0 bytes] Needs comprehensive documentation
└── requirements.txt # [BASIC] Missing FastAPI, SQLAlchemy, Alembic, Pydantic, etc.
```
---
## 3. Existing Machine Learning Models Verification
### 3.1 Local Biomedical NER Model (`models/bc5cdr-ner`)
* **Architecture:** `RobertaForTokenClassification` fine-tuned on BioCreative V CDR (BC5CDR).
* **Entity Classes:**
* `0: O` (Outside)
* `1: B-Chemical` (Beginning of Chemical/Drug name)
* `2: B-Disease` (Beginning of Disease/Condition name)
* `3: I-Disease` (Inside of Disease name)
* `4: I-Chemical` (Inside of Chemical name)
* **Performance:** Overall F1: `88.41%` (Chemical F1: `92.57%`, Disease F1: `83.38%`).
* **Live Inference Verification:**
* Successfully loaded onto CUDA (`cuda:0`) via HuggingFace `pipeline("ner")`.
* Sample: *"The patient was prescribed metformin for type 2 diabetes mellitus."*
* Result: `Chemical: metformin (confidence 0.9998)`, `Disease: type 2 diabetes mellitus (confidence 0.9985)`.
* **Deployment Consideration:** The model weights are ~1.4GB. The FastAPI application must load the model once as a singleton during application startup (`lifespan` handler) to prevent latency penalties on individual requests.
---
## 4. Technology Stack & Environment Assessment
| Subsystem | Existing State | Target Production Architecture |
| :--- | :--- | :--- |
| **Python Environment** | Python 3.11.9 with PyTorch 2.8.0 (CUDA 12.9), Transformers 4.57.1 | Extend `.venv` with FastAPI, Pydantic v2, SQLAlchemy 2.0, Alembic, python-jose, passlib, pypdf, httpx |
| **Node.js Environment** | Node.js v22.17.0, npm 10.9.2 | Next.js 14+ (App Router), TypeScript, Tailwind CSS, Lucide Icons, Radix/shadcn UI, TanStack Query |
| **Backend Framework** | None (Empty `app/` folder) | FastAPI with modular layered architecture (`api/v1`, `services`, `repositories`, `models`, `ml`) |
| **Database** | None | PostgreSQL (production/docker) & SQLite (aiosqlite dev fallback) via SQLAlchemy async engine + Alembic |
| **Authentication** | None | Secure JWT auth with refresh tokens, Argon2/Bcrypt password hashing, Role-Based Access Control (RBAC) |
| **Document Processing** | None | Multi-format extraction pipeline (PDF via `pypdf`/`pdfplumber`, TXT, DOCX), sanitization, entity linking |
| **AI LLM Provider** | None | Abstract `LLMProvider` with `GeminiProvider` (Google GenAI), `OpenAIProvider`, and `MockLLMProvider` |
| **Task Queue / Cache** | None | Redis with Celery / FastAPI async background tasks fallback |
| **Containerization** | None | Multi-stage `Dockerfile` (Backend & Frontend) + `docker-compose.yml` (App, DB, Redis, Worker) |
---
## 5. Identified Gaps & Technical Problems
1. **Missing Backend Application Layer:** The `app/` directory is completely empty. There are no API routers, service layers, Pydantic schemas, or data models.
2. **Missing Frontend Client:** No Next.js or React frontend exists. All UI interactions, dashboards, and visualizations must be built from scratch.
3. **Missing Database Schemas & Migrations:** No relational tables or Alembic migration environments are established.
4. **Missing Authentication & Authorization:** No user identity, session management, or RBAC controls exist.
5. **No Medical Safety Guards:** AI responses need guardrails distinguishing extracted facts from AI considerations, with clear disclaimers that SanjeevaniAI is not an autonomous diagnostic device.
6. **No API Documentation & Health Probes:** Missing OpenAPI schemas, `/health`, and `/ready` endpoints.
7. **No Automated Test Suites:** Missing unit, integration, and ML inference validation tests.
---
## 6. Recommended Migration & Architecture Plan
1. **Preserve High-Value Data & Models:** Retain all files under `models/` (especially `models/bc5cdr-ner`) and `datasets/`.
2. **Build Modular FastAPI Backend:** Implement clean separation of concerns:
`Router -> Schema Validation -> Service Layer -> Repository / ML Engine -> Database`.
3. **Build Modern Next.js TypeScript Frontend:** Modern healthcare SaaS UI with responsive sidebar, dark/light clinical theme, accessible components, and interactive NER visualizer.
4. **Implement Local ML Adapter (`MLManager`):** Encapsulate `models/bc5cdr-ner` with cached singleton lifecycle, warm-up routines, and fallback error handling.
5. **Implement Resilient Document Pipeline:** Secure upload handler with MIME validation, SHA256 hashing, structured entity extraction, and clinical summarization.
6. **Implement Multi-Provider LLM Engine:** Pluggable AI Assistant supporting Google Gemini with fallback to MockLLM for offline development.
7. **Provide Complete DevOps & Testing Tooling:** Alembic migrations, Pytest suite, Jest/React testing, Docker Compose configurations, and comprehensive documentation.