Note : Docker must installed and running in the system
cd [PATH TO PROJECT]
docker-compose down && docker-compose up
Note : I am learning about Software Development, Devops and AI from this book. Here is the book link : https://www.amazon.com/dp/B0F1Z4LDDH (50 microsaas startup ideas)
To design a system for calculating wasted food in a restaurant, we’ll create a model that takes grocery quantities and the number of plates sold as inputs. The goal is to compare the quantity of food ordered with the quantity of food actually used, calculating the waste based on any discrepancies.
Here's a software design approach to achieve this:
-
Requirements Analysis
Functional Requirements
Accept user input for groceries ordered (type and quantity).
Track the number of plates sold.
Calculate and display the quantity of wasted food.
Provide reporting and analytics, including summaries by day, week, or month.
Non-Functional Requirements
Usability: Interface should be simple and intuitive for restaurant staff to input data.
Scalability: Design should support multiple restaurants or outlets.
Performance: Calculations should be quick and responsive.
Security: Data should be secured as it may contain sensitive information about food costs. -
Data Model
Define the entities and their relationships.
Fields: orderId, item, quantityOrdered, date
Description: Represents an order of groceries, including item name, quantity ordered, and order date.
PlateSales
Fields: salesId, plateType, quantitySold, date
Description: Represents the number of plates sold for each plate type on a particular date.
WastedFood
Fields: wasteId, item, quantityWasted, date
Description: Stores the calculated amount of food waste per item on each date.
FoodUsageRate (optional, configurable)
Fields: item, averageUsagePerPlate
Description: Contains predefined values indicating the average usage of a specific item per plate. Used for estimating expected food usage.
- System Workflow
Input Data:
Staff inputs daily grocery quantities ordered (by item).
Staff inputs daily sales data (number of plates sold by type).
Calculate Expected Food Usage:
Multiply the number of plates sold by the average quantity of each grocery item expected per plate.
For example, if each plate uses 100g of rice and 50 plates are sold, the expected rice usage is 50 * 100g = 5000g.
Calculate Wasted Food:
Compare the quantityOrdered (from GroceryOrder) with quantityUsed (calculated from PlateSales and FoodUsageRate).
Waste is calculated as:
quantityWasted
quantityOrdered
−
quantityUsed
quantityWasted=quantityOrdered−quantityUsed
Save Waste Data:
Store the calculated waste data in the WastedFood entity.
Generate Reports:
Generate reports to view wasted food by date, item, or period (e.g., weekly, monthly).
Optional: Display trends in waste reduction over time.
4. High-Level Architecture
Components:
User Interface (UI): Provides forms for inputting grocery orders and plate sales, as well as a dashboard for waste reporting.
Backend Service: A REST API built with Java Spring Boot or FastAPI to handle CRUD operations and calculations.
Database: A relational database (e.g., PostgreSQL) to store GroceryOrder, PlateSales, WastedFood, and FoodUsageRate tables.
Analytics and Reporting: Basic reporting views and charts (using libraries like Chart.js) or more complex reporting through Grafana.
5. Data Flow Diagram
Here’s a basic data flow:
Data Entry: Staff enters GroceryOrder and PlateSales data via the UI.
Data Processing:
Backend service retrieves daily data and performs the Expected Food Usage calculation.
Backend service computes WastedFood and stores the results.
Display Results: The system displays waste metrics on the UI, with daily/weekly/monthly breakdowns.
6. Tech Stack
Backend: Java Spring Boot (or Python FastAPI)
Database: PostgreSQL or MySQL
Frontend: React or Angular for user interface and reporting dashboard
Reporting: Chart.js for visualizations, Grafana for advanced analytics
Hosting: Docker and Kubernetes for deployment in a cloud environment like AWS or Azure
7. Sample API Endpoints
Grocery Orders
POST /api/groceries: Add a grocery order
GET /api/groceries/{date}: Get grocery orders for a specific date
Plate Sales
POST /api/sales: Record plates sold
GET /api/sales/{date}: Retrieve plate sales data for a specific date
Waste Calculation
GET /api/waste/{date}: Retrieve calculated waste for a given date
GET /api/waste/report?start={date}&end={date}: Retrieve waste report over a range of dates
8. Example Calculation
Input:
Grocery Order: Rice = 6000g
Plates Sold: 50
Average Rice Per Plate: 100g
Expected Usage:
50 plates * 100g = 5000g
Waste Calculation:
Waste = 6000g - 5000g = 1000g
This data is stored in the WastedFood table and can be reported daily or periodically to help the restaurant track and minimize waste over time.