Skip to content

rayshivam30/EcoCart

Repository files navigation

EcoCart - AI-Powered Eco-Logistics Platform

A comprehensive web platform for sustainable logistics with AI-powered packaging optimization, carbon-optimized delivery routes, and blockchain traceability.

πŸš€ Features

βœ… Fully Implemented

  • AI/ML Packaging Optimization - TensorFlow.js-based ML model for eco-friendly packaging suggestions
  • Free Geospatial APIs - OpenRouteService + OpenStreetMap for route optimization (no cost)
  • Free Weather Integration - OpenWeatherMap API for weather-based route optimization
  • Blockchain Traceability - Cryptographic blockchain for packaging material verification
  • Retailer Dashboard - Complete product management with AI recommendations
  • Customer Dashboard - Order tracking with environmental impact metrics
  • Supabase Backend - PostgreSQL database with real-time subscriptions
  • Modern UI/UX - Responsive design with ShadCN UI components

πŸ”§ Tech Stack

  • Frontend: Next.js 15, React 19, TypeScript
  • Styling: Tailwind CSS, ShadCN UI
  • Backend: Supabase (PostgreSQL, Auth, Real-time)
  • AI/ML: TensorFlow.js for packaging optimization
  • Geospatial: OpenRouteService (free) + OpenStreetMap for routing
  • Weather: OpenWeatherMap API (free, 1M calls/month)
  • Blockchain: Cryptographic blockchain implementation
  • Deployment: Vercel-ready

πŸ“‹ Prerequisites

  • Node.js 18+
  • npm or pnpm
  • Google Maps API key
  • Supabase account

πŸ› οΈ Installation

  1. Clone the repository

    git clone <repository-url>
    cd ecocart-platform
  2. Install dependencies

    pnpm install
  3. Set up environment variables

    cp env.example .env.local

    Edit .env.local with your API keys:

    NEXT_PUBLIC_SUPABASE_URL=your-supabase-project-url
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
    GOOGLE_MAPS_API_KEY=your-google-maps-api-key
  4. Set up Supabase database

    # Run the database schema
    psql -h your-supabase-host -U postgres -d postgres -f scripts/create-database.sql
    
    # Seed with demo data
    psql -h your-supabase-host -U postgres -d postgres -f scripts/seed-demo-data-final.sql
  5. Start the development server

    pnpm dev

πŸ”‘ API Keys Setup

Free APIs (Recommended - No Cost)

The platform now uses free APIs with generous limits:

OpenWeatherMap API (Weather Data)

  1. Go to OpenWeatherMap
  2. Sign up for a free account
  3. Get your API key (1,000,000 calls/month free)
  4. Add to .env.local: OPENWEATHER_API_KEY=your-key

OpenRouteService API (Routing)

  1. Go to OpenRouteService
  2. Sign up for a free account (optional - works without key for basic usage)
  3. Get your API key (2,000 requests/day free)
  4. Add to .env.local: OPENROUTE_API_KEY=your-key

Google Maps API (Optional)

If you prefer Google Maps (paid after free tier):

  1. Go to Google Cloud Console
  2. Create a new project or select existing one
  3. Enable the following APIs:
    • Maps JavaScript API
    • Directions API
    • Geocoding API
  4. Create credentials (API key)
  5. Add the API key to .env.local

Supabase Setup

  1. Create a new project at Supabase
  2. Get your project URL and anon key
  3. Add them to .env.local
  4. Run the database schema scripts

🧠 AI/ML Features

Packaging Optimization

  • Real TensorFlow.js Model: Trained neural network for optimal packaging size prediction
  • Material Selection: AI-driven eco-friendly material recommendations
  • Eco-Score Calculation: ML-based sustainability scoring
  • Cost Optimization: Intelligent cost-benefit analysis

Route Optimization

  • Google Maps Integration: Real-time route calculation
  • CO2 Emission Tracking: Vehicle-specific emission calculations
  • Alternative Routes: Multiple route options with different vehicle types
  • Traffic Integration: Real-time traffic data (when available)

