Skip to content

Latest commit

Β 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SmartSort AI ♻️

Next-Generation AI-Powered Waste Segregation System

A full-stack Computer Vision platform that classifies waste in real-time and provides instant, localized disposal guidance based on BBMP (Bengaluru) waste management guidelines.

Live Demo Model Accuracy Classes


πŸ“‘ Table of Contents


🌐 Live Deployment

Service Platform URL
🎨 Frontend Vercel smart-sort-lac.vercel.app
⚑ Backend API Render REST /predict endpoint

πŸ›οΈ System Architecture

SmartSort follows a Decoupled Three-Tier Architecture to ensure scalability, separation of concerns, and high availability. Each tier is independently deployable and scalable.

graph TD
    subgraph CLIENT["πŸ–₯️  Client Tier β€” Vercel"]
        A["πŸ‘€ User\nPhone Camera"] -->|"Capture frame"| B["⬑ Next.js 15\nApp Router"]
        B -->|"Resize 224Γ—224\nNormalize [0,1]"| C{{"API Request"}}
    end

    subgraph SERVER["βš™οΈ  API & Inference Tier β€” Render"]
        C -->|"POST /predict"| D["⚑ FastAPI Backend"]
        D -->|"Tensor preparation"| E["🧠 MobileNetV2\nInference Engine"]
        E -->|"Softmax Β· 12 classes"| F{{"Confidence > 0.70?"}}
        F -->|"YES"| G["βœ… Identify Class\n+ BBMP Mapping"]
        F -->|"NO"| H["❓ Return 'Unknown'"]
    end

    G -->|"JSON response"| B
    H -->|"JSON response"| B
    B -->|"Display result"| A

    style CLIENT fill:#0f2027,stroke:#00cfff,color:#e2e8f0
    style SERVER fill:#0f2027,stroke:#f59e0b,color:#e2e8f0
    style E fill:#2d1b69,stroke:#a78bfa,color:#e2e8f0
    style D fill:#1a1a00,stroke:#f59e0b,color:#e2e8f0
    style B fill:#001a2e,stroke:#00cfff,color:#e2e8f0
    style G fill:#002200,stroke:#00ff9d,color:#e2e8f0
    style H fill:#2a0000,stroke:#ef4444,color:#e2e8f0
Loading

πŸ”Ή Tier 1 β€” Client (Frontend)

  • Framework: Next.js 15 (App Router)
  • Camera Handling: MediaDevices API + React-Webcam
  • Preprocessing: Resizes and normalizes images to 224Γ—224 client-side before transmission
  • UI: Tailwind CSS with real-time feedback and scan history
  • State Management: Prediction results and scan history persisted in React state

πŸ”Ή Tier 2 β€” API (Backend)

  • Framework: FastAPI (Python 3.10) via Uvicorn
  • Accepts multipart/form-data image uploads
  • Normalizes pixel tensors to [0, 1]
  • Handles CORS securely for cross-origin frontend requests
  • Acts as REST bridge between the UI and the ML inference engine

πŸ”Ή Tier 3 β€” Inference (ML Engine)

  • Model: MobileNetV2 (Transfer Learning β€” Functional API)
  • Confidence Guard: 0.70 threshold prevents false-positive classifications
  • Optimized for real-world variable lighting conditions

πŸ”„ Request–Response Lifecycle β€” Sequence Diagram

Full end-to-end flow from camera capture to disposal guidance display:

sequenceDiagram
    autonumber

    actor U as πŸ‘€ User
    participant FE as ⬑ Next.js 15<br/>(Vercel)
    participant BE as ⚑ FastAPI<br/>(Render)
    participant ML as 🧠 MobileNetV2<br/>(Inference Engine)

    Note over U,ML: ── SmartSort AI Β· Request–Response Lifecycle ──

    U->>FE: Capture waste image via phone camera
    Note right of U: MediaDevices API / React-Webcam

    FE->>FE: Client-side preprocessing
    Note right of FE: Resize β†’ 224Γ—224 px<br/>Normalize pixel values [0, 1]<br/>Reduces network payload

    FE->>BE: POST /predict (multipart/form-data)
    Note right of FE: Async HTTP request<br/>Preprocessed image bytes

    BE->>BE: Decode image β†’ NumPy tensor
    Note right of BE: Shape: (1, 224, 224, 3)<br/>Normalize to [0, 1]

    BE->>ML: Forward pass β€” tensor input
    Note right of BE: Prepared float32 tensor

    ML-->>BE: Probability distribution (12 classes)
    Note right of ML: Softmax output across<br/>Battery Β· Biological Β· Plastic Β· Glass<br/>Paper Β· Metal Β· Cardboard Β· Clothes<br/>Shoes Β· Trash Β· Brown-Glass Β· White-Glass

    BE->>BE: Confidence guard (threshold = 0.70)
    Note right of BE: score > 0.70 β†’ identify class<br/>score ≀ 0.70 β†’ return "Unknown"

    BE->>BE: Map result β†’ BBMP disposal instruction
    Note right of BE: e.g. Plastic β†’ "Blue Dry Waste Bin"<br/>Biological β†’ "Green Compost Bin"<br/>Battery β†’ "e-waste collection centre"

    BE-->>FE: JSON response
    Note right of BE: { class, confidence, instruction }

    FE-->>U: Render result + disposal guidance
    Note right of FE: Class label Β· Confidence % Β· Recycling tip
