How arankan05/ygc-ai-medical-intelligence works
Purpose and entry points
YGC AI Medical Intelligence is a patient-facing medical-record intelligence platform: users upload records, the system extracts structured clinical data, evaluates medication safety, and supports record review and provider discovery. The backend FastAPI entry point is backend/app/main.py; frontend routing starts at frontend/src/app/page.tsx and authenticated application routes live under frontend/src/app/(app).
Frontend application shell
The Next.js/TypeScript frontend separates authentication from the signed-in medical workspace. Shared navigation and layout are centralized in frontend/src/components/app-shell.tsx, frontend/src/components/app-sidebar.tsx, and frontend/src/app/(auth)/layout.tsx. API, Supabase, types, and client upload state are boundary modules in frontend/src/lib/api.ts, frontend/src/lib/supabase.ts, and frontend/src/lib/upload-store.ts.
Records and document ingestion
Document APIs accept and expose record uploads through backend/app/api/documents.py. Processing is staged: storage/upload handling, PDF extraction or OCR, text cleaning, then orchestration into medical extraction, represented by backend/app/services/document_processing_service.py, backend/app/services/pdf_extractor.py, and backend/app/services/ocr_service.py. The UI entry is frontend/src/app/(app)/documents/upload/page.tsx, with document browsing/detail routes under frontend/src/app/(app)/documents.
AI extraction and clinical persistence
A provider-independent AI layer abstracts LLM implementations behind a base interface and factory, allowing Gemini or mock providers: backend/app/services/ai/base_provider.py, backend/app/services/ai/factory.py, and backend/app/services/ai/gemini_provider.py. Extracted information is normalized through schemas and persisted as domain entities by backend/app/services/medical_extraction_service.py and backend/app/services/medical_persistence_service.py. Core persisted concepts include documents, findings, medications, lab results, allergies, events, analyses, and patient records in backend/app/models/document.py, backend/app/models/finding.py, and backend/app/models/medical_event.py.
Medication safety pipeline
Medication-safety endpoints are isolated in backend/app/api/medication_safety.py. The service composes interaction checks, dosage rules, and persistence of analysis results in backend/app/services/medication_safety_service.py, backend/app/services/medication_interactions.py, and backend/app/services/medication_safety_persistence_service.py. Its patient-facing surface is frontend/src/app/(app)/medication-safety/medication-safety-view.tsx; related record views include medications, allergies, lab results, findings, and timeline routes.
Records, analyses, and provider workflows
Record-oriented API access is concentrated in backend/app/api/records.py, while frontend routes provide timeline, analyses, AI-question, and provider-search experiences: frontend/src/app/(app)/timeline/page.tsx, frontend/src/app/(app)/ask-ai/page.tsx, and frontend/src/app/(app)/providers/results/page.tsx. Provider domain models (backend/app/models/doctor_search.py, backend/app/models/doctor_recommendation.py) indicate provider search/ranking is a distinct domain boundary; the README identifies OpenStreetMap, Nominatim, and Overpass as its external data sources.
Identity, data, and deployment boundaries
Authentication endpoints and security logic reside in backend/app/api/auth.py and backend/app/core/security.py; the frontend has dedicated sign-in/sign-up flows. SQLAlchemy database wiring is in backend/app/db/database.py, with schema evolution managed by Alembic migrations such as backend/alembic/versions/b1b8329252b7_initial_medical_intelligence_schema.py. Production infrastructure uses Supabase PostgreSQL with pgvector and Supabase Storage; the frontend is intended for Vercel and backend for Render. Document extraction depends on PyMuPDF and Tesseract; AI may use an LLM provider and optionally Ollama.
Main entry points: app-shell.tsx Application shell · main.py FastAPI application · document.py Clinical domain entities · records.py Records API
Components 20
Next.js frontend
Patient-facing authentication and medical workspace.
- Frontend routes · Public entry and authenticated workspace routes.
frontend/src/app/page.tsx - Application shell · Shared signed-in navigation and layout.
frontend/src/components/app-shell.tsx - Client API and session · API client, Supabase client, and upload state.
frontend/src/lib/api.ts - Document upload
frontend/src/app/(app)/documents/upload/page.tsx - Medication safety view
frontend/src/app/(app)/medication-safety/medication-safety-view.tsx - Record review workflows · Timeline, AI questions, and provider search results.
frontend/src/app/(app)/timeline/page.tsx
FastAPI backend
HTTP boundaries for identity, records, documents, and safety.
- FastAPI application
backend/app/main.py - Authentication API · Auth endpoints and security enforcement.
backend/app/api/auth.py - Documents API · Upload and document access endpoints.
backend/app/api/documents.py - Records API · Record-oriented clinical data access.
backend/app/api/records.py - Medication safety API
backend/app/api/medication_safety.py
Clinical ingestion
Document processing and structured medical extraction.
- Document processing · Coordinates storage, extraction, cleaning, and medical extraction.
backend/app/services/document_processing_service.py - PDF and OCR extraction · Uses PyMuPDF or Tesseract for source text.
backend/app/services/pdf_extractor.py - Medical extraction · Converts text into structured clinical data.
backend/app/services/medical_extraction_service.py - AI provider factory · Selects Gemini or mock implementations behind a common interface.
backend/app/services/ai/factory.py
Medication safety
Medication risk evaluation pipeline.
- Safety evaluation · Combines interaction checks, dosage rules, and result persistence.
backend/app/services/medication_safety_service.py
Persistence and external services
Clinical data, storage, and third-party providers.
- Clinical domain entities · Documents, findings, medications, labs, allergies, events, analyses, and records.
backend/app/models/document.py - Supabase PostgreSQL + pgvector · Production clinical data store managed through SQLAlchemy and Alembic.
backend/app/db/database.py - Supabase Storage · Production document upload storage.
- Provider data sources · OpenStreetMap, Nominatim, and Overpass support provider discovery.
Connections 21
- Frontend routes → Application shell: renders
- Application shell → Client API and session: uses
- Application shell → Document upload: hosts
- Application shell → Medication safety view: hosts
- Application shell → Record review workflows: hosts
- Client API and session → FastAPI application: HTTP requests
- FastAPI application → Authentication API: routes
- FastAPI application → Documents API: routes
- FastAPI application → Records API: routes
- FastAPI application → Medication safety API: routes
- Documents API → Document processing: ingests uploads
- Document processing → Supabase Storage: stores source files
- Document processing → PDF and OCR extraction: extracts text
- PDF and OCR extraction → Medical extraction: clean text
- Medical extraction → AI provider factory: uses LLM
- Medical extraction → Clinical domain entities: persists normalized data
- Clinical domain entities → Supabase PostgreSQL + pgvector: mapped to
- Records API → Clinical domain entities: reads records and analyses
- Medication safety API → Safety evaluation: evaluates
- Safety evaluation → Clinical domain entities: reads medications and writes analyses
- Records API → Provider data sources: provider discovery