Skip to content

Latest commit

Β 

History

History
297 lines (246 loc) Β· 14 KB

File metadata and controls

297 lines (246 loc) Β· 14 KB

MedoraX βš•οΈ β€” Intelligent Clinical Medication Coordinator & AI Health Platform

React TypeScript Vite Tailwind CSS Java Spring Boot Python FastAPI LangChain MySQL License: MIT

MedoraX is a HIPAA-compliant, enterprise-grade medication management and clinical decision-support ecosystem. Built with a high-performance React + Vite frontend, a robust Spring Boot 3 REST API, and a dedicated Python FastAPI AI Service (powered by LangChain + Mistral AI and Google Gemini Vision AI), MedoraX eliminates prescription mismatch risks, calculates patient adherence metrics, and delivers automated medication reminders.

🌐 Live Application: https://medora-x-five.vercel.app
βš™οΈ Backend Service: http://localhost:8080 / https://medorax-0.onrender.com
πŸ€– AI Service (FastAPI): http://localhost:8000


πŸ—οΈ System Architecture

MedoraX follows a multi-tier microservices architecture combining standard RESTful APIs with decoupled AI inference services.

graph TD
    subgraph ClientLayer ["Client Layer (React 18 + Vite SPA)"]
        UI["User Interface & Dashboard"]
        AuthModule["Auth & OAuth2 Handler"]
        Store["AppContext & Local State"]
        Axios["Axios API Interceptor"]
    end

    subgraph BackendLayer ["Backend API & Gateway (Spring Boot 3)"]
        CORS["CORS Preflight & Origin Filter"]
        JWTFilter["JWT Authentication Filter"]
        Security["Spring Security Chain"]
        AuthCtrl["Auth Controller"]
        MedCtrl["Medicine Controller"]
        ProfileCtrl["Profile Controller"]
        LogCtrl["Analytics & Log Controller"]
        RemCtrl["Reminder Controller"]
        MismatchCtrl["Mismatch & OCR Controller"]
        AiCtrl["AI Integration Controller"]
        FastAiService["FastAiService RestTemplate Proxy"]
    end

    subgraph AiMicroservice ["AI Service Microservice (Python FastAPI)"]
        FastAPIApp["FastAPI Engine"]
        ExplanationChain["LangChain Medicine Explanation Chain"]
        PrescriptionChain["LangChain Prescription Analysis Chain"]
        MistralLLM["Mistral AI LLM (mistral-small-latest)"]
    end

    subgraph ExternalServices ["External Vision & Data Engines"]
        Gemini["Google Gemini Vision API"]
        OCR["Tesseract OCR Engine"]
    end

    subgraph PersistenceLayer ["Persistence Layer"]
        JPA["Spring Data JPA / Hibernate"]
        DB[("MySQL Database")]
    end

    UI --> Store
    Store --> Axios
    Axios --> CORS
    AuthModule --> Security
    CORS --> JWTFilter
    JWTFilter --> Security
    Security --> AuthCtrl
    Security --> MedCtrl
    Security --> ProfileCtrl
    Security --> LogCtrl
    Security --> RemCtrl
    Security --> MismatchCtrl
    Security --> AiCtrl

    AiCtrl --> FastAiService
    FastAiService -->|HTTP POST| FastAPIApp

    FastAPIApp --> ExplanationChain
    FastAPIApp --> PrescriptionChain
    ExplanationChain --> MistralLLM
    PrescriptionChain --> MistralLLM

    MedCtrl --> Gemini
    MismatchCtrl --> OCR
    MismatchCtrl --> Gemini

    AuthCtrl --> JPA
    MedCtrl --> JPA
    ProfileCtrl --> JPA
    LogCtrl --> JPA
    RemCtrl --> JPA
    JPA --> DB
Loading

