Skip to content

nxd010/Shelfies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ Shelfies - AI-Powered Inventory Management System

An intelligent inventory management system that uses YOLOv8 object detection to automatically identify and track products through image scanning.

Tech Stack Flask React YOLOv8


🌟 Features

  • AI-Powered Detection - Custom-trained YOLOv8 model recognizes 294 different products
  • Real-Time Analytics - Interactive dashboard with charts and statistics
  • Persistent Storage - SQLite database for reliable data management
  • Smart Search - Filter and search products by name or category
  • Inventory Tracking - Monitor stock levels and scan history
  • 13 Product Categories - Organized classification system
  • RESTful API - Clean API design for easy integration

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React UI      β”‚ ──────> β”‚   Flask API      β”‚ ──────> β”‚  YOLOv8     β”‚
β”‚  (Frontend)     β”‚ <────── β”‚   (Backend)      β”‚ <────── β”‚   Model     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                                     β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  SQLite DB      β”‚
                            β”‚  (Persistence)  β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Tech Stack

Backend

  • Flask - Lightweight web framework
  • SQLAlchemy - Database ORM
  • YOLOv8 (Ultralytics) - Object detection model
  • Pillow - Image processing
  • SQLite - Database
  • uv - Dependency management

Frontend

  • React - UI framework
  • Tailwind CSS - Styling
  • Chart.js - Data visualization
  • Axios - HTTP client
  • Vite - Build tool

AI/ML

  • YOLOv8 - Custom-trained on 294 product classes
  • NumPy - Numerical operations

πŸ“¦ Installation

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • pip & npm

1. Clone the Repository

git clone https://github.com/nxd010/Shelfies.git
cd shelfies

2. Backend Setup

# Navigate to backend
cd backend

# Create virtual environment (uv recommended)
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
uv add -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env if needed

# Initialize database
uv run python init_db.py

# Run the server
uv run python app.py

Backend will run on http://localhost:5000

3. Frontend Setup

# Navigate to frontend (in a new terminal)
cd frontend

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env if needed (set VITE_API_URL=http://localhost:5000/api)

# Run development server
npm run dev

Frontend will run on http://localhost:5173


🐳 Docker Support

You can run the entire application using Docker Compose.

Prerequisites

  • Docker and Docker Compose installed

Run with Docker

# Build and start services
docker compose up --build -d

# View logs
docker compose logs -f

# Stop services
docker compose down

The application will be available at:


🎯 Usage

1. Access the Application

Open your browser and navigate to http://localhost:5173

2. Scan Products

  • Go to the Scanning page
  • Upload an image of a product or use your webcam
  • Click Process Image
  • The system will detect the product and update inventory automatically

3. View Dashboard

  • See real-time statistics (total products, categories, low stock alerts)
  • View category distribution chart
  • Monitor recently scanned products

4. Manage Inventory

  • Navigate to Database page
  • Search and filter products
  • View current stock levels
  • Manually adjust counts if needed

πŸ”Œ API Endpoints

Product Detection

POST /api/detect
Content-Type: application/json

{
  "image": "base64_encoded_image_data"
}

Get All Products

GET /api/products
GET /api/products?category=Snacks
GET /api/products?search=cola

Get Statistics

GET /api/stats

Update Product

PUT /api/products/{id}
Content-Type: application/json

{
  "count": 10
}

Scan History

GET /api/history?limit=50

Health Check

GET /api/health

πŸ—‚οΈ Project Structure

shelfies/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py              # Main Flask application
β”‚   β”œβ”€β”€ models.py           # Database models
β”‚   β”œβ”€β”€ config.py           # Configuration management
β”‚   β”œβ”€β”€ utils.py            # Helper functions
β”‚   β”œβ”€β”€ init_db.py          # Database initialization
β”‚   β”œβ”€β”€ requirements.txt    # Python dependencies
β”‚   β”œβ”€β”€ .env.example        # Environment template
β”‚   β”œβ”€β”€ data/               # SQLite database (auto-generated)
β”‚   └── models/
β”‚       └── best.pt         # YOLOv8 trained model
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/     # React components
β”‚   β”‚   β”œβ”€β”€ pages/          # Page components
β”‚   β”‚   β”œβ”€β”€ utils/          # Utility functions
β”‚   β”‚   └── App.jsx         # Main app component
β”‚   β”œβ”€β”€ package.json        # Node dependencies
β”‚   └── .env.example        # Environment template
β”‚
└── README.md               # This file

πŸŽ“ Product Categories

The system classifies products into 13 categories:

  1. 🐟 Seafood & Meat Products
  2. πŸ₯› Dairy & Milk Products
  3. πŸ₯€ Beverages (Non-Alcoholic)
  4. 🍎 Fruits
  5. πŸ₯¬ Vegetables
  6. 🍫 Snacks & Confectionery
  7. 🍜 Instant Foods & Noodles/Pasta
  8. 🍞 Bakery & Pastries
  9. πŸ§‚ Sauces, Condiments & Seasonings
  10. πŸ₯£ Cereals
  11. πŸ₯š Eggs & Tofu
  12. πŸ„ Mushrooms
  13. 🍺 Alcoholic Beverages

πŸ”§ Configuration

Backend Configuration (backend/.env)

# Flask settings
FLASK_DEBUG=True
SECRET_KEY=your-secret-key

# Database
DATABASE_URL=sqlite:///data/inventory.db

# Model settings
MODEL_PATH=./models/best.pt
CONFIDENCE_THRESHOLD=0.1

# CORS
CORS_ORIGINS=http://localhost:5173

Frontend Configuration (frontend/.env)

VITE_API_URL=http://localhost:5000/api

πŸ§ͺ Testing the System

Test Product Detection

# Using curl
curl -X POST http://localhost:5000/api/detect \
  -H "Content-Type: application/json" \
  -d '{"image": "BASE64_IMAGE_DATA"}'

Test Database Queries

# Get all products
curl http://localhost:5000/api/products

# Get stats
curl http://localhost:5000/api/stats

# Health check
curl http://localhost:5000/api/health

πŸ› Troubleshooting

Backend Issues

Problem: ModuleNotFoundError: No module named 'flask_sqlalchemy'

# Solution: Install dependencies
pip install -r requirements.txt

Problem: Database errors

# Solution: Reinitialize database
rm -rf data/inventory.db
python3 init_db.py

Problem: Model not found

# Solution: Verify model path
ls -la models/best.pt
# Update MODEL_PATH in .env if needed

Path-Related Issues

Problem: sqlite3.OperationalError or FileNotFoundError on Flask reloader restart

Root Cause: The Flask development server uses a reloader that changes the working directory context, causing relative paths to break.

Solution: The application now uses absolute paths automatically. Ensure these lines are commented out in backend/.env:

# DATABASE_URL=sqlite:///data/inventory.db  # Relative path - don't use
# MODEL_PATH=./models/best.pt              # Relative path - don't use

The code in backend/config.py will automatically resolve absolute paths for you.

Verification:

cd backend
python3 app.py
# Should see: 
# Base Directory: /absolute/path/to/backend
# Database URI: sqlite:////absolute/path/to/backend/data/inventory.db
# Model Path: /absolute/path/to/backend/models/best.pt

Frontend Issues

Problem: API connection errors

# Solution: Check backend is running and CORS is configured
# Verify VITE_API_URL in frontend/.env

Problem: npm install fails

# Solution: Clear cache and retry
npm cache clean --force
rm -rf node_modules package-lock.json
npm install

πŸ“Š Database Schema

Products Table

CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    name VARCHAR(200) UNIQUE NOT NULL,
    category VARCHAR(100) NOT NULL,
    class_id INTEGER NOT NULL,
    count INTEGER DEFAULT 0,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    last_updated DATETIME DEFAULT CURRENT_TIMESTAMP
);

Scan History Table

CREATE TABLE scan_history (
    id INTEGER PRIMARY KEY,
    product_id INTEGER NOT NULL,
    confidence FLOAT NOT NULL,
    scanned_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (product_id) REFERENCES products(id)
);

🚧 Known Limitations

  • Model Accuracy: Current model is a proof-of-concept with moderate accuracy (~35-45%). Production deployment would require additional training data and fine-tuning.
  • Single User: No authentication system; designed for single-user scenarios
  • Local Only: Runs on localhost; deployment configuration needed for production
  • Image Size: Limited to 16MB file uploads

πŸ“Έ Screenshots

Dashboard

Dashboard Real-time inventory statistics and analytics

Product Scanning

Scanning AI-powered product detection interface

Database View

Database Comprehensive inventory management


πŸ’‘ About This Project

This project was built as a demonstration of:

  • Full-stack web development (React + Flask)
  • Machine learning deployment (YOLOv8)
  • Database design and management
  • RESTful API design
  • Modern development practices

About

An AI based Store Inventory Management System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors