Inspiration
Small neighborhood shops in Kenya (dukas) track stock on paper and reorder on guesswork. When multiple clerks or mobile-money callbacks claim the last unit at once, read-modify-write loops race and oversell physical shelf stock. Shopkeepers and customers also search inventory using Swahili and Sheng terms rather than formal English brand names.
What it does
DukaPulse combines a web Kiosk POS (Render) and an analytics dashboard (Streamlit) backed by FastAPI, PostgreSQL, and TimescaleDB:
- Race-proof checkouts: Atomic conditional SQL
UPDATE inventory SET current_stock = current_stock - :qty WHERE ... AND current_stock >= :qtypaired with aCHECK (current_stock >= 0)constraint andSELECT ... FOR UPDATErow locks for restocks. - Time-series telemetry: Stores 60 days of sales events in a 7-day chunk TimescaleDB hypertable with continuous aggregates (
hourly_sales_summary,daily_duka_analytics). - Swahili and Sheng semantic search: Serves
all-MiniLM-L6-v2(384 dimensions) via FastEmbed ONNX Runtime with vernacular expansion againstpgvector. - Demand forecasting: Benchmarks Seasonal-Naive against Holt Linear across all 14 catalog SKUs and selects Seasonal-Naive where it wins.
- Role-based access control: Verifies Auth0 RS256 JWKS tokens to redact wholesale margins from staff accounts and block unauthorized restocks with HTTP 403.
How I built it
- Backend: Python 3.12, FastAPI, Pydantic v2, SQLAlchemy 2.0, FastEmbed ONNX Runtime.
- Database: PostgreSQL and TimescaleDB hypertables with continuous aggregates and
pgvector. - Frontends: Vanilla HTML5/CSS3/JS Kiosk POS and Streamlit + Plotly analytics dashboard.
- Security and CI: Auth0 RS256 RBAC, Docker Compose, GitHub Actions, and 30 pytest checks.
Verified Benchmarks
- Concurrency test: 16 threads racing 10,000 checkout attempts against 1 unit of stock on real PostgreSQL resulted in 1 HTTP 200 claim, 9,999 HTTP 409
InsufficientStockErrorrejections, and 0 oversells. - Forecasting tournament: Seasonal-Naive beat Holt Linear on 14/14 products (1.012% to 5.433% MAPE vs 2.533% to 16.58% for Holt Linear).
- Semantic retrieval: Cosine similarity of 0.8611 for
unga ya ugali, 0.7743 formafuta ya kupika, and 0.6119 forsabuni ya kuoga.
Built With
- auth0
- docker
- fastapi
- onnx
- pgvector
- postgresql
- pytest
- python
- streamlit
- timescaledb