Case study 03Operations · Forecasting
Smart Inventory
An inventory system for small businesses: real-time stock, suppliers, sales, and role-based dashboards, with a Python forecasting layer that predicts restock dates and quantities for every item six months ahead.
- Role
- Team lead, team of three
- Context
- MCA project · 2024
- Stack
- PHP 8, MySQL, Python, scikit-learn, pandas, Plotly, Bootstrap 5
- Engineers, led by me
- 3
- Roles: admin, manager, employee
- 3
- Restock forecast for every item
- 6 mo
The problem
Businesses that track stock on paper or in spreadsheets find out they've run out when a customer asks. They needed one system that tracks every stock movement, keeps counts honest without manual reconciliation, and tells them what to reorder before it runs out.
The system
Admins, managers, and employees use a PHP 8 application with role-based dashboards. It writes stock movements and sales to MySQL with atomic updates. A separate Python job reads sales history, fits a regression per item, and writes restock forecasts that the app displays for a manager to review and save.
Hover, tap, or tab through a component to see why it's in the system.
Walk through it
A sale, and a restock forecast
Two paths through the system: the request that keeps stock honest, and the batch job that predicts what to reorder.
- Staffbrowser
- PHP approle guard
- MySQLinventory
- ForecastPython job
- Record sale: 2 units
- Check session
- Insert sale
- stock = stock − 2
- Updated stock
Press Play, or step through with the arrows (← → work too). Each step explains what happens and why.
Key decisions
- 01
A schema where every change has a history
A relational MySQL schema for items, suppliers, sales, predictions, and reports, with foreign keys whose delete rules are deliberate (a sale disappears with its item; an item outlives its supplier) and audit-log tables recording who did what to users and suppliers.
- 02
Stock moves in the database, not in PHP
Recording a sale decrements stock with a single atomic UPDATE in the same request, so two concurrent sales can't both read the old count. Sales and supplier writes use prepared statements.
- 03
Roles enforced on every page
Admin, Manager, and Employee roles. A shared guard runs on every request: employees record sales, while stock, suppliers, reports, and forecasts are restricted to admins and managers. Passwords are hashed with PHP's password_hash.
- 04
Forecasting kept out of the request path
A separate Python job aggregates monthly sales with pandas and fits a linear regression per item with scikit-learn, writing restock predictions and Plotly charts to files. The PHP app only reads the results, so a slow model can never slow a page down.
- 05
Guardrails, then a human decision
Items with less than two months of history are skipped and predictions are clamped to a sane range. A manager reviews the forecast before saving it, and saving skips any prediction already stored for that item and date.
- 06
Suppliers are never deleted by accident
Deleting a supplier hides it rather than removing it, and it can be restored. Permanent deletion is a separate, explicit action, so the items and purchase history tied to a supplier aren't lost to a misclick.
What shipped
- Real-time stock tracking with warehouse locations, movement history, and inventory valuation, plus sales, inventory, supplier, and financial reports with date ranges, export, and print-ready layouts.
- I led a team of three to deliver it, and the forecasting work became the basis of my research paper on inventory optimisation through predictive analysis.
- PHP 8
- MySQL
- Python
- scikit-learn
- pandas
- Plotly
- Bootstrap 5
Contact
Have something worth building? Let's talk.
A question about my work, an idea to pressure-test, or a role you think I'd fit. My inbox is open.