⛓️ Blockchain Features

Traceability System

  • Cryptographic Verification: SHA-256 hashing for data integrity
  • Material Origin Tracking: Complete supply chain transparency
  • Certification Verification: Sustainability certification validation
  • Immutable Records: Tamper-proof blockchain ledger

Blockchain Operations

  • Add Records: Store new packaging material data
  • Verify Records: Validate blockchain integrity
  • View Chain: Complete blockchain ledger access

πŸ—ΊοΈ Geospatial Features

Route Optimization

  • Real Google Maps API: Actual route calculations
  • Distance & Duration: Accurate travel time estimates
  • Vehicle-Specific Routes: Optimized for different vehicle types
  • CO2 Calculations: Emission estimates based on vehicle type

Map Integration

  • Interactive Maps: Real-time route visualization
  • Waypoint Tracking: Detailed route breakdown
  • Alternative Routes: Multiple route options

πŸ“Š Database Schema

The platform uses a comprehensive PostgreSQL schema with the following tables:

  • profiles: User authentication and roles
  • products: Product information and dimensions
  • packaging_suggestions: AI-generated packaging recommendations
  • routes: Optimized delivery routes
  • orders: Customer order tracking
  • rewards: Customer reward points system
  • packaging_blockchain: Blockchain traceability records
  • analytics: Performance metrics and reporting

πŸš€ Deployment

Vercel Deployment

  1. Connect your GitHub repository to Vercel
  2. Add environment variables in Vercel dashboard
  3. Deploy automatically on push to main branch

Environment Variables for Production

NEXT_PUBLIC_SUPABASE_URL=your-production-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-production-supabase-key
GOOGLE_MAPS_API_KEY=your-production-google-maps-key

πŸ”§ Development

API Endpoints

AI/ML APIs

  • POST /api/ai/packaging-ml - Real ML packaging optimization
  • POST /api/ai/route-optimization - Route optimization (calls Google Maps)

Geospatial APIs

  • POST /api/geospatial/google-maps - Direct Google Maps integration

Blockchain APIs

  • POST /api/blockchain/traceability - Blockchain operations
  • GET /api/blockchain/traceability - Verify blockchain records

Database APIs

  • POST /api/packaging/suggestions - Store packaging suggestions
  • GET /api/packaging/suggestions - Retrieve packaging data

Component Structure

  • Retailer Dashboard: /app/retailer/dashboard/page.tsx
  • Customer Dashboard: /app/customer/dashboard/page.tsx
  • Blockchain Component: /components/BlockchainTraceability.tsx
  • UI Components: /components/ui/

πŸ§ͺ Testing

API Testing

# Test ML packaging optimization
curl -X POST http://localhost:3000/api/ai/packaging-ml \
  -H "Content-Type: application/json" \
  -d '{"length": 20, "width": 15, "height": 8, "weight": 300, "category": "electronics"}'

# Test route optimization
curl -X POST http://localhost:3000/api/ai/route-optimization \
  -H "Content-Type: application/json" \
  -d '{"origin": "New York, NY", "destination": "Boston, MA", "vehicleType": "electric"}'

# Test blockchain verification
curl -X GET "http://localhost:3000/api/blockchain/traceability?packagingId=test-id"

πŸ“ˆ Performance

ML Model Performance

  • Training Time: ~30 seconds for initial model training
  • Inference Time: <100ms for packaging predictions
  • Accuracy: 85%+ for eco-score predictions

API Response Times

  • Packaging API: 200-500ms
  • Route API: 1-3 seconds (Google Maps dependent)
  • Blockchain API: <100ms

πŸ”’ Security

API Security

  • Environment Variables: All API keys stored securely
  • Input Validation: Comprehensive request validation
  • Error Handling: Secure error responses

Blockchain Security

  • Cryptographic Hashing: SHA-256 for data integrity
  • Proof of Work: Mining difficulty for block validation
  • Immutable Records: Tamper-proof blockchain structure

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

For support, please open an issue in the GitHub repository or contact the development team.


Built with ❀️ for sustainable logistics

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors