Skip to content

An AI powered platform developed in InnovateX 2025, BUBT Hackathon that helps users to reach the SDG goals 2 and 12

Notifications You must be signed in to change notification settings

Saon110/EcoMealHub

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🌱 EcoMealHub

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.

πŸš€ Tech Stack

Backend

  • 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

Frontend

  • 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

πŸ“‹ Features

🍱 Core Features

  • 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

πŸ€– AI-Powered Features

  • 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

πŸ“Š Analytics & Insights

  • 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

🌱 Sustainability Features

  • 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

πŸ” Authentication & Security

  • 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

🎨 User Experience

  • 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

πŸ› οΈ Setup Instructions

Prerequisites

1. Clone the Repository

git clone https://github.com/Tahmidul-Islam-Omi/EcoMealHub.git
cd EcoMealHub

2. Backend Setup

Install Dependencies

cd Backend
npm install

Environment Configuration

Create 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

Database Setup

  1. Create a Supabase project at supabase.com
  2. 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
);

Start Backend Server

# Development mode
npm run dev

# Production mode
npm start

The backend server will start on http://localhost:3000

3. Frontend Setup

Install Dependencies

cd ../Frontend/EcoMealHub
npm install

Start Frontend Development Server

npm run dev

The frontend will start on http://localhost:5173

Build for Production

npm run build
npm run preview

🌱 Seed Data Usage

Sample Global Inventory Items

To 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);

Sample Resources

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');

πŸ”§ API Endpoints

Authentication

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - User login
  • GET /api/v1/auth/google - Google OAuth login
  • GET /api/v1/auth/google/callback - Google OAuth callback
  • POST /api/v1/auth/forgot-password - Request password reset
  • POST /api/v1/auth/verify-code - Verify reset code
  • POST /api/v1/auth/reset-password - Reset password with verified code

Inventory Management

  • 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 database
  • POST /api/v1/inventory/global - Add item to global inventory (admin)

AI-Powered Features

  • POST /api/v1/inventory/text-analysis - Analyze OCR text with Gemini AI
  • POST /api/v1/inventory/add-ocr-items - Add AI-extracted items to inventory

SDG Impact Scoring

  • 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 information
  • GET /api/v1/sdg/history - Get historical SDG scores (authenticated)

Resources

  • 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)

Activity Logs

  • GET /api/v1/logs - Get user activity logs (authenticated)
  • POST /api/v1/logs - Create log entry (authenticated)

User Profile

  • GET /api/v1/user/:id - Get user profile (authenticated)
  • PUT /api/v1/user/:id - Update user profile (authenticated)

πŸ” Environment Variables

Required Backend Variables

  • host - Database host (Supabase)
  • port - Database port (default: 5432)
  • database - Database name (default: postgres)
  • user - Database user
  • password - Database password
  • JWT_SECRET - JWT signing secret (use strong random string)
  • SERVER_PORT - Server port (default: 3000)
  • NODE_ENV - Environment (development/production)

AI & External Services

  • GEMINI_API_KEY - Required - Google Gemini AI API key for OCR text analysis and SDG insights
  • RESEND_API_KEY - For email functionality (password reset)
  • FROM_EMAIL - Email sender address

Optional Authentication

🌍 SDG Impact Scoring System

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

Scoring Components

1. Waste Reduction (30%)

  • 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

2. Nutrition Quality (25%)

  • 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

3. Sustainability Practices (25%)

  • Inventory Diversity: Balance across food categories
  • Fresh Food Ratio: Fresh vs. processed items
  • Seasonal Awareness: Using seasonal produce
  • Local Sourcing: Supporting local food systems

4. Budget Efficiency (20%)

  • 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

AI-Powered Insights

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

Score Interpretation

  • 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

🚦 Health Check

Visit http://localhost:3000/health to check if the backend server is running properly.

πŸ“± Usage Guide

Getting Started

  1. Register/Login - Create an account with email/password or use Google OAuth
  2. Complete Profile - Add household size, dietary preferences, and sustainability goals
  3. Set Up Inventory - Start adding food items manually or use OCR scanning

Managing Inventory

  1. Add Items Manually - Select from global inventory or create custom items
  2. Scan Receipts - Upload receipt images, AI extracts and categorizes items automatically
  3. Monitor Expiration - Dashboard shows color-coded alerts for expiring items
  4. Update Quantities - Track consumption and adjust inventory levels

AI-Powered Features

  1. 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
  2. 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

Using the Dashboard

  1. Quick Stats - View daily calories, weekly spending, inventory health, and sustainability score
  2. Consumption Trends - Interactive charts showing your eating patterns and costs
  3. Category Distribution - Visual breakdown of your food inventory
  4. Inventory Alerts - Immediate notifications for expiring items
  5. AI Recommendations - Personalized tips to reduce waste and improve nutrition

Additional Features

  1. Meal Planning - Plan meals using your current inventory
  2. Recipe Management - Store and organize favorite recipes
  3. Resource Sharing - Browse and share food-related tips with the community
  4. Activity Logs - Complete history of all inventory changes and meals logged

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

About

An AI powered platform developed in InnovateX 2025, BUBT Hackathon that helps users to reach the SDG goals 2 and 12

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 83.3%
  • HTML 16.7%