MediQuery is a natural language to SQL engine for hospital analytics. Ask questions about hospital data in plain English — the app generates SQL using Groq LLM and returns results from a structured hospital database.
Live Demo: https://mediquery.vercel.app Backend API Docs: https://mediquery-api-uu2g.onrender.com/docs
User Question (plain English)
│
▼
FastAPI Backend (Render)
│
▼
LangChain SQLDatabaseChain
│
├── Groq LLM generates SQL query
│
▼
SQLite Hospital Database
│
▼
Results returned as JSON
│
▼
Next.js Frontend renders table
| Layer | Tool |
|---|---|
| Frontend | Next.js + Tailwind CSS |
| Frontend Hosting | Vercel |
| Backend | FastAPI |
| Backend Hosting | Render |
| NL to SQL | LangChain SQLDatabaseChain |
| LLM | Groq (llama-3.1-8b-instant) |
| Database | SQLite |
| Containerisation | Docker |
Hospital data warehouse with 5 tables:
dim_patient — patient demographics (1,751 records)
dim_staff — staff records (262 members)
dim_dept — hospital departments (10 departments)
dim_bed — bed assignments
fact_treatment — treatment records (cost, LOS, rating, feedback)
"Show total treatment cost by department"
"How many patients are in each status category?"
"What is the average rating per department?"
"List top 5 patients by length of stay"
mediquery/
├── core/
│ └── chain.py ← LangChain NL-to-SQL chain + DB stats
├── api/
│ └── routes.py ← FastAPI route handlers
├── frontend/ ← Next.js app (deployed on Vercel)
│ ├── app/
│ │ ├── page.tsx ← main page
│ │ └── layout.tsx ← root layout
│ └── components/
├── main.py ← FastAPI entry point
├── hospital_warehouse.db ← SQLite hospital database
├── Dockerfile
├── requirements.txt
└── .env.example
- Python 3.11+
- Node.js 18+
- Groq API key → console.groq.com
git clone https://github.com/rohitsahayy/mediquery.git
cd mediquery
cp .env.example .env
# add GROQ_API_KEY to .env
pip install -r requirements.txt
uvicorn main:app --reload
# API running at http://localhost:8000
# Docs at http://localhost:8000/docscd frontend
npm install
echo "NEXT_PUBLIC_API_URL=http://localhost:8000" > .env.local
npm run dev
# UI running at http://localhost:3000docker build -t mediquery .
docker run -p 8000:8000 --env-file .env mediquery// Request
{ "question": "Show total treatment cost by department" }
// Response
{
"sql": "SELECT dd.Dept_Name, SUM(ft.Treatment_Cost) ...",
"columns": ["Dept_Name", "Total_Cost"],
"rows": [["Cardiology", 245000.0], ["Neurology", 198000.0]],
"row_count": 10
}{
"total_patients": 1751,
"departments": 10,
"staff": 262,
"treatment_records": 1751
}{
"examples": [
"Show total treatment cost by department",
"List top 5 patients by length of stay",
"How many patients are in each status category?",
"What is the average rating per department?"
]
}Full interactive docs: https://mediquery-api-uu2g.onrender.com/docs
Backend .env:
| Variable | Description |
|---|---|
GROQ_API_KEY |
Groq API key for LLM inference |
Frontend .env.local:
| Variable | Description |
|---|---|
NEXT_PUBLIC_API_URL |
Backend API base URL |
| Service | Platform | URL |
|---|---|---|
| Frontend | Vercel | https://mediquery.vercel.app |
| Backend | Render | https://mediquery-api-uu2g.onrender.com |
Auto-deploys on every push to main.
Note: Backend is on Render free tier — first request after inactivity may take 30–50 seconds to wake up.