Skip to content

AntoDono/edgecart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

148 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EdgeCart Logo

EdgeCart

Predictive Waste Intelligence System

Sometimes sustainability isn't about doing something grandβ€”it's about starting small.

We're tackling food waste, one produce shelf at a time.

HackPrinceton 2025

Made at HackPrinceton 2025 Powered by Knot API AI by xAI Grok

πŸ”§ Technology Stack

Python Flask PyTorch React TypeScript

YOLOv8 OpenCV Google Gemini WebSocket SQLite


🌍 The Problem

Every year, 40% of food in America goes to wasteβ€”that's $408 billion worth of food thrown away. Meanwhile:

  • Grocery stores lose money on expired produce
  • Customers miss out on deals on perfectly good food
  • Our planet suffers from unnecessary environmental impact

The current approach? Random discounts, generic sales, and hoping someone buys it. It doesn't work.


πŸ’‘ The EdgeCart Solution

We're bringing intelligence to the edge of the supply chainβ€”right where food meets shelf.

EdgeCart Admin Video Stream

How It Works

1. πŸŽ₯ Smart Camera Surveillance

Cameras point directly at produce shelves, continuously monitoring fruits, vegetables, and perishables in real-time using:

  • YOLO object detection to identify what's on the shelf
  • ResNet freshness model scoring items from 100 (just arrived) to 0 (spoiled)
  • Gemini blemish detection for precise quality assessment

Blemish Detection

Our AI detects visual changesβ€”browning bananas, soft spots on tomatoes, wilting lettuceβ€”creating a real-time decay map of all inventory.

2. πŸ”— Customer Intelligence via Knot API

Customers download our app and connect their bank/cards through Knot API, which reveals:

  • Complete purchase history across all grocery stores
  • What they buy, how often, from which stores
  • Price sensitivity and spending patterns

The system learns: "User A buys avocados 2x per week, always organic, usually spends $3-4 each" and "User B bought strawberries 5 times last month, only when under $5."

3. 🎯 Smart Matching in Real-Time

When cameras detect produce entering the "risky" freshness zone (70% freshness, 12 hours until spoilage):

  1. AI automatically calculates dynamic discounts (lower freshness = deeper discount)
  2. System identifies customers who actually buy that item
  3. Push notification: "Your favorite organic avocados now 40% off at Store X, perfect ripeness for tonight!"

No spam. No random deals. Only relevant offers for groceries you were already going to buy.

4. πŸ€– AI-Powered Recommendations (xAI Grok)

Our recommendation engine powered by xAI's Grok analyzes:

  • Purchase Pattern Analysis - When are they due for their next shopping trip?
  • Timing Relevance - Weekend bulk buyers vs. weekday shoppers
  • Value Perception - Does the discount exceed their usual threshold?
  • Behavioral Triggers - Seasonal preferences, health choices, new varieties
  • Urgency Factors - Limited quantity, time sensitivity, expiration proximity

Dashboard

Example reasoning: "Perfect for meal prep Sunday - matches weekly buying pattern, 30% discount exceeds usual 20% threshold, last purchased 8 days ago (usual cycle: 10 days)"

5. πŸ“Š Predictive Analytics for Stores

Store dashboard provides actionable insights:

  • "Based on current decay rates and customer buying patterns, reduce next banana order by 30%"
  • "Your avocado customers also shop at Whole Foods - stock more organic"
  • "50 customers notified about strawberries but only 10 bought - discount wasn't deep enough"

Prediction Dashboard

6. 🌱 Zero-Waste Fallback

For items that won't sell even with targeted discounts:

  • System auto-schedules food bank donations 12 hours before critical decay
  • Customers who referred the food bank earn "waste warrior" points
  • Community impact tracking shows pounds of food saved

Carbon

7. πŸ’¬ Natural Language Insights (xAI Grok)

Everything is queryable:

  • Stores ask: "Which products have the worst sell-through rate at 60% freshness?"
  • Customers ask: "How much could I save monthly based on my shopping patterns?"
  • Instant AI-powered insights with context

πŸ—οΈ System Architecture

High-Level Component Diagram

graph TB
    subgraph "Edge Layer"
        CAM[πŸ“Ή Smart Cameras<br/>YOLO + ResNet + Gemini]
    end
    
    subgraph "Backend Services"
        API[πŸ”§ Flask API<br/>REST + WebSocket]
        DB[(πŸ—„οΈ SQLite DB<br/>Inventory + Customers)]
        AI[πŸ€– xAI Grok<br/>Recommendation Engine]
    end
    
    subgraph "External APIs"
        KNOT[πŸ”— Knot API<br/>Purchase History]
    end
    
    subgraph "User Interfaces"
        ADMIN[πŸ‘¨β€πŸ’Ό Admin Dashboard<br/>React + TypeScript]
        CUSTOMER[πŸ‘€ Customer Portal<br/>React + TypeScript]
    end
    
    CAM -->|Real-time Detection| API
    API <-->|Store/Query| DB
    API <-->|Get Recommendations| AI
    API <-->|Sync Purchase Data| KNOT
    API <-->|WebSocket Updates| ADMIN
    API <-->|WebSocket Notifications| CUSTOMER
    
    style CAM fill:#4ade80,stroke:#22c55e,color:#000
    style API fill:#60a5fa,stroke:#3b82f6,color:#000
    style DB fill:#a78bfa,stroke:#8b5cf6,color:#000
    style AI fill:#fbbf24,stroke:#f59e0b,color:#000
    style KNOT fill:#fb923c,stroke:#f97316,color:#000
    style ADMIN fill:#ec4899,stroke:#db2777,color:#000
    style CUSTOMER fill:#06b6d4,stroke:#0891b2,color:#000
