โ˜• Brewlytics โ€” Cafรฉ Business Digital Twin

Hackathon 2026 โ€” Simulate pricing changes, staffing decisions, and growth scenarios before committing a single dollar.

Python React FastAPI NumPy


๐Ÿ“Œ What Is This?

Brewlytics is a Digital Twin simulation engine for cafรฉs and small food businesses.

Instead of guessing whether raising prices or hiring staff is a good idea, Brewlytics runs Monte Carlo simulations of entire business days using a stochastic discrete-event simulation (DES) model.

The system predicts full distributions of outcomes rather than a single forecast.

It answers questions like

  • What happens if I raise latte prices by 10%?
  • Should I hire another barista during lunch rush?
  • Will a 20% cold drink discount increase profit or hurt margins?

Each scenario simulates hundreds of possible business days and reports:

  • Revenue distribution (P5โ€“P95)
  • Profit distribution
  • Wait time distribution
  • Abandonment rate
  • Per-product demand changes

๐ŸŽฏ Key Features

๐Ÿ“Š Monte Carlo Business Simulation

Runs hundreds of simulated days to produce risk distributions.

๐Ÿง  AI Hypothesis Builder

Users can type natural language scenarios:

โ€œRun a 20% discount on cold drinks Friday afternoonsโ€

GPT converts this into a simulation configuration automatically.

๐Ÿงฎ Queue + Demand Modeling

Captures realistic operational dynamics:

  • Customer arrivals
  • Queue waiting
  • Purchase behavior
  • Abandonment when waits are too long

๐Ÿ“ฆ Product-Level Insights

Shows which products gain or lose sales under pricing changes.


๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      HTTP/JSON       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   React Frontend     โ”‚ โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ โ”‚   FastAPI Backend             โ”‚
โ”‚   (Vite + TypeScript)โ”‚                      โ”‚                                โ”‚
โ”‚                      โ”‚                      โ”‚  โ€ข Monte Carlo Engine         โ”‚
โ”‚  โ€ข Hypothesis Lab    โ”‚    POST /simulate    โ”‚  โ€ข Discrete Event Simulation  โ”‚
โ”‚  โ€ข AI Chat           โ”‚    POST /compare     โ”‚  โ€ข Queue Model (M/G/c)        โ”‚
โ”‚  โ€ข Sliders           โ”‚    GET  /baseline    โ”‚  โ€ข NHPP Arrival Model         โ”‚
โ”‚  โ€ข Results Dashboard โ”‚    GET  /products    โ”‚  โ€ข Multinomial Logit Demand   โ”‚
โ”‚                      โ”‚                      โ”‚                                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‚ Project Structure

Brewlytics/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ server.py
โ”‚   โ”œโ”€โ”€ simulation.py
โ”‚   โ”œโ”€โ”€ distributions.py
โ”‚   โ”œโ”€โ”€ scenario_builder.py
โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ””โ”€โ”€ config.py
โ”‚
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ api.ts
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Landing.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Simulator.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Results.tsx
โ”‚   โ”‚   โ””โ”€โ”€ components/
โ”‚
โ””โ”€โ”€ README.md

๐Ÿš€ Running the Project

Backend

cd backend
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn server:app --reload

Backend runs at:

http://localhost:8000

Docs:

http://localhost:8000/docs

Frontend

cd frontend
npm install
npm run dev

Frontend runs at:

http://localhost:5173

๐Ÿง  Statistical Model

The simulation models a cafรฉ using four coupled stochastic processes.

Symbol Component Distribution
C Customer attributes Gaussian Mixture, LogNormal, Beta
E Arrival process Non-Homogeneous Poisson Process
W Waiting time M/G/c Queue
P Purchase decisions Multinomial Logit

The dependencies form the following structure:

Arrival process โ†’ Customer โ†’ Queue โ†’ Purchase decisions

More formally:

$$ P(P \mid C, W, products) \rightarrow W(queue \mid P, staff) \rightarrow E(t \mid prices, discounts) $$


๐Ÿ“ˆ Customer Model

Each arriving customer has a vector of attributes:

$$ C = (age, spending, price_sensitivity, caffeine_pref, hot_pref) $$

Age Distribution

A two-component Gaussian mixture

$$ Age \sim \pi_1 N(\mu_1, \sigma_1^2) + (1-\pi_1)N(\mu_2,\sigma_2^2) $$

Example parameters:

55%: N(25, 5ยฒ)
45%: N(40, 8ยฒ)

This models student vs professional demographics.


Spending Distribution

Spending is LogNormal:

$$ X \sim LogNormal(\mu, \sigma) $$

MLE estimation:

$$ \hat{\mu} = \frac{1}{n}\sum \ln x_i $$