Loading

πŸ”§ Component Pipeline

graph LR
    subgraph INPUT["πŸ“₯ Input Module"]
        I1["Image Acquisition\nMediaDevices API"]
        I2["Client Preprocessing\n224Γ—224 Β· Normalize"]
    end

    subgraph CORE["βš™οΈ Core Pipeline"]
        C1["FastAPI REST Layer\nPOST /predict"]
        C2["Tensor Converter\nNumPy Β· float32"]
        C3["MobileNetV2 Engine\nTransfer Learning"]
        C4["Confidence Guard\nThreshold = 0.70"]
    end

    subgraph OUTPUT["πŸ“€ Output Module"]
        O1["BBMP Mapper\n12 category rules"]
        O2["JSON Formatter\nclass Β· confidence Β· instruction"]
        O3["UI Renderer\nNext.js State Update"]
    end

    I1 --> I2 --> C1 --> C2 --> C3 --> C4 --> O1 --> O2 --> O3

    style INPUT fill:#001a2e,stroke:#00cfff,color:#e2e8f0
    style CORE fill:#1a0f00,stroke:#f59e0b,color:#e2e8f0
    style OUTPUT fill:#001a00,stroke:#00ff9d,color:#e2e8f0
Loading

πŸ“‹ Disposal Guidelines (BBMP Mapping)

SmartSort doesn't just classify waste β€” it maps every prediction to Bengaluru's BBMP segregation rules, encouraging correct disposal at the source.

Category Item Types Disposal Instruction
πŸ”‹ Hazardous Battery Take to designated e-waste collection centers.
🌱 Organic Biological Place in the Green Compost Bin.
♻️ Recyclable Plastic, Glass, Metal, Cardboard Rinse and place in the Dry Waste (Blue) Bin.
πŸ‘• Textile Clothes, Shoes Donate if usable, else use textile recycling drop-off.
πŸ—‘οΈ General Trash Dispose of in the Landfill (Red) Bin.

πŸ“Š Performance Metrics

Metric Value
βœ… Validation Accuracy 91%
πŸ‹οΈ Training Accuracy 97%
🧠 Model Architecture MobileNetV2
πŸ“¦ Total Classes 12
πŸ“ Input Dimensions 224 Γ— 224 Γ— 3
πŸ›‘οΈ Confidence Threshold 0.70

πŸ“¦ Supported Waste Classes

# Class # Class
1 πŸ”‹ Battery 7 βš™οΈ Metal
2 🧫 Biological 8 πŸ“„ Paper
3 🟀 Brown-Glass 9 🧴 Plastic
4 πŸ“¦ Cardboard 10 πŸ‘Ÿ Shoes
5 πŸ‘• Clothes 11 πŸ—‘οΈ Trash
6 πŸ«™ Glass 12 ⬜ White-Glass

πŸ› οΈ Technical Stack

🎨 Frontend

Tool Purpose
Next.js 15 (App Router) UI framework & routing
Tailwind CSS Utility-first responsive styling
React-Webcam Camera access & frame capture

βš™οΈ Backend

Tool Purpose
FastAPI REST API framework
Uvicorn ASGI production server
Python 3.10 Runtime

πŸ€– Machine Learning

Tool Purpose
TensorFlow 2.x Deep learning framework
Keras High-level model API
MobileNetV2 Transfer learning base model
NumPy Tensor operations
Pillow Image decoding & preprocessing

πŸš€ DevOps & Deployment

Tool Purpose
GitHub Version control & CI/CD
Vercel Frontend hosting (CDN + edge)
Render Backend hosting (auto-deploy)

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Git

1️⃣ Clone the Repository

git clone https://github.com/Yusufali2004/smart-sort.git
cd smart-sort

2️⃣ Backend Setup

cd backend
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload

Backend runs at: http://localhost:8000
API docs available at: http://localhost:8000/docs

3️⃣ Frontend Setup

Create a .env.local file inside the frontend/ directory:

NEXT_PUBLIC_API_URL=http://localhost:8000

Then run:

cd frontend
npm install
npm run dev

Frontend runs at: http://localhost:3000


πŸ’‘ Engineering Highlights

Feature Description
πŸ›‘οΈ Confidence Threshold 0.70 guard prevents incorrect or ambiguous classifications from reaching the user
⚑ Client-Side Preprocessing 224Γ—224 resize & normalization on the edge reduces backend load and latency
πŸ”₯ Cold-Start Optimization Warm-up ping strategy ensures the Render backend is ready on first request
πŸ”€ Decoupled Deployment Frontend and backend scale independently with zero coupling
πŸ—ΊοΈ BBMP Mapping Every class maps to a real Bengaluru disposal rule β€” not just a label

πŸ” Authentication & User Management

SmartSort uses Supabase Authentication to provide secure, user-specific access to the platform.

Authentication Features

  • πŸ“§ Email/password authentication
  • πŸ“ User registration with full name
  • πŸ”‘ Secure login and logout
  • πŸ›‘οΈ Protected scanner and dashboard routes
  • πŸ‘€ User profile storage
  • πŸ”’ Supabase Row Level Security (RLS)
  • πŸ†” Every waste record is associated with the authenticated user's UUID

Authentication Flow

User
 β”‚
 β”œβ”€β”€ Sign Up
 β”‚      β”‚
 β”‚      └── Supabase Auth
 β”‚              β”‚
 β”‚              └── User ID
 β”‚
 β”œβ”€β”€ Login
 β”‚      β”‚
 β”‚      └── Supabase Session
 β”‚
 └── Authenticated Application
         β”‚
         β”œβ”€β”€ SmartSort Scanner
         β”‚
         └── Personal Dashboard

The frontend obtains the authenticated user through the Supabase client and uses the user's UUID when creating waste records.


πŸ“Š User Dashboard

SmartSort provides a personalized dashboard for every authenticated user.

The dashboard retrieves only the waste records belonging to the currently authenticated user.

Dashboard Features

Feature Description
πŸ“ˆ Total Scans Total number of waste classifications performed
♻️ Recyclable Items Number of potentially recyclable classifications
🧠 Average Confidence Average AI classification confidence
🌱 COβ‚‚ Impact Estimated cumulative carbon impact
πŸ“Š Waste Distribution Category-wise breakdown of classified waste
βš–οΈ Recorded Weight Total recorded waste weight
πŸ”’ Total Quantity Total quantity of recorded waste
πŸ•’ Recent Scans Latest user classifications
πŸš€ Quick Scan Direct navigation back to the scanner

Dashboard Flow

Authenticated User
        β”‚
        β–Ό
   Supabase Auth
        β”‚
        β–Ό
     User UUID
        β”‚
        β–Ό
   waste_records
        β”‚
        β”‚  RLS:
        β”‚  auth.uid() = user_id
        β–Ό
 User-specific records
        β”‚
        β–Ό
 Dashboard Analytics
        β”‚
        β”œβ”€β”€ Total Scans
        β”œβ”€β”€ Recyclable Count
        β”œβ”€β”€ Average Confidence
        β”œβ”€β”€ COβ‚‚ Impact
        β”œβ”€β”€ Waste Distribution
        └── Recent Activity

πŸ—„οΈ Database Architecture

SmartSort uses PostgreSQL through Supabase for authentication-related data, user profiles, waste classifications, disposal information, and environmental impact calculations.

Database Tables

Table Purpose
profiles Stores application-level user profile information
waste_records Stores authenticated users' AI waste classifications
waste_categories Stores waste category definitions and properties
disposal_guides Stores disposal instructions for different materials
emission_factors Stores carbon/emission factors used for environmental calculations

Database Relationship

Supabase Auth
     β”‚
     β”‚ user.id
     β–Ό
 profiles
     β”‚
     β”‚
     └───────────────┐
                      β”‚
                      β–Ό
               waste_records
                      β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β–Ό          β–Ό          β–Ό
    waste_categories  disposal_guides  emission_factors

πŸ“‹ Complete Database Schema

profiles

Stores application-level information associated with an authenticated Supabase user.

Column Type Nullable Default
id UUID NO β€”
full_name TEXT YES β€”
created_at TIMESTAMPTZ YES β€”

waste_categories

Defines supported waste categories and their disposal characteristics.

Column Type Nullable
id UUID NO
name TEXT NO
material TEXT YES
recyclable BOOLEAN NO
compostable BOOLEAN NO
default_disposal_method TEXT YES
created_at TIMESTAMPTZ NO

disposal_guides

Stores disposal instructions associated with materials.

Column Type Nullable
id UUID NO
material TEXT NO
disposal_method TEXT NO
instructions TEXT NO
created_at TIMESTAMPTZ NO

emission_factors

Stores environmental impact factors used for COβ‚‚e calculations.

Column Type Nullable
id UUID NO
material TEXT NO
co2e_per_kg NUMERIC NO
unit TEXT NO
source TEXT YES
recycling_factor NUMERIC YES
created_at TIMESTAMPTZ NO

waste_records

Stores the result of each user's waste classification.

Column Type Nullable Default
id UUID NO gen_random_uuid()
user_id UUID NO β€”
ai_category TEXT YES β€”
ai_confidence NUMERIC YES β€”
final_category TEXT NO β€”
material TEXT YES β€”
quantity INTEGER NO 1
weight_grams NUMERIC YES β€”
weight_source TEXT NO 'manual'
disposal_method TEXT YES β€”
carbon_impact_co2e NUMERIC YES β€”
created_at TIMESTAMPTZ NO now()

waste_records Constraints

  • Primary key: waste_records_pkey β†’ id
  • Foreign key: waste_records_user_id_fkey β†’ authenticated user
  • Check constraint: weight_source
  • Required fields enforced through NOT NULL constraints

πŸ”’ Row Level Security

SmartSort uses PostgreSQL Row Level Security to ensure that users can access only their own waste records.

waste_records Policies

Policy Operation Rule
Users can view their own waste records SELECT auth.uid() = user_id
Users can insert their own waste records INSERT auth.uid() = user_id
Users can update their own waste records UPDATE auth.uid() = user_id
Users can delete their own waste records DELETE auth.uid() = user_id

This prevents one authenticated user from accessing another user's scan history through the client application.

Read-only Reference Data

Authenticated users can read:

  • waste_categories
  • disposal_guides
  • emission_factors

πŸ”„ Complete SmartSort Data Flow

The application now extends beyond simple image classification into a complete authenticated waste-management workflow.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      User        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Supabase Auth    β”‚
β”‚ Login / Signup   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ User UUID
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SmartSort        β”‚
β”‚ Scanner          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ Camera Image
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ FastAPI Backend  β”‚
β”‚ POST /predict    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ MobileNetV2      β”‚
β”‚ ML Inference     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Prediction +     β”‚
β”‚ Confidence       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Supabase         β”‚
β”‚ waste_records    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ RLS
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Dashboard   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β–Ό              β–Ό              β–Ό
Analytics    Distribution    History
  β”‚              β”‚              β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β–Ό
           User Insights

🧩 Application Routes

Route Purpose Authentication
/ AI waste scanner Required
/login User login Public
/signup User registration Public
/dashboard Personal waste analytics Required

🌐 Environment Configuration

Frontend

Create frontend/.env.local:

NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_supabase_publishable_key
NEXT_PUBLIC_API_URL=http://localhost:8000

For production, NEXT_PUBLIC_API_URL should point to the deployed Render backend.

Never commit private Supabase service-role keys or other server-side secrets to the repository.


πŸ§ͺ Current Application Capabilities

SmartSort currently supports the following end-to-end functionality:

  • βœ… User registration
  • βœ… User login
  • βœ… User logout
  • βœ… Protected application access
  • βœ… Camera-based waste capture
  • βœ… AI-powered waste classification
  • βœ… 12 waste classes
  • βœ… Confidence-based unknown filtering
  • βœ… Disposal guidance
  • βœ… Persistent user-specific scan records
  • βœ… Supabase PostgreSQL database
  • βœ… Row Level Security
  • βœ… Personalized dashboard
  • βœ… Waste distribution analytics
  • βœ… Recyclable item tracking
  • βœ… AI confidence analytics
  • βœ… Recorded quantity and weight
  • βœ… COβ‚‚ impact tracking
  • βœ… Recent scan history
  • βœ… Render backend deployment
  • βœ… Vercel frontend deployment

πŸ§ͺ Current Runtime Versions

Note: The System Architecture and Technical Stack sections above reflect the original project versions (Next.js 15 / Python 3.10). The current implementation has since been developed and tested with the versions below.

Component Version
Next.js 16.1.6
React 19.2.3
FastAPI 0.129.0
Python 3.12
TensorFlow 2.20.0
Keras 3.13.2
Supabase JS 2.112.3
Tailwind CSS 4.x

πŸ‘¨β€πŸ’» Team

Team Lead

Team Members

Department of Computer Science & Engineering, HKBKCE-VTU


🌍 Impact

SmartSort directly contributes to:

  • ♻️ Proper waste segregation at source β€” reducing contamination of recyclables
  • πŸ™οΈ Reduced landfill dependency β€” diverting recyclables and compostables away from dumps
  • πŸ“ˆ Improved recycling efficiency β€” by giving actionable, bin-specific guidance
  • πŸ€– AI-driven urban sustainability β€” aligning with BBMP's Smart City initiatives

♻️ Segregate Smart. Keep Bengaluru Clean.

⭐ Star this repo if you found it useful!

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages