How inkithai/medimind works
1. Purpose and entry points
MediMind is an anonymous medical-document intelligence workspace. It accepts PDFs/images, extracts structured clinical records, persists a patient snapshot, derives safety/lab insights, and supports cited retrieval Q&A.
Backend entry point: backend/api.py FastAPI app under /api/v1/. Frontend entry: frontend/src/main.tsx, routing/UI rooted in frontend/src/App.tsx.
2. Anonymous workspace and access boundary
A browser provisions an anonymous UUID/JWT session, stores credentials locally, and sends both bearer token and user ID on subsequent requests. The API validates identity and scopes every record, object path, and vector collection by user.
Core paths:
• backend/auth.py
• backend/api.py
• frontend/src/context/AuthContext.tsx
Public API surface is health/session creation; document, history, Q&A, conversation, and job endpoints are authenticated.
3. Upload and asynchronous processing orchestration
POST /documents accepts multipart files and either processes synchronously or creates an asynchronous parent job. Jobs expose independent per-file states plus batch finalization; a bounded shared worker pool controls provider load and handles partial failures without discarding successful files.
Core paths:
• backend/api.py
• backend/jobs.py
• frontend/src/pages/UploadPage.tsx
The frontend polls jobs and presents extraction progress separately from record finalization (timeline, safety, search indexing).
4. Extraction, validation, and clinical record assembly
The extraction pipeline reads PDF/image content and calls an OpenAI-compatible LLM provider for structured JSON. It supports Groq, Gemini, or generic providers, including multimodal vision models and fallback parsing/retry behavior. Extracted documents are filtered for medical relevance, merged with prior uploads, grouped into a timeline/snapshot, and checked for clinical conflicts.
Core paths:
• backend/medical_extractor.py
• backend/document_filter.py
• backend/docs/pipeline.md
Primary derived outputs are visits, medications, labs, allergies, safety cross-checks, and a structured patient timeline.
5. Persistence and file-storage split
Original files are uploaded to Cloudinary under a user-scoped mediscan/<user>/ path. Structured documents and patient snapshots are stored in Supabase Postgres. The schema enables RLS and is intended for service-role backend access; raw file bytes and LLM tokens are not stored in the database.
Core paths:
• backend/storage.py
• backend/db.py
• backend/supabase_schema.sql
Material external services: Cloudinary, Supabase, and the selected LLM provider. Runtime secrets and deployment configuration are defined through backend environment variables.
6. Analytics and retrieval boundary
Lab trends are deterministic Python computations over extracted lab values, dates, ranges, and crossings. Retrieval chunks structured timeline content, embeds it using OpenAI embeddings when available or local ONNX fallback, and indexes/searches through a pluggable vector-store layer.
Core paths:
• backend/lab_trends.py
• backend/retrieval.py
• backend/vector_store.py
Vector storage is either local Chroma (requires persistent volume) or Supabase chunks (brute-force cosine; deployment-friendly). Q&A self-heals by rebuilding a missing index from persisted documents.
7. Question answering, conversations, and workspace UI
Single-shot Q&A retrieves patient-scoped chunks and returns grounded answers, confidence, source citations, and professional-consultation guidance. In-memory conversations retain turns, rewrite follow-ups into standalone retrieval queries, and summarize old context; they are lost on process restart unless externally persisted.
Core paths:
• backend/conversation.py
• frontend/src/pages/QAPage.tsx
• frontend/src/pages/SessionPage.tsx
The React/Vite frontend renders the patient workspace: dashboard, document viewer, timeline, medicines, lab trends, safety, Q&A, and conversations. It communicates through the centralized client layer at frontend/src/api/client.ts.
8. Deployment runtime
Backend runs on Python 3.10+ with Uvicorn/FastAPI and is packaged for Railway via backend/Procfile and backend/Dockerfile. Frontend is React/TypeScript/Vite, with production hosting configuration in frontend/vercel.json. For Railway, Supabase vectors avoid a persistent disk; Chroma requires a mounted volume.
Core paths:
• backend/Procfile
• backend/Dockerfile
• frontend/vite.config.ts
Main entry points: api.py REST API · pipeline.md Patient record assembly · client.ts API client · jobs.py Job orchestration
Components 19
React workspace
- Workspace UI · Dashboard, records, safety, labs, Q&A, and conversations.
frontend/src/App.tsx - Anonymous session · Provisions and locally retains UUID/JWT credentials.
frontend/src/context/AuthContext.tsx - API client · Sends authenticated workspace requests.
frontend/src/api/client.ts - Upload & job progress · Polls per-file extraction and finalization states.
frontend/src/pages/UploadPage.tsx - Cited Q&A UI
frontend/src/pages/QAPage.tsx
FastAPI backend
- REST API · Public health/session endpoints; all workspace data endpoints are authenticated.
backend/api.py - Identity scoping · Validates JWT/user identity and scopes records, objects, and vectors.
backend/auth.py - Job orchestration · Runs bounded per-file processing and preserves partial successes.
backend/jobs.py - Clinical extraction · Parses PDF/images into structured clinical JSON with retries and fallbacks.
backend/medical_extractor.py - Medical relevance filter
backend/document_filter.py - Patient record assembly · Merges uploads into timeline, snapshot, safety checks, visits, medications, labs, and allergies.
backend/docs/pipeline.md - Lab trend analysis · Computes trends, ranges, and threshold crossings.
backend/lab_trends.py - Grounded Q&A · Rewrites follow-ups, retrieves citations, and keeps in-memory conversation context.
backend/conversation.py
Storage & retrieval
- Clinical records & snapshots · RLS-backed structured persistence accessed by the service-role backend.
backend/db.py - Original documents · Stored under user-scoped mediscan paths.
backend/storage.py - Retrieval indexing · Chunks timeline content and rebuilds missing indexes from persisted documents.
backend/retrieval.py - Patient vector index · Local Chroma or Supabase chunks, scoped per user.
backend/vector_store.py
External services
- LLM provider · Provides structured extraction and multimodal vision when configured.
- Embedding provider
Connections 21
- Workspace UI → Anonymous session: uses session
- Workspace UI → API client: workspace requests
- Upload & job progress → API client: upload and poll jobs
- Cited Q&A UI → API client: ask questions
- API client → REST API: JWT + user ID
- REST API → Identity scoping: authenticate requests
- REST API → Job orchestration: create/process document jobs
- Job orchestration → Original documents: store originals
- Job orchestration → Clinical extraction: process each file
- Clinical extraction → LLM provider: structured extraction
- Clinical extraction → Medical relevance filter: extracted document
- Medical relevance filter → Patient record assembly: medical documents
- Patient record assembly → Clinical records & snapshots: persist documents and snapshot
- Patient record assembly → Lab trend analysis: lab values and dates
- Patient record assembly → Retrieval indexing: timeline content
- Lab trend analysis → Clinical records & snapshots: derived insights
- Retrieval indexing → Embedding provider: embed chunks
- Retrieval indexing → Patient vector index: index patient chunks
- REST API → Grounded Q&A: Q&A and conversation endpoints
- Grounded Q&A → Patient vector index: patient-scoped retrieval
- Grounded Q&A → Clinical records & snapshots: rebuild from persisted records