Loading

Data Flow: From Detection to Customer Notification

sequenceDiagram
    participant Camera as πŸ“Ή Smart Camera
    participant API as πŸ”§ Backend API
    participant DB as πŸ—„οΈ Database
    participant Grok as πŸ€– xAI Grok
    participant Knot as πŸ”— Knot API
    participant Customer as πŸ‘€ Customer App
    
    Camera->>API: Detect banana @ 65% freshness
    API->>DB: Update freshness score
    API->>DB: Calculate discount (35% off)
    
    alt Discount >= 20%
        API->>DB: Query customers
        API->>Knot: Fetch purchase patterns
        Knot-->>API: Sarah buys bananas weekly
        
        API->>Grok: Analyze match quality
        Grok-->>API: Priority: 92 (Perfect match)
        
        API->>DB: Create recommendation
        API->>Customer: πŸ”” Push notification
        Customer-->>API: View notification
        API->>DB: Mark as viewed
    end
    
    Note over Camera,Customer: Real-time processing: ~2-3 seconds
Loading

AI/ML Pipeline Architecture

flowchart LR
    subgraph "Computer Vision Pipeline"
        IMG[πŸ“Έ Camera Frame] --> YOLO[YOLO v8<br/>Object Detection]
        YOLO --> CROP[Crop Objects]
        CROP --> RESNET[ResNet18<br/>Freshness 0-100]
        CROP --> GEMINI[Gemini Robotics<br/>Blemish Detection]
    end
    
    subgraph "Decision Engine"
        RESNET --> SCORE[Freshness Score]
        GEMINI --> BLEMISH[Blemish Count]
        SCORE --> DISCOUNT[Calculate<br/>Dynamic Discount]
        BLEMISH --> DISCOUNT
    end
    
    subgraph "Recommendation AI"
        DISCOUNT --> FILTER{Discount<br/>>= 20%?}
        FILTER -->|Yes| GROK[xAI Grok<br/>Match Customers]
        FILTER -->|No| SKIP[Skip]
        GROK --> NOTIFY[Push Notification]
    end
    
    style IMG fill:#4ade80,stroke:#22c55e
    style YOLO fill:#60a5fa,stroke:#3b82f6
    style RESNET fill:#a78bfa,stroke:#8b5cf6
    style GEMINI fill:#fbbf24,stroke:#f59e0b
    style GROK fill:#fb923c,stroke:#f97316
    style NOTIFY fill:#ec4899,stroke:#db2777
Loading

Customer Journey Map

journey
    title Customer Experience with EdgeCart
    section Discovery
      Download app: 5: Customer
      Connect Knot account: 4: Customer
      Sync purchase history: 5: System
    section First Deal
      Camera detects ripe avocado: 5: System
      AI matches with customer: 5: System
      Push notification sent: 5: System
      Customer sees deal: 4: Customer
    section Purchase
      Customer visits store: 4: Customer
      Buys discounted avocado: 5: Customer
      Saves 40%: 5: Customer
    section Impact
      Feel good about waste: 5: Customer
      See savings dashboard: 5: Customer
      Get another deal: 5: System
Loading

Technology Stack Visualization

mindmap
  root((EdgeCart))
    Backend
      Flask REST API
      WebSocket Server
      SQLite Database
      Python 3.11
    AI/ML
      YOLOv8
        Object Detection
        Real-time Inference
      ResNet18
        Transfer Learning
        Freshness Classification
      Gemini Robotics
        Blemish Segmentation
        Quality Assessment
      xAI Grok
        NLP Recommendations
        Context Understanding
    Frontend
      React + TypeScript
      Framer Motion
      WebSocket Client
      Custom Terminal UI
    External APIs
      Knot API
        Purchase History
        Customer Profiles
        Multi-merchant Data
Loading

🎯 The Impact

For Stores

  • βœ… Reduce food waste by 30-50%
  • βœ… Recover revenue from inventory that would expire
  • βœ… Better inventory forecasting based on actual customer demand
  • βœ… Turn waste into profit

For Customers

  • βœ… Save 30-50% on groceries they already buy
  • βœ… Get notified only about items they actually want
  • βœ… Buy produce at optimal ripeness for their needs
  • βœ… Feel good about reducing waste

For the Planet

  • 🌍 Less food in landfills = reduced methane emissions
  • πŸ’§ Conserve water used to grow wasted food
  • 🌱 More efficient food supply chain
  • ♻️ Circular economy approach to grocery retail

