A comprehensive web-based platform for medication verification, drug interaction checking, and patient safety monitoring. MedSafe combats counterfeit medications while providing AI-powered tools for medication management and safety assessment.
MedSafe is a full-stack healthcare application designed to address medication safety challenges in India and beyond. The platform enables users to verify medication authenticity through multiple methods (QR codes, image recognition, batch numbers), check for dangerous drug interactions, manage medical history, and access emergency medical resources.
- React 18 with TypeScript
- Vite - Build tool and development server
- TailwindCSS - Utility-first styling with custom design system
- shadcn/ui - Accessible component library
- React Router v6 - Client-side routing
- TanStack Query - Server state management
- Recharts - Data visualization
- next-themes - Dark mode with system preference detection
- Supabase - Backend-as-a-Service
- PostgreSQL database with Row-Level Security (RLS)
- Edge Functions (TypeScript/Deno serverless)
- Real-time subscriptions
- Authentication (Email/Password, Google OAuth, Phone OTP)
- File Storage
- pg_cron - Automated scheduled tasks
- Google Gemini 2.0 Flash - AI model for:
- Medicine information lookup
- Drug interaction analysis
- Safety score calculation
- Diet recommendations
- Prescription OCR assistance
- Tesseract.js - OCR for prescription scanning
- html2canvas + jsPDF - PDF report generation
- qrcode - QR code generation
- html5-qrcode - QR code scanning
- React Markdown - Rich text rendering
- KaTeX - Mathematical expression rendering
- QR Code Scanning: Real-time camera scanning or file upload
- Batch Number Lookup: Direct database verification against FDA dataset
- Medicine Name Search: AI-powered information retrieval
- Image Recognition: Photo-based medicine identification using AI
- OCR extraction using Tesseract.js + Gemini AI
- Automatic drug verification for all extracted medications
- Counterfeit and interaction flagging
- Secure encrypted storage with PDF export
- Multi-user support (family members, caregivers)
- Multi-medication interaction analysis
- Food and alcohol interaction detection
- Severity levels (Severe/Moderate/Minor) with color coding
- Timing recommendations
- Alternative medication suggestions
- AI-based patient-specific safety assessment
- Considers: age, medical conditions, current medications
- Drug interaction risk evaluation
- Built-in example entries for testing
- Two-Tier Patient Profile System:
- First tier: Create and manage patient profiles with personal details (name, age, gender, blood group, medical conditions, allergies, emergency contacts)
- Second tier: Access individual patient records to manage medications, dosages, and reminder schedules
- Multi-patient support for managing family members and dependents
- Per-medicine reminder configuration with customizable frequencies and times
- Caregiver access control with granular permissions
- Searchable patient directory by name or ID
- AI-powered personalized diet plans
- Considers medical history and current medications
- Interactive AI chat for nutritional guidance
- Markdown-formatted recommendations with mathematical expressions
- Counterfeit medication reporting with photo uploads
- Anonymous submission support
- Status workflow (Submitted β Under Review β Investigated β Resolved)
- Gamification: points, badges, and leaderboard
- Public heatmap visualization of reported locations
- Licensed pharmacy directory
- Google Maps integration (API required)
- Filtering by 24/7 availability, services, ratings
- License verification status
- Contact information and directions
- Public access (no login required)
- Indian-specific emergency helplines (112, Poison Control)
- First aid guides aligned with Indian medical standards
- Drug overdose symptoms and antidote information
- Emergency report filing
- Supabase real-time subscriptions
- Counterfeit detection alerts
- Medicine reminders
- Verification status updates
- Community report status changes
- Patient: Personal medication management
- Pharmacist: Drug verification approval workflow
- Admin: System-wide oversight, user management, analytics
- Single Page Application (SPA) with code splitting
- React.lazy and Suspense for lazy loading
- Responsive design with mobile-first approach
- WebP image optimization with lazy loading
- Dark/Light theme with system preference detection
Serverless TypeScript functions running on Deno:
medicine-info- AI medicine information lookupdrug-interactions- Multi-drug interaction analysisprescription-ocr- OCR + AI prescription extractionsafety-score-ai- Patient safety calculationdiet-recommendation- Personalized diet planningdiet-chat- Diet AI chat assistantscan-medicine-image- Image-based medicine identificationcheck-medicine-reminders- Automated reminder notifications (cron)send-auth-email- Custom authentication emailsimport-fda-drugs- Bulk FDA dataset import
PostgreSQL with comprehensive schema:
Core Tables:
drugs- FDA drug dataset (200k+ entries with batch numbers, risk levels, dates)scan_logs- Drug verification history with status trackingpatients- Patient profiles with personal details and medical conditionspatient_history- Medication records with reminders linked to patient profilesprescriptions- OCR-extracted prescription datacounterfeit_reports- User-submitted reports with gamificationpharmacies- Licensed pharmacy directoryfamily_members- Family health record managementcaregivers- Caregiver access control
User Management:
profiles- User profile datauser_roles- Role-based access controluser_rewards- Gamification points and badgesnotifications- Real-time notification systemdashboard_stats- User activity tracking
Security:
- Row-Level Security (RLS) policies on all tables
- Security definer functions for role checking
- Trigger-based automatic notifications
- Automated timestamp updates
- Email/Password authentication with leaked password protection
- Google OAuth integration
- Phone OTP authentication
- Session management with automatic refresh
- Role-based authorization
- Supabase Storage buckets:
avatars- User profile pictures (public)- Prescription images (private)
- Community report photos
Every table implements RLS policies ensuring:
- Users can only access their own data
- Pharmacists can verify pending scans
- Admins have system-wide access
- Public data is accessible to everyone
handle_new_user()- Auto-create profile and assign default role on signupnotify_pharmacists_of_new_scan()- Real-time alerts to pharmacistsaward_report_points()- Gamification point assignmentupdate_updated_at_column()- Automatic timestamp management
check-medicine-reminders- Runs every minute to send medication reminders
- Node.js 18+ and npm
- Git
# Clone the repository
git clone <repository-url>
cd <project-directory>
# Install dependencies
npm installCreate a .env file (or use the auto-generated one):
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_PUBLISHABLE_KEY=your_supabase_anon_key
VITE_SUPABASE_PROJECT_ID=your_project_id# Start development server
npm run dev
# Run type checking
npm run build
# Run E2E tests
npx playwright test# Build for production
npm run build
# Preview production build
npm run preview- Code splitting with React.lazy
- WebP image format with fallbacks
- Lazy loading with
loading="lazy"attribute - Tree shaking and minification
- Chunk optimization
- ARIA-compliant components
- Keyboard navigation support
- Screen reader compatibility
- High contrast support
- Focus management
- Playwright E2E tests
- GitHub Actions CI/CD integration
- Automated testing on every push
- Responsive design testing
- Row-Level Security on all database tables
- Leaked password protection
- Secure session management
- CORS configuration for edge functions
- Input validation and sanitization
- Encrypted file storage
- Custom Tailwind configuration with semantic tokens
- HSL color system for theming
- Consistent spacing and typography
- Dark/Light theme support
- Responsive breakpoints
-
FDA Drug Dataset (February 2024): 200,000+ FDA-approved drugs
- Kaggle: United States FDA Drugs dataset
- Imported via bulk JSON processing
- Includes: drug names, batch numbers, manufacturers, dates, risk levels
-
AI Models: Google Gemini 2.0 Flash
- Medicine information retrieval
- Drug interaction analysis
- Safety assessment
- Diet recommendations
βββ src/
β βββ components/ # Reusable UI components
β βββ pages/ # Route-based page components
β βββ contexts/ # React context providers
β βββ hooks/ # Custom React hooks
β βββ lib/ # Utility functions
β βββ integrations/ # External service integrations
β βββ assets/ # Static assets (images, icons)
βββ supabase/
β βββ functions/ # Edge Functions (serverless)
β βββ migrations/ # Database migration scripts
β βββ config.toml # Supabase configuration
βββ e2e/ # Playwright E2E tests
βββ public/ # Public static files
This is a hackathon project for medication safety awareness. The codebase demonstrates integration of modern web technologies with AI to solve real-world healthcare challenges.
[Add your license here]
- FDA for open drug dataset
- Google Gemini AI for intelligent features
- Supabase for backend infrastructure
- shadcn/ui for accessible components