Skip to content

Sai-Prannav/StockSnap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inventory Management System

A feature-rich full-stack inventory management application with AI-powered image analysis capabilities. Built with FastAPI backend and React frontend, featuring mock computer vision analysis that can be easily replaced with real AI models.

Features

  • Store & Product Management: CRUD operations for stores and products
  • Image Upload & Analysis: Upload shelf photos with AI-powered detection and counting
  • Timeline Visualization: Interactive charts showing inventory trends over time
  • Mock AI Pipeline: Realistic dummy data structure ready for real model integration
  • Modern UI: Responsive React interface with Tailwind CSS
  • Local Storage: SQLite database with local file storage

Tech Stack

Backend

  • FastAPI: Modern Python web framework
  • SQLAlchemy: ORM with SQLite database
  • Pillow: Image processing
  • Mock Image Analyzer: Simulates computer vision pipeline

Frontend

  • React 18: Modern UI framework
  • TypeScript: Type-safe development
  • Vite: Fast build tool
  • Tailwind CSS: Utility-first styling
  • Recharts: Data visualization
  • Axios: HTTP client
  • Lucide React: Icon library

Project Structure

project-root/
├── backend/
│   ├── main.py               # FastAPI app entry point
│   ├── app/
│   │   ├── models/          # SQLAlchemy models
│   │   ├── schemas/         # Pydantic schemas
│   │   ├── routers/         # API endpoints
│   │   ├── services/        # Business logic
│   │   └── database.py     # DB configuration
│   └── requirements.txt     # Python dependencies
├── frontend/
│   ├── src/
│   │   ├── components/      # React components
│   │   ├── pages/          # Page components
│   │   ├── services/        # API services
│   │   └── types/          # TypeScript types
│   ├── package.json         # Node dependencies
│   └── vite.config.ts      # Vite configuration
├── uploads/                # Image storage (created automatically)
├── app.db                  # SQLite database (created automatically)
└── README.md

Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm or yarn

Backend Setup

  1. Navigate to backend directory:

    cd backend
  2. Create and activate virtual environment:

    python -m venv .venv
    .venv\Scripts\activate  # On Windows
    # or
    source .venv/bin/activate  # On macOS/Linux
  3. Install dependencies:

    pip install -r requirements.txt
  4. Start the backend server:

    python main.py

    The API will be available at http://localhost:8000

Frontend Setup

  1. Navigate to frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

    The frontend will be available at http://localhost:5173

Usage

1. Add Stores and Products

  • Navigate to the Dashboard
  • Use the quick action buttons to add stores and products
  • Or access the API directly at http://localhost:8000/docs

2. Upload and Analyze Images

  • Go to the Upload page
  • Select a store and product
  • Upload a shelf photo
  • The system will run mock analysis and show results:
    • Item count (1-30 items)
    • Confidence score (75-98%)
    • Bounding boxes for detected objects
    • Segmentation masks (optional)

3. View Timeline Data

  • Visit the Timeline page
  • Filter by store and/or product
  • View interactive charts showing:
    • Daily inventory counts
    • Confidence trends
    • Statistical summaries

API Endpoints

Stores

  • GET /api/stores/ - List all stores
  • POST /api/stores/ - Create store
  • GET /api/stores/{id} - Get store
  • PUT /api/stores/{id} - Update store
  • DELETE /api/stores/{id} - Delete store

Products

  • GET /api/products/ - List all products
  • POST /api/products/ - Create product
  • GET /api/products/{id} - Get product
  • PUT /api/products/{id} - Update product
  • DELETE /api/products/{id} - Delete product

Scans

  • GET /api/scans/ - List scans with filters
  • POST /api/scans/ - Upload image and create scan
  • GET /api/scans/{id} - Get scan details
  • DELETE /api/scans/{id} - Delete scan

Timeline

  • POST /api/timeline/data - Get timeline data
  • GET /api/timeline/stats - Get statistics
  • GET /api/timeline/summary - Get summary data

Mock AI Analysis

The system includes a sophisticated mock image analyzer that simulates real computer vision results:

# Example mock output
{
    "count": 15,
    "confidence": 0.92,
    "bounding_boxes": [
        {
            "x1": 0.1, "y1": 0.2,
            "x2": 0.3, "y2": 0.4,
            "label": "product",
            "confidence": 0.95
        }
        // ... more detections
    ],
    "segmentation_masks": [
        {
            "mask_type": "polygon",
            "mask_data": [{"points": [...]}],
            "label": "product",
            "confidence": 0.88
        }
        // ... more masks
    ]
}

Replacing with Real AI

To integrate a real AI model:

  1. Replace the MockImageAnalyzer class in backend/app/services/image_analyzer.py

  2. Implement the ImageAnalyzer interface:

    class RealImageAnalyzer(ImageAnalyzer):
        async def analyze_image(self, image_path: str) -> AnalysisResult:
            # Your real AI logic here
            pass
  3. Update the import in backend/app/routers/scans.py:

    from app.services.image_analyzer import RealImageAnalyzer
    image_analyzer = RealImageAnalyzer()

Database Schema

Stores

  • id, name, location, description, timestamps

Products

  • id, name, sku, description, category, timestamps

Scans

  • id, store_id, product_id, image_path, count, confidence, timestamps

Detections

  • id, scan_id, bounding box coordinates, label, confidence

SegmentationMasks

  • id, scan_id, mask_type, mask_data, label, confidence

Development

Running Tests

# Backend tests (when implemented)
cd backend
pytest

# Frontend tests (when implemented)
cd frontend
npm test

Code Quality

# Backend linting
cd backend
flake8 app/

# Frontend linting
cd frontend
npm run lint

Troubleshooting

Backend Issues

  1. Database not found: The SQLite database is created automatically on first run
  2. Port 8000 in use: Change the port in main.py
  3. Dependencies missing: Ensure virtual environment is activated

Frontend Issues

  1. Port 5173 in use: Vite will automatically find an available port
  2. API connection failed: Ensure backend is running on port 8000
  3. Dependencies missing: Run npm install in frontend directory

Common Issues

  • CORS errors: The backend is configured for localhost:5173
  • Image upload fails: Check file size and format restrictions
  • Timeline empty: Upload some scans first to generate data

Production Deployment

Backend

  1. Use a production WSGI server like Gunicorn:

    pip install gunicorn
    gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
  2. Configure environment variables for production

  3. Set up proper file storage permissions

Frontend

  1. Build for production:

    npm run build
  2. Deploy the dist/ folder to your web server

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.

Future Enhancements

  • Real AI model integration (YOLO, SAM, etc.)
  • User authentication and authorization
  • Advanced filtering and search
  • Export functionality (CSV, PDF reports)
  • Real-time notifications
  • Mobile app
  • Cloud deployment options
  • Advanced analytics dashboard
  • Integration with external inventory systems

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors