PMAi is a comprehensive healthcare application that combines AI-powered symptom analysis, personalized diet recommendations, medication management, and health tracking. Built with modern web technologies and powered by Google's Gemini AI.
- Symptom Analysis: Get instant insights about health symptoms with AI-powered analysis
- Diet Recommendations: Personalized nutrition advice based on health goals and restrictions
- Meal Planning: Complete meal plans with calorie targets and dietary preferences
- AI Chat: Interactive health conversations with context awareness
- Authentication: Secure login/signup with JWT tokens
- Google OAuth: One-click login with Google accounts
- Face Recognition: Biometric authentication using facial recognition
- Profile Management: Comprehensive health profiles with medical history
- Medication Management: Track medications, dosages, and schedules
- Symptom Logging: Record and monitor health symptoms
- Health Statistics: Comprehensive health metrics and insights
- Diet Plans: Save and manage personalized nutrition plans
- Rate Limiting: Protected against API abuse
- Input Validation: Robust error handling and data validation
- CORS Configuration: Secure cross-origin resource sharing
- Compression: Optimized response times
- React 18 with TypeScript
- Vite for fast development and building
- Tailwind CSS for modern, responsive design
- React Router for navigation
- Axios for API communication
- Node.js with Express.js
- MongoDB with Mongoose ODM
- Google Gemini AI for intelligent responses
- JWT for authentication
- Passport.js for OAuth strategies
- Multer for file uploads
- Rate Limiting for API protection
- Google Generative AI (Gemini 2.0 Flash)
- Custom AI Prompts for healthcare and nutrition
- Context-Aware Responses with conversation history
- Personalized Recommendations based on user profiles
PMAi/
βββ backend/ # Backend server
β βββ config/ # Configuration files
β βββ controllers/ # Route controllers
β βββ middleware/ # Custom middleware
β βββ models/ # Database models
β βββ routes/ # API routes
β βββ services/ # Business logic & AI services
β βββ utils/ # Utility functions
β βββ uploads/ # File upload directory
βββ src/ # Frontend source code
β βββ components/ # React components
β βββ contexts/ # React contexts
β βββ hooks/ # Custom React hooks
β βββ pages/ # Page components
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions
βββ docs/ # Documentation
POST /auth/google- Google OAuth client-side authenticationGET /auth/google- Google OAuth server-side flowGET /auth/google/callback- Google OAuth callbackPOST /auth/logout- User logoutGET /auth/status- Authentication status checkGET /auth/face-status- Face registration statusPOST /auth/register-face- Face registrationPOST /auth/login-face- Face authenticationPOST /auth/identify-face- Face identification
POST /users/register- User registrationPOST /users/login- User loginGET /users/profile- Get user profilePUT /users/profile- Update user profilePOST /users/upload-avatar- Profile picture uploadDELETE /users/account- Delete user account
POST /api/ai/analyze-symptoms- Symptom analysis with AIPOST /api/ai/diet-recommendations- Personalized diet advicePOST /api/ai/chat- AI-powered health conversationsPOST /api/ai/meal-plan- Complete meal planningGET /api/ai/health- AI service health check
GET /api/medications- Get user medicationsPOST /api/medications- Add new medicationPUT /api/medications/:id- Update medicationDELETE /api/medications/:id- Delete medicationPATCH /api/medications/:id/taken- Mark medication as taken
GET /api/health/symptoms- Get user symptomsPOST /api/health/symptoms- Add new symptomGET /api/health/stats- Health statisticsGET /api/health/diet-plans- Get saved diet plansPOST /api/health/diet-plans- Save new diet plan
GET /health- Server health checkPOST /debug- Debug endpoint for testing
- Node.js 18+ and npm
- MongoDB instance
- Google Cloud account (for Gemini AI)
- Google OAuth credentials (optional)
-
Clone the repository
git clone <repository-url> cd PMAi/backend
-
Install dependencies
npm install
-
Environment Configuration Create a
.envfile in the backend directory:# Server Configuration PORT=5001 NODE_ENV=development # MongoDB Configuration MONGODB_URI=mongodb://localhost:27017/PMAi # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-here # Session Configuration SESSION_SECRET=your-session-secret-key-here # Google OAuth Configuration GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret GOOGLE_CALLBACK_URL=http://localhost:5001/auth/google/callback # Frontend URL FRONTEND_URL=http://localhost:5173 # Google AI Configuration GEMINI_API_KEY=your-gemini-api-key # Bcrypt Configuration BCRYPT_ROUNDS=12
-
Start the server
# Development mode npm run dev # Production mode npm start
-
Navigate to frontend directory
cd ../src -
Install dependencies
npm install
-
Start development server
npm run dev
The AI service uses carefully crafted prompts for optimal responses:
- Health Assistant: Medical guidance with safety disclaimers
- Diet Planner: Nutritional advice with personalization
- Meal Planner: Structured meal plans with nutritional balance
- Content filtering and safety settings
- Medical consultation recommendations
- Allergy and dietary restriction awareness
- Rate limiting to prevent abuse
- JWT Authentication with secure token handling
- Rate Limiting for all API endpoints
- Input Validation with comprehensive error handling
- CORS Configuration for secure cross-origin requests
- Helmet.js for security headers
- File Upload Validation with size and type restrictions
- Response Compression for faster data transfer
- MongoDB Indexing for optimized queries
- Rate Limiting to maintain service quality
- Error Handling with graceful fallbacks
- Logging with Morgan for monitoring
cd backend
npm testUse tools like Postman or curl to test endpoints:
# Health check
curl http://localhost:5001/health
# Test AI endpoint
curl -X POST http://localhost:5001/api/ai/analyze-symptoms \
-H "Content-Type: application/json" \
-d '{"symptoms": ["headache", "fatigue"]}'- Set environment variables for production
- Use PM2 or similar process manager
- Configure MongoDB Atlas for production database
- Set up proper CORS origins
- Build the project:
npm run build - Deploy to Vercel, Netlify, or similar platforms
- Update API base URL in environment variables
All API endpoints follow a consistent format:
Success Response:
{
"success": true,
"data": {...},
"message": "Operation successful"
}Error Response:
{
"error": "Error type",
"message": "Detailed error message",
"success": false
}Most endpoints require JWT authentication:
Authorization: Bearer <your-jwt-token>- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the API endpoints
AI Service 500 Errors: If you're getting 500 errors on AI endpoints, check the Troubleshooting Guide for solutions.
Quick Fix: Most AI issues are resolved by setting the correct GEMINI_API_KEY environment variable.
- API Documentation - Complete API reference
- Setup Guide - Installation and deployment
- Troubleshooting Guide - Common issues and solutions
- β Complete API endpoint implementation
- β Enhanced AI prompts for better responses
- β Comprehensive security features
- β File upload system with validation
- β Rate limiting and abuse protection
- β Input validation and error handling
- β Medication and health tracking APIs
- β Face recognition authentication
- β Google OAuth integration
PMAi - Empowering healthcare with AI technology π