Data Flow & Request Lifecycle

  1. Authentication: Users log in via JWT credentials (/auth/login) or Google OAuth2 (/oauth2/authorization/google). On OAuth success, the server redirects back to the SPA with signed tokens.
  2. API Interception: All protected frontend requests attach Authorization: Bearer <token> headers via Axios interceptors.
  3. AI Pipeline:
    • FastAPI Microservice (/api/ai/*): Handles natural language medicine queries, prescription breakdowns, and AI assistant chats using LangChain chains with Mistral AI.
    • Multimodal Vision (/api/mismatch/check): OCR extracts text from prescription images, while Gemini AI cross-references physical pill images against user medication profiles.

✨ Key Features

1. πŸ“Š Interactive Dashboard & Adherence Hub

  • Real-Time Streak Tracker: Computes consecutive compliant intake days without missed doses.
  • Daily Compliance Rate: Calculates percentage of completed vs. missed doses dynamically.
  • Weekly Adherence Graph: Interactive Area & Bar charts powered by Recharts.
  • Active Shelf Catalog: Instant overview of current prescriptions, dosage strengths, and remaining pill counts.

2. πŸ“Έ AI Prescription Mismatch & OCR Vision Scanner

  • Multimodal AI Analysis: Scans uploaded physical prescription documents alongside pill packaging.
  • Conflict Identification: Automatically flags drug mismatches, improper dosage frequencies, and dangerous drug-drug interactions using Google Gemini 1.5 Flash.
  • Automated Fallbacks: Analyzes raw OCR text if medicine packaging images are omitted.

3. πŸ€– MedoraX AI Health Assistant (FastAPI + LangChain)

  • Clinical Copilot Assistant: Interactive AI assistant for answering medical queries, explaining side effects, and verifying food/beverage interactions.
  • Structured Markdown Rendering: Renders clinical headers, warning callout cards (⚠️), and bulleted recommendations cleanly in the UI.
  • FastAPI Proxy: Spring Boot proxies request payloads seamlessly to the Python FastAPI microservice.

4. πŸ—“οΈ Intelligent Reminder Timeline & Schedule Engine

  • Horizontal Date Navigator: 7-day calendar strip allowing historical review and future intake planning.
  • Hourly Medication Timeline: Chronological event sequence showing exact dosage times, food constraints (Before Meals, With Food, After Meals), and administration notes.
  • Compliance Toggles: One-click action buttons to mark doses as Taken, Missed, or Reset.

5. πŸ“ˆ Analytics & Heatmap Visualization

  • GitHub-Style Compliance Heatmap: 6-month density matrix visualizing long-term intake consistency.
  • Per-Medication Adherence Rates: Individual breakdown of compliance percentages across every active treatment.

6. πŸ‘€ Patient Profile & Emergency Escalation

  • Demographic Vitals: Blood group, height, weight, and allergy records.
  • Emergency Guardian Contact: Stores emergency contact details for automated alert escalation.

πŸ› οΈ Technology Stack

Layer Technologies
Frontend Framework React 18, TypeScript, Vite 6
Styling & Design System Vanilla CSS, Tailwind CSS 3, Glassmorphism, Dark Mode
Animations & UI Components Framer Motion, Lucide Icons, React Hot Toast
Data Visualization Recharts (Area, Bar, & Line Charts)
HTTP & State Management Axios, React Context API, React Hook Form
Backend Framework Java 21, Spring Boot 3.x, Spring MVC, RestTemplate
Security & Auth Spring Security 6, JWT (io.jsonwebtoken), Google OAuth2
AI Microservice Python 3.11+, FastAPI, Uvicorn, LangChain, Pydantic
AI Models & LLMs Mistral AI (mistral-small-latest), Google Gemini 1.5 Flash
Database & ORM MySQL 8.0, Spring Data JPA, Hibernate
Build Tools Maven (Spring Boot), UV / Pip (Python), Vite (React)

πŸ“‚ Project Directory Structure

MedoraX/
β”œβ”€β”€ README.md                             # Project Overview & Architecture Guide
β”œβ”€β”€ Ai Service/                           # Python FastAPI AI Microservice
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ chains/                           # LangChain chains (explanation & prescription)
β”‚   β”œβ”€β”€ models/                           # Pydantic Request/Response models
β”‚   β”œβ”€β”€ prompts/                          # Clinical system prompt templates
β”‚   β”œβ”€β”€ routes/                           # FastAPI APIRouter endpoints
β”‚   β”œβ”€β”€ services/                         # LLM invocation services
β”‚   └── main.py                           # FastAPI application entrypoint
β”œβ”€β”€ main.py                               # Root FastAPI runner
β”œβ”€β”€ requirements.txt                      # Python dependencies
β”œβ”€β”€ pyproject.toml / uv.lock              # UV package management
β”‚
β”œβ”€β”€ frontend/                             # React + Vite Frontend Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/                          # Axios API clients
β”‚   β”‚   β”‚   β”œβ”€β”€ ai.api.ts                 # FastAPI AI integration client
β”‚   β”‚   β”‚   β”œβ”€β”€ analytics.api.ts          # Analytics & Heatmap endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.api.ts               # Login, Signup, OAuth endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ medicine.api.ts           # Medicine CRUD & AI endpoints
β”‚   β”‚   β”‚   └── mismatch.api.ts           # OCR & Prescription Scanner endpoints
β”‚   β”‚   β”œβ”€β”€ components/                   # UI components (Header, Sidebar, Cards, Badges)
β”‚   β”‚   β”œβ”€β”€ context/                      # AppContext global state
β”‚   β”‚   β”œβ”€β”€ pages/                        # AIAssistant, Dashboard, PrescriptionMismatch, etc.
β”‚   β”‚   └── App.tsx / main.tsx
β”‚   β”œβ”€β”€ .env                              # VITE_API_BASE_URL config
β”‚   └── package.json
β”‚
└── backend/                              # Spring Boot Java Backend Service
    └── medicineRemainder/
        └── medicineRemainder/
            β”œβ”€β”€ src/main/java/com/project/medicineRemainder/
            β”‚   β”œβ”€β”€ Security/             # SecurityConfig, JWT Filter, OAuth2 Handler
            β”‚   β”œβ”€β”€ controller/           # REST API Controllers (AiIntegrationController, etc.)
            β”‚   β”œβ”€β”€ dto/                  # AiMedicineRequest, AiChatRequest, etc.
            β”‚   β”œβ”€β”€ Entity/               # JPA Entities (User, Medicine, Reminder, Log)
            β”‚   └── service/              # FastAiService, GeminiServices, OCRservices, etc.
            β”œβ”€β”€ src/main/resources/
            β”‚   └── application.properties# Environment configurations & database settings
            β”œβ”€β”€ run-backend.ps1           # Helper script for running Spring Boot with env vars
            └── pom.xml

πŸ“‘ REST API Reference

πŸ€– AI Service Integration (/api/ai)

Method Endpoint Description Proxied To
POST /api/ai/chat AI Health Assistant chat FastAPI POST /chat
POST /api/ai/explain Explain medicine details & side effects FastAPI POST /api/medicine/explain
POST /api/ai/prescription Analyze unstructured prescription text FastAPI POST /api/prescription/analyze
GET /api/ai/health FastAPI service health check FastAPI GET /health

πŸ” Authentication (/auth, /api/auth)

Method Endpoint Description Auth Required
POST /auth/signup Register a new user account ❌
POST /auth/login Log in and receive JWT token ❌
GET /oauth2/authorization/google Trigger Google OAuth2 Sign-In ❌
GET /api/auth/me Fetch authenticated user details βœ…

πŸ’Š Medicines (/api/medicines)

Method Endpoint Description Auth Required
GET /api/medicines Get all active medicines for authenticated user βœ…
POST /api/medicines Add a new medicine item βœ…
PUT /api/medicines/{id}/taken Mark dose as taken today βœ…
PUT /api/medicines/{id}/missed Mark dose as missed today βœ…

πŸ“Έ Prescription Scan & Mismatch (/api/mismatch)

Method Endpoint Description Auth Required
POST /api/mismatch/check Analyze prescription image against medicine image or name ❌
POST /api/mismatch/ocr-only Extract raw text via Tesseract OCR ❌

⚑ Local Setup & Execution Guide

1. Clone the Repository

git clone https://github.com/Rohit-code07/MedoraX.git
cd MedoraX

2. Start Python FastAPI AI Service

cd "Ai Service"

# Option A: Using UV (Recommended)
uv run uvicorn app.main:app --port 8000 --reload

# Option B: Using Pip & Virtual Environment
python -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --port 8000 --reload

AI Service will run on http://localhost:8000.


3. Start Spring Boot Backend

Navigate to the Spring Boot directory:

cd "backend/medicineRemainder/medicineRemainder"

Edit credentials in run-backend.ps1 or export environment variables, then execute:

.\run-backend.ps1

Backend API will run on http://localhost:8080.


4. Start React Frontend Client

Navigate to the frontend folder:

cd frontend
npm install
npm run dev

Frontend app will run on http://localhost:5173.


πŸ“œ License & Acknowledgements

This project is licensed under the MIT License β€” see the LICENSE file for details.

Developed with ❀️ by Rohit Verma.