Skip to content
Β 
Β 

Latest commit

Β 

History

108 Commits

Folders and files

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

Repository files navigation

πŸ“¦ πŸ₯— NutriScan: Packaged Food QR & Barcode Nutrition Scanner

NutriScan Packaged Food QR Code Scanner

React Vite Node.js Express.js MongoDB TailwindCSS License: MIT

NutriScan is an AI-powered smart nutrition scanner built to instantly analyze packaged food items (such as packaged snacks, cereals, canned foods, beverages, chocolates, and packaged grocery items) by scanning their QR codes or 1D/2D barcodes.

With a single camera scan of any packaged food item, NutriScan instantly decodes complex nutrition labels, calculates official NutriScore grades (A to E), flags hidden toxic additives (palm oil, HFCS, sodium), evaluates personalized age-aware health risks, and recommends healthier packaged food swaps.


πŸš€ Quick Links & Live Deployments

Resource URL Description
🌐 Web Application nutriscan-food.vercel.app Production Frontend hosted on Vercel
βš™οΈ Backend API nutriscan-6okf.onrender.com Live Express.js REST API on Render
πŸ“„ Postman API Docs Postman Collection Complete API Endpoint Documentation
🎨 Figma UI Prototype View Design Interactive UI/UX Design System
πŸ“Ί Demo Video Watch Video App Walkthrough & Features Demo

πŸ“± App Interface Preview

NutriScan App Screen Clean, modern, and accessible packaged food health analytics dashboard.


πŸ’‘ How Packaged Food QR Scanning Works: Complete Flow

NutriScan captures QR codes & 1D/2D barcodes on packaged food items and passes them through a cascading multi-tier database strategy.

flowchart TD
    subgraph Step1 ["πŸ“· 1. Packaged Food Capture"]
        A[Scan Packaged Food QR Code / Barcode via Camera]
        B[Manual Numeric Barcode Entry]
        C[Packaged Food Search Query]
    end

    subgraph Step2 ["πŸ” 2. Cascading Data Fetching Strategy"]
        D{MongoDB Cache Hit?}
        E{Local Indian Packaged Snacks JSON Hit?}
        F[Query Open Food Facts Global API]
        G[Save & Cache to MongoDB Database]
    end

    subgraph Step3 ["🧠 3. Packaged Food Health Engine"]
        H["NutriScore Service (A–E Grade)"]
        I["Age-Aware Risk Engine (Child / Adult / Senior)"]
        J["Additive Radar (Palm oil, HFCS, E-numbers)"]
        K["Healthy Packaged Food Swaps Generator"]
    end

    subgraph Step4 ["πŸ“Š 4. Interactive Health Dashboard"]
        L[Grade Badge & Nutritional Radar]
        M[Personalized Health & Risk Alerts]
        N[Daily Sugar & Calorie Log Tracker]
        O[Healthier Packaged Alternatives]
    end

    A --> D
    B --> D
    C --> D
    D -- Yes --> H
    D -- No --> E
    E -- Yes --> H
    E -- No --> F
    F --> G
    G --> H
    H --> I
    I --> J
    J --> K
    K --> L
    K --> M
    K --> N
    K --> O
Loading

Data Pipeline & Cascading Fallback Mechanics

sequenceDiagram
    autonumber
    actor User
    participant Frontend as React Frontend
    participant Backend as Express REST API
    participant Mongo as MongoDB Cache
    participant LocalData as Local Snacks DB
    participant OFF as Open Food Facts API

    User->>Frontend: Scan Packaged Food QR / Barcode
    Frontend->>Backend: GET /api/scan/barcode?barcode=XYZ
    
    Note over Backend,Mongo: Step 1: Check MongoDB Cache
    Backend->>Mongo: Query product document by barcode
    Mongo-->>Backend: Return cached product document (if HIT)

    Note over Backend,LocalData: Step 2: Check Local Database
    Backend->>LocalData: Fallback query to indianSnacks.json
    LocalData-->>Backend: Return local product document (if HIT)

    Note over Backend,OFF: Step 3: Fetch External API
    Backend->>OFF: Fetch from Open Food Facts REST API
    OFF-->>Backend: Return raw food nutritional data
    Backend->>Mongo: Cache fetched product document in MongoDB

    Note over Backend: Step 4: Run Health Analysis Engines
    Backend->>Backend: Calculate NutriScore (A to E Grade)
    Backend->>Backend: Evaluate Age-Aware Health Risk (Child / Adult / Senior)
    Backend->>Backend: Scan Ingredients for Toxic Additives & Preservatives
    Backend->>Backend: Generate Healthier Packaged Alternatives

    Backend-->>Frontend: Return analyzed product JSON payload
    Frontend->>User: Display grade, warnings, charts & swaps
