EcoMealHub is a comprehensive food inventory management system that helps users track their food items, monitor expiration dates, and reduce food waste. The platform features OCR-based receipt scanning, meal planning, and resource sharing to promote sustainable food consumption.
- Node.js with Express.js - RESTful API server
- PostgreSQL with Supabase - Cloud database service
- Google Gemini AI - AI-powered text analysis and SDG insights
- JWT - Authentication and authorization
- Bcrypt - Password hashing
- Multer - File upload handling
- Resend - Email service integration
- Zod - Schema validation
- Helmet & CORS - Security middleware
- React 19 - User interface library
- Vite - Build tool and development server
- React Router DOM - Client-side routing
- Axios - HTTP client for API requests
- Tailwind CSS - Utility-first CSS framework
- Lucide React - Icon library
- Tesseract.js - OCR (Optical Character Recognition)
- Recharts - Data visualization and analytics
- Food Inventory Management - Track food items with quantities, costs, expiration dates, and categories
- Smart Global Inventory - Pre-populated database of common food items with estimated expiration times
- Expiration Monitoring - Visual alerts for expiring and expired items with color-coded warnings
- Activity Logging - Comprehensive tracking of all inventory changes and meal consumption
- User Profiles - Customizable profiles with household size, dietary preferences, and goals
- OCR Receipt Scanning - Extract food items from receipt images using Tesseract.js
- AI Text Analysis - Google Gemini AI automatically structures and categorizes extracted food data
- SDG Impact Scoring - AI-powered sustainability scoring based on UN Sustainable Development Goals
- Weekly AI Insights - Personalized recommendations for reducing waste and improving nutrition
- Smart Recommendations - AI-generated suggestions for meal planning and food usage
- Interactive Dashboard - Real-time visualization of consumption patterns, spending, and inventory health
- SDG Impact Breakdown - Detailed scoring across waste reduction, nutrition, sustainability, and budget efficiency
- Consumption Trends - Charts showing calorie intake and spending over time
- Category Distribution - Visual breakdown of food inventory by category
- Achievement Tracking - Gamified progress tracking with achievements and milestones
- Waste Reduction Tracking - Monitor food waste patterns and get improvement suggestions
- Inventory Turnover Analysis - Track how efficiently you use your food inventory
- Expiration Management - Proactive alerts to use food before it expires
- Budget Efficiency Scoring - Optimize food spending and reduce waste
- Next Steps Recommendations - Actionable tips to improve sustainability practices
- JWT Authentication - Secure token-based authentication
- Google OAuth Integration - Quick sign-in with Google accounts
- Password Reset - Email-based password recovery with secure verification codes
- Role-Based Access - User and admin role management
- Resource Sharing - Community platform for sharing food-related tips and resources
- Meal Planning - Plan meals using your current inventory
- Recipe Management - Store and organize favorite recipes
- Responsive Design - Mobile-friendly interface with Tailwind CSS
- Real-time Updates - Instant UI updates with React state management
- Node.js (v18 or higher)
- npm or yarn
- PostgreSQL database (Supabase account) - Sign up here
- Google Gemini API key - Get free API key
- Resend API key (optional, for email features) - Get API key
- Google OAuth credentials (optional, for social login) - Google Console
git clone https://github.com/Tahmidul-Islam-Omi/EcoMealHub.git
cd EcoMealHubcd Backend
npm installCreate a .env file in the Backend directory with the following variables:
# Database Configuration (Supabase)
host=your-supabase-host
port=5432
database=postgres
user=your-supabase-user
password=your-supabase-password
pool_mode=session
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
SERVER_PORT=3000
NODE_ENV=development
# AI Service (Google Gemini)
GEMINI_API_KEY=your_gemini_api_key_from_google_ai_studio
# Email Service (Resend)
RESEND_API_KEY=your_resend_api_key
FROM_EMAIL=your_from_email@domain.com
# Google OAuth (Optional)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=http://localhost:3000/api/v1/auth/google/callback- Create a Supabase project at supabase.com
- Create the following tables in your Supabase database:
Users Table:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255),
google_id VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Global Inventory Table:
CREATE TABLE global_inventory (
id SERIAL PRIMARY KEY,
item_name VARCHAR(255) NOT NULL,
category VARCHAR(100),
expiration_days INTEGER,
cost DECIMAL(10,2),
image_url TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);User Inventory Table:
CREATE TABLE user_inventory (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
item_id INTEGER REFERENCES global_inventory(id),
quantity DECIMAL(10,2) NOT NULL,
unit VARCHAR(50),
custom_cost DECIMAL(10,2),
expiration_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Resources Table:
CREATE TABLE resources (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
title VARCHAR(255) NOT NULL,
description TEXT,
category VARCHAR(100),
url TEXT,
image_url TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Logs Table:
CREATE TABLE logs (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
action VARCHAR(255) NOT NULL,
details TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Password Reset Table:
CREATE TABLE password_resets (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
reset_code VARCHAR(10) NOT NULL,
expires_at TIMESTAMP NOT NULL,
used BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);# Development mode
npm run dev
# Production mode
npm startThe backend server will start on http://localhost:3000
cd ../Frontend/EcoMealHub
npm installnpm run devThe frontend will start on http://localhost:5173
npm run build
npm run previewTo populate your database with sample food items, you can insert the following data into the global_inventory table:
INSERT INTO global_inventory (item_name, category, expiration_days, cost) VALUES
('Bananas', 'fruits', 7, 2.50),
('Milk', 'dairy', 5, 3.99),
('Bread', 'grains', 3, 2.99),
('Chicken Breast', 'meat', 2, 8.99),
('Lettuce', 'vegetables', 7, 1.99),
('Eggs', 'dairy', 14, 4.49),
('Tomatoes', 'vegetables', 5, 3.29),
('Rice', 'grains', 365, 5.99),
('Yogurt', 'dairy', 10, 4.99),
('Apples', 'fruits', 14, 3.99);INSERT INTO resources (user_id, title, description, category, url) VALUES
(1, 'Food Waste Reduction Tips', 'Learn how to reduce food waste at home', 'sustainability', 'https://example.com/food-waste-tips'),
(1, 'Meal Prep Guide', 'Complete guide to meal preparation', 'cooking', 'https://example.com/meal-prep'),
(1, 'Seasonal Produce Calendar', 'Know when fruits and vegetables are in season', 'seasonal', 'https://example.com/seasonal-produce');POST /api/v1/auth/register- User registrationPOST /api/v1/auth/login- User loginGET /api/v1/auth/google- Google OAuth loginGET /api/v1/auth/google/callback- Google OAuth callbackPOST /api/v1/auth/forgot-password- Request password resetPOST /api/v1/auth/verify-code- Verify reset codePOST /api/v1/auth/reset-password- Reset password with verified code
GET /api/v1/inventory- Get user's inventory items (authenticated)POST /api/v1/inventory- Add new inventory item (authenticated)PUT /api/v1/inventory/:id- Update inventory item (authenticated)DELETE /api/v1/inventory/:id- Delete inventory item (authenticated)GET /api/v1/inventory/global- Get global inventory databasePOST /api/v1/inventory/global- Add item to global inventory (admin)
POST /api/v1/inventory/text-analysis- Analyze OCR text with Gemini AIPOST /api/v1/inventory/add-ocr-items- Add AI-extracted items to inventory
GET /api/v1/sdg/score- Get user's SDG impact score (authenticated)GET /api/v1/sdg/insights- Get weekly AI insights (authenticated)GET /api/v1/sdg/targets- Get SDG target informationGET /api/v1/sdg/history- Get historical SDG scores (authenticated)
GET /api/v1/resources- Get all resources (with pagination)POST /api/v1/resources- Create resource (authenticated)PUT /api/v1/resources/:id- Update resource (authenticated)DELETE /api/v1/resources/:id- Delete resource (authenticated)
GET /api/v1/logs- Get user activity logs (authenticated)POST /api/v1/logs- Create log entry (authenticated)
GET /api/v1/user/:id- Get user profile (authenticated)PUT /api/v1/user/:id- Update user profile (authenticated)
host- Database host (Supabase)port- Database port (default: 5432)database- Database name (default: postgres)user- Database userpassword- Database passwordJWT_SECRET- JWT signing secret (use strong random string)SERVER_PORT- Server port (default: 3000)NODE_ENV- Environment (development/production)
GEMINI_API_KEY- Required - Google Gemini AI API key for OCR text analysis and SDG insights- Get your API key from Google AI Studio
- Free tier available with rate limits
RESEND_API_KEY- For email functionality (password reset)FROM_EMAIL- Email sender address
GOOGLE_CLIENT_ID- For Google OAuth integrationGOOGLE_CLIENT_SECRET- For Google OAuth integrationGOOGLE_CALLBACK_URL- Google OAuth callback URL (default: http://localhost:3000/api/v1/auth/google/callback)
EcoMealHub implements a comprehensive sustainability scoring system based on the United Nations Sustainable Development Goals (SDGs), specifically targeting:
- SDG 2: Zero Hunger (Nutrition & Food Security)
- SDG 3: Good Health and Well-being
- SDG 12: Responsible Consumption and Production
- Inventory Turnover: How quickly you use items before expiration
- Expiration Management: Percentage of items used before expiring
- Food Waste Patterns: Tracking and reducing expired items
- Smart Shopping: Buying appropriate quantities
- Meal Logging Consistency: Regular tracking of meals
- Calorie Balance: Maintaining healthy daily intake
- Dietary Diversity: Variety in food categories
- Fresh Produce Consumption: Prioritizing fresh over processed foods
- Inventory Diversity: Balance across food categories
- Fresh Food Ratio: Fresh vs. processed items
- Seasonal Awareness: Using seasonal produce
- Local Sourcing: Supporting local food systems
- Cost Per Meal: Optimizing spending without sacrificing quality
- Price Consciousness: Smart shopping decisions
- Waste-Cost Ratio: Financial impact of food waste
- Value Optimization: Getting the most from your food budget
The system uses Google Gemini AI to:
- Analyze your consumption patterns
- Identify improvement opportunities
- Generate personalized weekly insights
- Suggest actionable next steps
- Track achievements and milestones
- Provide context-aware recommendations
- 90-100: π SDG Champion - Leading by example in sustainable food management
- 75-89: β SDG Achiever - Making significant positive impact
- 60-74: π SDG Contributor - Good progress with room for improvement
- 45-59: π SDG Learner - On the right track, keep improving
- 0-44: π± SDG Beginner - Just starting your sustainability journey
Visit http://localhost:3000/health to check if the backend server is running properly.
- Register/Login - Create an account with email/password or use Google OAuth
- Complete Profile - Add household size, dietary preferences, and sustainability goals
- Set Up Inventory - Start adding food items manually or use OCR scanning
- Add Items Manually - Select from global inventory or create custom items
- Scan Receipts - Upload receipt images, AI extracts and categorizes items automatically
- Monitor Expiration - Dashboard shows color-coded alerts for expiring items
- Update Quantities - Track consumption and adjust inventory levels
-
OCR Receipt Scanning:
- Take a photo of your grocery receipt
- Upload to the OCR scanner
- AI extracts food items with quantities, costs, and categories
- Review and confirm items before adding to inventory
-
SDG Impact Tracking:
- View your sustainability score (0-100) on the dashboard
- Get breakdown across 4 key areas:
- Waste Reduction (30%)
- Nutrition Quality (25%)
- Sustainability Practices (25%)
- Budget Efficiency (20%)
- Receive weekly AI-generated insights and recommendations
- Track achievements and progress over time
- Quick Stats - View daily calories, weekly spending, inventory health, and sustainability score
- Consumption Trends - Interactive charts showing your eating patterns and costs
- Category Distribution - Visual breakdown of your food inventory
- Inventory Alerts - Immediate notifications for expiring items
- AI Recommendations - Personalized tips to reduce waste and improve nutrition
- Meal Planning - Plan meals using your current inventory
- Recipe Management - Store and organize favorite recipes
- Resource Sharing - Browse and share food-related tips with the community
- Activity Logs - Complete history of all inventory changes and meals logged
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request