$$ \hat{\sigma}^2 = \frac{1}{n}\sum (\ln x_i - \hat{\mu})^2 $$

This captures the right-skewed nature of transaction sizes.


Price Sensitivity

$$ PriceSensitivity \sim Beta(\alpha,\beta) $$

Estimated using method of moments:

$$ \kappa = \frac{\bar{x}(1-\bar{x})}{s^2} - 1 $$

$$ \alpha = \bar{x}\kappa $$

$$ \beta = (1-\bar{x})\kappa $$

This constrains sensitivity to [0,1].


Caffeine Preference

Modeled with logistic regression:

$$

p_{caff}(age)

\frac{1}{1 + e^{-(\beta_0 + \beta_1 age)}} $$

Older customers are more likely to choose caffeinated drinks.


Hot vs Cold Preference

Time-of-day dependence:

$$ p_{hot}(t) = A + B\cos\left(\frac{\pi(t-\phi)}{10}\right) $$

Morning customers prefer hot drinks; afternoon customers prefer cold drinks.


๐Ÿ‘ฅ Arrival Model

Customer arrivals follow a Non-Homogeneous Poisson Process (NHPP).

$$ N(t) \sim Poisson(\lambda(t)) $$

The rate varies over the day:

$$ \lambda(t) = \sum_{k=1}^{3} A_k \exp \left( -\frac{(t-\mu_k)^2}{2\sigma_k^2} \right) $$

representing:

  • morning rush
  • lunch rush
  • afternoon traffic.

Demand Modifiers

The arrival rate adjusts dynamically:

$$

\lambda_{eff}(t)

\lambda(t) \times discount_lift \times price_drag \times day_multiplier $$

Example:

discount_lift = 1 + 0.8 ร— discount
price_drag = 1 โˆ’ 0.5 ร— price_change

โฑ๏ธ Queue Model

Service is modeled as an M/G/c queue.

  • M โ€” Poisson arrivals
  • G โ€” General service distribution
  • c โ€” number of staff

Waiting time:

$$ W_q = \max(0, t_{server_free} - t_{arrival}) $$


Service Time

Per-item service time:

$$ ServiceTime \sim LogNormal(\ln t_{make}, \sigma) $$

Total service time:

$$ T = \sum_i ServiceTime_i $$

This captures barista variability and occasional slowdowns.


Customer Patience

$$ Patience \sim LogNormal(\ln(8), 0.5) $$

Customers abandon if:

$$ wait > patience $$

Median patience โ‰ˆ 8 minutes.


๐Ÿ›’ Purchase Model

Customers choose products using a Multinomial Logit model.

Utility of product (i):

$$ u_i = pop_i

  • 0.5[caff\ match]
  • 0.4[temp\ match]

  • 2 s \frac{price_i}{budget}

  • 1.5 discount

  • 0.5 \frac{wait}{patience} $$

Choice probability:

$$

P(i)

\frac{e^{u_i}}{\sum_j e^{u_j}} $$

A โ€œno purchaseโ€ option is included with utility 0.


Number of Items Purchased

$$ N \sim Poisson(\lambda = 1.4) + 1 $$

Each customer makes at least one purchase decision.


๐ŸŽฒ Monte Carlo Simulation

Each simulation generates a full business day.

Algorithm:

1. Sample arrival times (NHPP)
2. For each arrival:
      sample customer attributes
      compute queue wait
      sample patience
      if wait > patience โ†’ abandon
      sample purchases
      update server schedule
3. Aggregate revenue, profit, wait metrics

This is repeated N times (default 200โ€“1000).

Outputs:

mean
std
p5
p25
p50
p75
p95

This gives a risk distribution for business outcomes.


๐Ÿ› ๏ธ Tech Stack

Layer Technology
Frontend React + TypeScript + Vite
Charts Recharts
Backend FastAPI
Simulation NumPy
AI GPT-4o-mini

๐ŸŽค Demo Script

1๏ธโƒฃ Run baseline simulation 2๏ธโƒฃ Ask AI:

โ€œIncrease latte prices 10%โ€

3๏ธโƒฃ Show profit distribution change

4๏ธโƒฃ Add another staff member

5๏ธโƒฃ Show wait time collapse

6๏ธโƒฃ Highlight product-level demand changes


๐Ÿ‘ฅ Team

Built for Hackathon 2026.


If you'd like, I can also help you add two extremely powerful sections that judges love:

1๏ธโƒฃ โ€œModel Calibration from Real POS Dataโ€ (how the parameters are estimated from logs) 2๏ธโƒฃ A diagram explaining the stochastic pipeline (arrival โ†’ queue โ†’ choice โ†’ revenue)

Those two sections would make this README look much more like a research project than a hackathon demo, which judges tend to reward.

Built With

Share this project:

Updates