Loading

πŸ”₯ Key Features & Technical Capabilities

πŸ“· 1. Instant Packaged Food QR Code & Barcode Scanner

  • Built with @zxing/library (BrowserMultiFormatReader).
  • Uses HTML5 video stream to decode standard 1D barcodes (EAN-13, EAN-8, UPC) and 2D QR codes on packaged food boxes, bags, cans, and bottles in real-time.
  • Features a camera overlay with animated scanning lines and manual numeric entry fallback.

πŸ† 2. French NutriScore A–E Rating for Packaged Foods

  • Implements an automated NutriScore calculator based on European dietary standards for packaged food evaluation.
  • Evaluates negative points (Energy in kJ, Sugars, Saturated Fats, Sodium per 100g) against positive points (Dietary Fiber, Proteins).
  • Outputs clear letter grades (A, B, C, D, E) with color-coded visual indicators.

🎯 3. Age-Aware Personalized Health Risk Engine

  • Dynamically adjusts nutrient danger thresholds based on user age bracket:
    • Child: Stricter sugar (<5g–10g) and fat limits.
    • Adult: Standard daily intake limits.
    • Senior: Stricter sodium (<400mg) and saturated fat constraints.
  • Generates actionable warnings such as "High diabetes + obesity risk" or "Heart & kidney risk".

⚠️ 4. Packaged Food Additive & Preservative Radar

  • Scans packaged food ingredient lists for artificial preservatives, trans fats, high-fructose corn syrup (HFCS), palm oil, and harmful E-number food additives.

πŸ”„ 5. Healthier Packaged Swaps & Alternatives Engine

  • Automatically searches for higher-rated food alternatives within the same packaged food category, providing healthier choices when grocery shopping.

πŸ“Š 6. Daily Packaged Intake Tracker

  • Logs scanned packaged products to session history.
  • Calculates total sugar, sodium, fat, and calories consumed against WHO/AHA daily recommended limits (e.g., 25g max daily sugar).
  • Renders 7-day trend charts powered by Chart.js.

πŸ› οΈ Tech Stack & Dependencies

Frontend (/frontend)

  • Framework: React 19, Vite
  • Styling & UI: Tailwind CSS, Lucide React icons
  • Barcode Scanning: @zxing/library
  • Data Visualization: chart.js, react-chartjs-2

Backend (/backend)

  • Runtime: Node.js, Express.js REST API
  • Database & ORM: MongoDB, Mongoose
  • Fuzzy Search: Fuse.js (for fast local food search with typo tolerance)
  • External Integration: Open Food Facts REST API

πŸ“‚ Project Directory Structure

nutriscan/
β”œβ”€β”€ frontend/                     # React + Vite Frontend Application
β”‚   β”œβ”€β”€ public/                   # Static assets & health banner
β”‚   β”‚   β”œβ”€β”€ health-banner.jpg
β”‚   β”‚   └── image.png
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/           # Modular UI Components
β”‚   β”‚   β”‚   β”œβ”€β”€ Scanner.jsx       # Camera Barcode Scanner component (@zxing/library)
β”‚   β”‚   β”‚   β”œβ”€β”€ NutritionCard.jsx # Nutrient radar & metric breakdown
β”‚   β”‚   β”‚   β”œβ”€β”€ NutriScoreBadge.jsx # Grade A–E badge indicator
β”‚   β”‚   β”‚   β”œβ”€β”€ RiskBadge.jsx     # Health risk warning card
β”‚   β”‚   β”‚   β”œβ”€β”€ Alternatives.jsx  # Healthier swap recommendations
β”‚   β”‚   β”‚   β”œβ”€β”€ DailySugarTracker.jsx # Daily consumption tracker
β”‚   β”‚   β”‚   β”œβ”€β”€ WeeklySugarChart.jsx  # Chart.js weekly sugar graph
β”‚   β”‚   β”‚   β”œβ”€β”€ ManualEntry.jsx   # Manual barcode & search entry
β”‚   β”‚   β”‚   β”œβ”€β”€ HistoryView.jsx   # Past scan history list
β”‚   β”‚   β”‚   └── ProfilePage.jsx   # User profile & age group settings
β”‚   β”‚   β”œβ”€β”€ App.jsx               # Primary application layout & router
β”‚   β”‚   └── main.jsx              # React application entry point
β”‚   └── package.json
β”‚
β”œβ”€β”€ backend/                      # Node.js + Express.js REST Backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/               # Database connection (MongoDB)
β”‚   β”‚   β”œβ”€β”€ controllers/          # Route Request Controllers
β”‚   β”‚   β”‚   β”œβ”€β”€ scan.controller.js # Barcode scan & search logic
β”‚   β”‚   β”‚   β”œβ”€β”€ analyse.controller.js # Manual product evaluation
β”‚   β”‚   β”‚   β”œβ”€β”€ alternatives.controller.js # Healthy swap finder
β”‚   β”‚   β”‚   └── history.controller.js # User scan logs & summaries
β”‚   β”‚   β”œβ”€β”€ services/             # Core Analytical Engines
β”‚   β”‚   β”‚   β”œβ”€β”€ nutriScore.service.js # Official NutriScore A–E algorithm
β”‚   β”‚   β”‚   β”œβ”€β”€ risk.service.js   # Age-aware health risk evaluation
β”‚   β”‚   β”‚   β”œβ”€β”€ ingredient.service.js # Additive & warning scanner
β”‚   β”‚   β”‚   β”œβ”€β”€ alternatives.service.js # Healthier substitute matching
β”‚   β”‚   β”‚   └── scan.service.js   # DB scan persistence & summaries
β”‚   β”‚   β”œβ”€β”€ models/               # Mongoose Schemas (Product, Scan, User)
β”‚   β”‚   β”œβ”€β”€ data/                 # Local Indian snacks fallback database
β”‚   β”‚   β”‚   └── indianSnacks.json
β”‚   β”‚   β”œβ”€β”€ routes/               # Express API Route definitions
β”‚   β”‚   └── app.js                # Express app setup & middleware
β”‚   β”œβ”€β”€ index.js                  # Backend server entry point
β”‚   └── package.json
β”‚
└── README.md                     # Project documentation

⚑ API Endpoint Reference

Method Endpoint Description
GET /api/scan/barcode?barcode={code} Fetch product by barcode (MongoDB -> Local -> OpenFoodFacts)
GET /api/scan/search?q={query} Search products by name using OpenFoodFacts + Fuse.js
POST /api/scan/analyse Analyze manually entered nutritional values
GET /api/scan/alternatives?category={cat} Get healthier product alternatives
GET /api/scan/history?sessionId={id} Retrieve recent scan history for user session
GET /api/scan/summary/daily?sessionId={id} Get daily accumulated nutrient consumption summary
GET /api/scan/summary/weekly?sessionId={id} Get 7-day sugar intake history for charting

πŸš€ Setup & Installation Guide

Prerequisites

  • Node.js (v18+)
  • npm or yarn
  • MongoDB Atlas database URI or local MongoDB instance

1. Environment Configuration

Create a .env file inside the backend/ directory:

PORT=3001
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/nutriscan?retryWrites=true&w=majority
JWT_SECRET=your_super_secret_jwt_key
OPEN_FOOD_FACTS_API=https://world.openfoodfacts.org/api/v0

2. Start the Backend API Server

cd backend
npm install
npm run dev # Starts server on http://localhost:3001

3. Start the Frontend Development Server

cd frontend
npm install
npm run dev # Starts Vite server on http://localhost:5173

πŸ“œ Repository Documentation & Governance

To maintain open-source transparency, security, and community governance, NutriScan includes standard repository documentation:

Document Description Link
πŸ“œ License MIT Open Source License LICENSE
πŸ“œ Code of Conduct Community pledge and standards (Contributor Covenant v2.1) CODE_OF_CONDUCT.md
πŸ›‘οΈ Security Policy Vulnerability reporting procedure & security practices SECURITY.md

πŸ›‘οΈ Security & Privacy

We treat security and user privacy as top priorities. If you discover a vulnerability or security issue, please review our Security Policy to report it responsibly.


πŸ“œ License

Distributed under the MIT License. See LICENSE for more information.


Developed with ❀️ for a healthier lifestyle by Harshit Kumar.

About

Nutriscan is a cutting-edge web application designed to empower users with deep insights into their food choices. By scanning labels and analyzing ingredients against personal health profiles, it acts as a digital nutritionist in your pocket.

Topics

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages