Before I became a developer, I worked as a waiter for over 6 years. And if there's one thing I saw repeat itself over and over during that time, it was how poorly managed menus and inventory are in most restaurants: dishes kept being sold without available ingredients, food waste from lack of stock visibility, and menu decisions made on gut feeling instead of real data.
When I started coding, that experience stuck with me. I knew I wanted to build something that tackled this exact problem, and AI seemed like the perfect tool to help restaurants make better decisions about their menu and inventory in real time. That's how Materia AI was born, and in this post I'll walk you through how I built the first version of the agent using Python and Flask.
The stack I chose
For the backend I used Flask, mainly because I wanted something lightweight and fast to iterate on while I was still figuring out the business logic. I didn't need the full structure of Django, and I wanted direct control over each endpoint while experimenting with the AI integration.
For the AI piece, I connected the backend to a language model that analyzes sales and inventory patterns, and generates recommendations (for example, which dishes to adjust or pull from the menu based on available stock).
The basic architecture
The flow is simple but effective:
Frontend (React) -> Flask Endpoint (/api/analyze) -> AI API call -> Response processing -> JSON with recommendations -> Frontend
The core code
Here's a simplified example of the endpoint that receives inventory and sales data, and returns AI-generated recommendations:
from flask import Flask, request, jsonify
import os
from openai import OpenAI
app = Flask(__name__)
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
@app.route("/api/analyze", methods=["POST"])
def analyze_inventory():
data = request.json
menu_items = data.get("menu_items")
inventory = data.get("inventory")
prompt = f"""
Analyze the following menu and available inventory.
Menu: {menu_items}
Inventory: {inventory}
Suggest which dishes should be paused due to missing ingredients
and which products are at risk of being wasted.
"""
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
return jsonify({"recommendation": response.choices[0].message.content})
if __name__ == "__main__":
app.run(debug=True)
The challenges I ran into
Not everything was smooth. I had to solve a few real problems along the way: how to structure the prompt so the AI returned consistent, useful responses instead of generic text, how to handle API rate limits without the app crashing, and how to store the API key securely using environment variables instead of hardcoding it.
Connecting it to the fullstack side
As a fullstack developer, I didn't want this to stay only on the backend. On the React side, a simple example of how this endpoint gets consumed would look like this:
async function getRecommendation(menuItems, inventory) {
const response = await fetch("/api/analyze", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ menu_items: menuItems, inventory: inventory }),
});
const data = await response.json();
return data.recommendation;
}
What I learned
Building this taught me three key things. First, the best motivation for a technical project almost always comes from a real problem you lived close to. Second, integrating AI into an app isn't just about calling an API, it's about designing the prompt carefully and handling errors with care. And third, coming from a waiter role gave me an advantage I didn't expect: I understood the business problem better than many developers who've never been on the other side of the counter.
If you work in the restaurant industry, or something similar happened to you in another field, I'd love to hear about it in the comments. And if you want to check out more of my projects, you can find me on GitHub: https://github.com/GerAle30
Top comments (0)