πŸ› οΈ Technology Stack

Backend (Python)

  • Flask - REST API & WebSocket server
  • Flask-SQLA - Database ORM
  • OpenCV + YOLO - Real-time object detection
  • PyTorch + ResNet - Freshness classification model
  • Google Gemini - Blemish segmentation & detection
  • Knot API - Customer purchase data integration
  • xAI Grok - AI-powered recommendation engine
  • SQLite/PostgreSQL - Database

Frontend (React + TypeScript)

  • React - Modern component-based UI
  • WebSocket - Real-time updates
  • Framer Motion - Smooth animations
  • Custom Terminal UI - Cyberpunk aesthetic

AI/ML Models

  1. YOLOv8 - Object detection for identifying produce
  2. ResNet18 - Transfer learning for fresh/rotten classification
  3. Gemini Robotics - High-precision blemish detection
  4. xAI Grok - Natural language recommendations

πŸš€ Quick Start

Prerequisites

# Python 3.11+
python --version

# Node.js 18+
node --version

Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env with your API keys:
# - KNOT_CLIENT_ID (from Knot)
# - KNOT_SECRET (from Knot)
# - XAI_API_KEY (from xAI)
# - GEMINI_API_KEY (from Google)

# Initialize database with sample data
POPULATE=true python main.py

Frontend Setup

cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

Access the System


πŸ“Έ Demo Users

Try these pre-loaded customer profiles (no Knot API key needed):

Sarah Chen (@abc)

Health-conscious mom who loves organic berries

  • Buys strawberries, blueberries, spinach regularly
  • Shops at Instacart and Whole Foods
  • Average spend: $45-50 per trip

Marcus Lee (@def)

Fitness enthusiast buying citrus for smoothies

  • Buys oranges, grapefruits, kale 2x per week
  • Shops at Walmart and Target
  • Average spend: $22-35 per trip

Emily Rodriguez (@ghi)

Foodie exploring exotic fruits

  • Buys grapes, dragon fruit, kiwi occasionally
  • Shops at specialty stores
  • Average spend: $30-40 per trip

πŸŽ₯ Features

Admin Dashboard

  • πŸ“Ή Live Camera Feed with real-time fruit detection
  • πŸ“Š Inventory Management with freshness scores
  • 🎨 Blemish Detection with visual highlighting
  • πŸ“ˆ Analytics - Waste prevention metrics
  • πŸ”” WebSocket Updates - Real-time inventory changes
  • πŸ“‰ Predictive Ordering - AI-suggested inventory adjustments

Customer Portal

  • πŸ›’ Personalized Deals based on Knot purchase history
  • πŸ”” Smart Notifications via WebSocket (only relevant items)
  • πŸ“œ Purchase History from both Knot and EdgeCart
  • πŸ’° Savings Tracker showing total money saved
  • 🌍 Impact Dashboard showing food waste prevented
  • 🎯 AI Reasoning explains why each deal was recommended

AI Recommendation Engine

  • 🧠 Multi-dimensional Analysis (timing, value, behavior, urgency)
  • 🎯 Priority Scoring (80-100 for perfect matches)
  • πŸ“– Natural Language Reasoning for each recommendation
  • ⚑ Rate-Limited to optimize API costs (10s between calls)
  • πŸ”„ Feedback Loop learns from customer responses

πŸ“Š Database Schema

stores                 fruit_inventory           freshness_status
- id                   - id                      - id
- name                 - store_id                - inventory_id
- location             - fruit_type              - freshness_score (0-1.0)
                       - quantity                - predicted_expiry_date
                       - original_price          - discount_percentage
                       - current_price           - status (fresh/ripe/clearance)
                       - thumbnail_path          - last_checked

customers              purchase_history          recommendations
- id                   - id                      - id
- knot_customer_id     - customer_id             - customer_id
- name                 - inventory_id            - inventory_id
- email                - quantity                - priority_score
- preferences (JSON)   - price_paid              - reason (JSON)
                       - discount_applied        - viewed
                       - knot_transaction_id     - purchased

quantity_change_log    waste_log
- id                   - id
- inventory_id         - inventory_id
- old_quantity         - quantity_wasted
- new_quantity         - estimated_value_loss
- change_type          - reason
- freshness_score      - logged_at

πŸ” Environment Variables

Create a .env file in the backend/ directory:

# Knot API (for customer data)
KNOT_CLIENT_ID=your_knot_client_id
KNOT_SECRET=your_knot_secret
KNOT_ENV=tunnel  # tunnel, dev, or prod
KNOT_USE_REAL=true

# xAI (for AI recommendations)
XAI_API_KEY=your_xai_api_key

# Google Gemini (for blemish detection)
GEMINI_API_KEY=your_gemini_api_key

# Database
DATABASE_URL=sqlite:///edgecart.db

# Server
PORT=3000
POPULATE=true  # Seed with sample data on first run

πŸ“œ License

MIT License - See LICENSE file for details


About

grocery mass surveillance for event arbitrage, 4x winner at hackprinceton 2025

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors