SavoryAI: AI-Powered Food Waste Prevention System Project Story

Inspiration

The staggering $218B annual food waste problem in the US food industry inspired SavoryAI. We discovered that:

  • 30-40% of restaurant stock becomes waste due to poor forecasting
  • Small cafes lose $25K+ yearly from overstocking perishables
  • Manual inventory methods fail to capture complex demand patterns like weather and day-of-week effects Inspired to build an accessible tool that could help small businesses reduce waste through better forecasting.

What it does

This app, SavoryAI, is an intelligent F&B inventory optimization platform that uses AI to predict demand, manage inventory, reduce waste, and optimize pricing for restaurants.

SavoryAI transforms food inventory management by:

  1. Predicting Demand / Sales Forecasting: Forecasting sales per menu item using historical data and AI
  2. Ingredient Mapping: Tracks what raw materials go into each menu item
  3. Optimizing Orders: Calculating exact ingredient quantities needed to minimize waste
  4. Tracking Waste: Comparing predicted vs actual ingredient usage with visual analytics
  5. Dynamic Pricing: Identifying waste hotspots and recommending promotion for menu items
  6. Order Recommendations: Suggests purchase quantities to minimize overstocking
  7. Manage Inventory : Smart tracking, order from supplier, and alert when stocks is near expiry date

How we built it

Frontend The user interface is built with React, leveraging TypeScript for type safety and improved developer experience. Vite serves as the build tool, providing fast development and optimized production builds. Styling is handled by Tailwind CSS, enabling rapid UI development with utility-first classes. Framer Motion is used for smooth animations and transitions, enhancing the user experience, while Lucide React provides a comprehensive set of customizable icons. Data visualization, particularly for analytics and forecasting, is powered by Chart.js, integrated with chartjs-adapter-date-fns for time-series data.

Backend The backend is a hybrid system, strategically distributing functionalities across different technologies:

Supabase Edge Functions (Deno/TypeScript): These serverless functions serve as the primary backend for core data operations. They handle direct interactions with the PostgreSQL database for managing inventory_items, menu_items, sales_data, and model_forecasts. This approach allows for highly scalable and performant API endpoints, especially for data-intensive tasks like fetching sales records or model predictions. Node.js (Express): A supplementary API server built with Node.js and Express handles various analytics endpoints (e.g., /analytics/waste-risk, /analytics/historical-waste) and integrations (e.g., /integrations/elevenlabs/speak). It also provides mock data for certain functionalities when direct database or external service connections are unavailable. Python (Flask): A Flask-based Python API is used for specific functionalities that might benefit from Python's ecosystem, such as initial mock data generation for waste risk and stock recommendations, and potentially for more complex machine learning models or data processing tasks that are better suited for Python libraries. Database PostgreSQL, managed through Supabase, serves as the central relational database. It stores all application data, including user profiles, inventory items, menu details, sales records, subscription information, and model training statuses and forecasts. Supabase provides real-time capabilities and robust data management features.

Authentication User authentication is handled by Supabase Auth, which provides secure user management, sign-up, sign-in, and session management functionalities. This integrates seamlessly with the frontend and backend components, ensuring secure access to user-specific data.

Payments and Subscriptions Stripe is integrated for handling all payment processing and subscription management. The application uses Stripe Checkout for a streamlined purchase flow and relies on Stripe webhooks to update subscription statuses in the Supabase database, ensuring features are unlocked or locked based on the user's active plan.

Data Flow The frontend communicates with the various backend components via API calls. For instance, fetching inventory data first attempts to call a Supabase Edge Function. If that fails or is not configured, it falls back to the Node.js/Express API. Similarly, model training and sales data uploads are primarily handled by dedicated Supabase Edge Functions. This layered approach provides flexibility, allowing specific services to be optimized for their respective tasks while maintaining a cohesive overall system.

