Medsense AI (a.k.a. MedExplain) is a full-stack React + TypeScript application that helps ingest clinical reports (PDFs/images), extract readable text (OCR), and produce patient-friendly, structured summaries via an AI gateway. It is built with TanStack Start for SSR, Supabase for auth/storage, and serverless functions for AI integration.
Key Features ✨
- 🔍 OCR processing:
pdfjs-disttext-layer +tesseract.jsraster OCR fallback (src/lib/ocr.ts). - 🤖 Structured AI summaries:
supabase/functions/summarize-report/index.tsreturns typed JSON summaries. - 🔐 Supabase authentication and storage: client and server helpers in
src/integrations/supabase. - 🧩 Reusable UI: accessible components under
src/components/ui(buttons, forms, tables, dialogs). - 🗺️ Routing & SSR: TanStack Start + Router for route-driven SSR and server functions.
- 🛡️ Error capture & theming: centralized error capture and theme utilities in
src/lib.
- Quickstart
- Environment Variables
- Development
- Architecture
- Deployment
- Testing & Linting
- Troubleshooting
- Contributing
- License
Prerequisites
- Node.js 18+ (LTS recommended)
npm,pnpmoryarn- (Optional) Supabase project and CLI for deploying functions
Install dependencies:
npm install
# or
pnpm installCreate a local env file from the provided example and fill in your keys (do not commit .env):
copy .env.example .env
# Edit .env and add SUPABASE_URL, VITE_SUPABASE_PUBLISHABLE_KEY, AI_GATEWAY_URL, AI_API_KEY, etc.Start development server (client + SSR):
npm run devBuild and preview production bundle:
npm run build
npm run preview- Frontend entry: Vite + TanStack Start (see
vite.config.ts). - Server entry:
src/server.tsroutes to the TanStack Start server entry. - Routes:
src/routes/*— route files are file-based and support server loaders and functions. - OCR pipeline:
src/lib/ocr.tsusespdfjs-distfor PDFs andtesseract.jsfor image OCR. - Summarization: Frontend calls Supabase function
summarize-report, implemented insupabase/functions/summarize-report/index.ts.
Common dev tasks:
- Format code:
npm run format- Lint (fixable issues can be auto-fixed):
npm run lint -- --fixsrc/— application codecomponents/— UI primitives and design systemintegrations/— Supabase clients and middlewarelib/— helpers and utilities (OCR, auth context, theme, error capture)routes/— pages (file-based routing)
supabase/functions/— serverless functions (summarize-report)migrations/— SQL migrations for Supabase
Key workflows:
- Upload file -> store in Supabase storage
- Extract text via OCR helpers
- Invoke serverless summarization
- Save summary JSON to
reportstable - Render summary and allow export (TXT/PDF)
- Formatting:
npm run format(Prettier) - Linting:
npm run lint
Current status: The repository lints cleanly (no blocking errors) after formatting; a few react-refresh warnings may appear in UI components but are non-blocking.
- Missing env variables: The app will throw an informative error listing missing keys. Check
.envand.env.example. - Node engine warnings: If
npm installwarns aboutEBADENGINE, upgrade Node to the required version. - Large bundles: PDF worker and pdf.js can create large chunks; consider offloading heavy processing to serverless functions or using a CDN for the worker script.
- Vercel 404s: Make sure
api/[...path].tsis present and the Vercel project is using this repo root.
- Fork the repo and create a feature branch.
- Follow the existing code style. Run
npm run formatandnpm run lint -- --fixbefore committing. - Open a PR with a clear summary of changes and any migration notes.
If you want, I can add a CONTRIBUTING.md with a checklist template and PR guidelines.
Add a LICENSE file (e.g., MIT) to make the repo open-source. Tell me which license you'd like and I will create the file.
If you want this README shortened, or extended with a developer guide (ERD, API examples, CI config), tell me which sections to add and I will update it.