Inspiration

Independent cafes run on instinct. The owner can feel that something shifted, maybe profit is down or the lunch rush feels slower, but they rarely know why, and they cannot afford the analysts or the software that big chains use to answer those questions. I wanted to give a single location cafe the kind of operational intelligence a large chain takes for granted.

The second thing that pushed me was frustration with AI business tools. Most of them are a chat box wired to a language model that will happily invent a number to sound helpful. For a tool that is supposed to help someone set payroll and prices, a made up figure is worse than no answer. So I set one hard rule from the start: the AI can explain and recommend, but it can never do the math and never make up a number.

What it does

Business Brain reads a cafe's sales, costs, inventory, labor, suppliers, and customer reviews, and acts like an operations manager that is always on.

  • It answers plain questions like "why did profit drop in June?" A deterministic engine computes the actual drivers first (milk cost up 18 percent, weekend overtime up 22 percent, pastry waste climbing), then the AI writes the explanation and cites every number it used.
  • It watches the business on its own and posts a Business Health Score out of 100, along with the alerts that need attention, before anyone asks.
  • It turns each finding into an action that a human approves. Pricing and staffing changes need the owner. The AI proposes, people decide, and every step is logged.
  • On the customer side it recommends menu items by taste and checks allergies against the actual recipe, not a guess.

How I built it

The stack is Next.js and TypeScript on the front, FastAPI and Python on the back, PostgreSQL with pgvector for storage and vector search, all wired together with Docker Compose so the whole thing comes up with one command and runs on free infrastructure.

The core design choice is a wall between the math and the model. Every number comes from a deterministic analytics engine written in plain SQL and Pandas. The language model sits behind an abstraction layer and only ever receives the finished facts, then it narrates them. Before any AI answer reaches the screen, a validator pulls every number out of the text and checks it against the computed facts. If the model cites a figure that was not computed, the answer is thrown out and the user sees the raw findings instead.

The Health Score is a weighted blend of five pillars:

$$ \text{Health} = \sum_{p} w_p \, s_p, \qquad \sum_{p} w_p = 1 $$

with profitability weighted 0.30, cost control 0.20, customer satisfaction 0.20, inventory 0.15, and labor 0.15. Each profit driver is a simple variance. An ingredient price effect, for example, is \( (c_{\text{now}} - c_{\text{base}}) \times q \), where \( c \) is the unit cost and \( q \) is the quantity used.

A few more decisions that mattered:

  • Embeddings run locally as ONNX (all-MiniLM-L6-v2), so menu search and document search work with no network and never depend on the model provider.
  • Review sentiment uses VADER and a keyword topic tagger at ingest time, so scoring 5,000 reviews costs nothing and never hits a rate limit.
  • The model layer can fall back from Gemini to a local model, and finally to a degraded mode that still returns the computed facts, so the product keeps working even with the AI switched off.
  • I generated two years of synthetic data for a demo cafe with real problems planted inside it (a milk price hike, two baristas quitting, rising waste), and wrote tests that assert the analytics finds exactly those problems. The project ships with over a hundred backend tests, including those golden tests and stress tests for messy file uploads.

Challenges I ran into

Making the AI trustworthy was the whole game and most of the work. Getting a model to cite its evidence and never improvise a number took a validator, a strict prompt, and a lot of back and forth. Free tier models also fight you. One model alias quietly routed to a slow thinking preview that took 30 seconds, the flash model needed its thinking budget turned off to answer in two, and the rate limit is easy to trip, so I leaned on caching, a fallback chain, and the degraded path.

Embeddings had a blind spot I did not expect. "I don't want sweet" produces almost the same vector as "sweet," so the recommender kept suggesting sugary drinks to the people avoiding them. I fixed it with a small deterministic negation parser that penalizes the unwanted flavor instead of matching it, and it stays a fast, no model path.

The allergy engine had to fail closed. It is a pure database join over recipe, ingredient, and allergen, and anything unknown is treated as unsafe. I would rather warn someone that a safe item might not be, than the reverse, so the language model is never allowed near that decision.

Ingestion was another grind. Real spreadsheets are messy, and my first version would let a single bad row, an overflowing number, or a stray currency symbol crash an entire upload. I rewrote it to validate every value before it touches the database, so one bad row lands in an error list and the rest of the file still imports.

What I learned

The most useful thing I learned is that keeping the language model out of the math is what makes an AI product you can actually trust. Once the numbers are computed and checked, the model has nothing to lie about, and "the AI can explain but not decide" turned out to be both a safety rule and the thing that sets the product apart.

I also learned how much free tier and offline limits shape the architecture. Caching, provider fallback, and a real degraded mode were not extras, they were the reason the thing survives a demo on bad wifi. And I learned that embeddings, sentiment lexicons, and vector search all have real edges you have to design around instead of trusting blindly.

What's next for Business Brain

  • Connectors that pull data straight from POS, accounting, and review platforms, so an owner never has to upload a file. The schema and ingestion pipeline are already shaped for this.
  • Employee onboarding and offboarding built on the same action item and document pieces that already exist.
  • A voice version of the customer assistant, since the recommendation and allergy checks already run fast enough with no model call to sit behind speech.

Built With

Share this project:

Updates