Challenges we ran into

  1. Backend API Instability and Transition : I initially struggled with the Python Flask backend's inconsistent behavior, which often led to empty responses. This forced me to implement mock data fallbacks to keep the frontend functional. Ultimately, I decided to transition critical data operations, such as inventory management, menu items, sales data, and model forecasts, to Supabase Edge Functions to achieve better reliability and performance.

  2. Supabase Edge Function Integration and Data Retrieval : A significant challenge involved correctly implementing and debugging the Supabase Edge Functions. This included ensuring they returned accurate data, handled various query parameters (like date ranges and item IDs), and provided meaningful error messages instead of empty results. Specifically, retrieving historical forecasts for accuracy analysis required careful handling of prediction run timestamps and data alignment.

  3. Data Alignment for Analytics : For the analytics features, particularly the prediction accuracy chart, I faced a challenge in aligning historical sales data with past model forecasts. Often, there were "no common dates found" between the datasets, since the actual sales data comes before the predicted sales data. This required me to implement logic to create artificial overlaps or generate mock historical forecasts to enable meaningful comparisons.

  4. Subscription System Migration : I had to manage a substantial change in the application's subscription model, moving from a RevenueCat-based system to a direct Stripe integration. This involved updating the entire payment flow, subscription status checks, and feature gating logic.

  5. Implementing Robust Error Handling : A continuous challenge was ensuring graceful degradation and providing clear feedback to the user when API calls or data operations failed. This led me to extensively use try-catch blocks, implement loading states, and craft user-friendly error messages throughout the application.

Accomplishments that we're proud of

I've successfully built a comprehensive AI-powered inventory management system as I ever wanted and never thought that I could built a end to end app without completing a full stack development course, this was accelerated by Bolt's development environment. And also I've integrating advanced features like waste prediction, demand forecasting, and dynamic pricing. I've also implemented a robust subscription paywall with Stripe and developed a full-stack application using React, Node.js, Python, and Supabase.

What we learned

I've gained practical experience in several key areas:

Development is =! Production

Full-stack Development: Building a complete application using React for the frontend, Node.js and Python for backend APIs, and Supabase for database and authentication.

Database Management: Designing and interacting with a PostgreSQL database schema, including tables for users, subscriptions, inventory, menu items, sales data, and AI model forecasts.

API Integration: Developing and consuming RESTful APIs, and integrating with third-party services like Stripe for payments and Supabase Edge Functions for serverless logic.

Machine Learning Integration: Implementing data upload, triggering model training, and visualizing AI-powered demand forecasts and prediction accuracy.

Subscription & Authentication: Setting up user authentication and a subscription paywall using Stripe and Supabase.

Data Visualization & Analytics: Presenting complex data through various charts and dashboards for waste risk, stock recommendations, and sales performance.

Error Handling & Debugging: Implementing robust error handling, logging, and fallback mechanisms for API calls and application components.

What's next for SavoryAI

SavoryAI's immediate future focuses on enhancing its core intelligence and practical utility. Many functions are still being refined, and the next steps involve:

Refining Waste Metrics : Implementing advanced waste calculations by comparing predicted versus actual sales data. This will provide a more accurate measure of food waste. Additionally, calculating potential waste by analyzing the difference between individual inventory items and the predicted ingredient needs for menu items will offer deeper insights into potential losses.

Dynamic Pricing Implementation: Fully activating and integrating the dynamic pricing module, including robust rules, schedules, and comprehensive analytics. The overview section will also be brought to full functionality.

Real-world Integration: Connecting SavoryAI to a real-life Point-of-Sale (POS) system to enable seamless, real-time data exchange and operational impact.

Once these enhancements are complete, the goal is to test SavoryAI with my sister's F&B chain. This real-world application aims to significantly increase the model's prediction accuracy, directly leading to substantial cost savings through reduced food wastage and optimized inventory management. And also to look for any real world problems to my system to refine it further. Hopefully, after all this is achieved to my satisfaction, I'll then try to sell this system. Fingers cross!

Built With

Share this project:

Updates

posted an update

Link for csv sales data file (Download and upload into model training and view analytics): June Sales Data: https://docs.google.com/spreadsheets/d/1UoXIz7U7fU0t-7p6le0KXlkz1D2M33VTnW7JAMJEsQE/edit?usp=sharing Updated July Sales Data: https://docs.google.com/spreadsheets/d/1XtQ15AfnRMsy-aZGwi3YvFsNamOR6LId00ZKfIN4b4A/edit?usp=sharing

For convenience log in and use my account to view the functions of existing menu items and inventory items email: roygee.sj@gmail.com password: Aa112233

Instructions if you want to try out new account: Create a new account by signing up with email and password, and then log in. After logging in you may want to subscribe to the SavoryAI premium account by paying on a sandbox enviroment. Information for the payment of subscribing
Credit card number : 4242 4242 4242 4242 CVC : any 3 number Exp Data : Any future date

Log in or sign up for Devpost to join the conversation.