Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

RecipeHub 02: The secret ingredient is data

The data model is the secret ingredient Project 0001 · GitHub for Recipes TLDR: We built a complete production version of GitHub for Recipes in less than a day with ARC. This series shows how. New to the series? Star

RecipeHub 02: The secret ingredient is data

The data model is the secret ingredient

Project 0001 · GitHub for Recipes

TLDR: We built a complete production version of GitHub for Recipes in less than a day with ARC. This series shows how.

New to the series? Start with 00 · Introducing Building With ARC.

Last week, we went through the initial discovery phase for RecipeHub: the early creative process where we took our idea and started to define what we actually wanted to build. Today we're going to talk about how it works, and how we took a recipe from text to structured data.

A Lemon Garlic Chicken recipe as written: a cream-colored recipe card with seven ingredients in one column and four numbered steps in plain text
As written

The same Lemon Garlic Chicken recipe in RecipeHub, with ingredients colored by category, amounts and units set apart, heat levels and cooking times highlighted, and each step listing the ingredients it uses with their amounts
As data

During that process, we quickly realized that RecipeHub didn't exist just to define recipes. RecipeHub needed to actually help you cook them as well. We put together a list of pain points while cooking, created some screen designs and prototypes, and talked to a couple of chefs and home cooks. As the designs and prototypes started to take shape, we felt confident that we could improve cooking outcomes. But how?

Data models

Features are the foundation for any application. They define what an application does (and doesn't do): what it does for users, what value it provides, what unique experiences it creates. In this way, features define what.

Data models are the first part of defining how. A data model describes how information is structured, what different pieces of information represent, and how they relate to one another.

That might sound like an abstract concept, but we encounter data models every day. At its simplest, a recipe is a data model: a list of ingredients and a set of instructions.

A recipe card for Lemon Garlic Chicken, annotated by hand. The whole card is one recipe. Each of its seven ingredient lines is one ingredient, and each of its four numbered paragraphs is one step.

Data models are important because they don't just define how information is structured. They define how your application understands the information, and they determine what your application can do.

  1. Good: organizes information. Gives your data a clear, consistent structure that your application can understand and work with.
  2. Better: enables functionality. Captures the relationships between information, making it easier to build the features and experiences you envision.
  3. Best: expands what's possible. Creates a foundation for capabilities that go beyond the application's original vision.

The more your application understands about its information, the more interesting features it can support.

Great data models are the secret ingredient to an application.

But the best data model isn't necessarily the most complex one. It's the one that represents your product, supports the features and functionality you want, and allows the product to evolve. To better understand that, let's look at some of the key features for RecipeHub's cook mode.

Scaling

The first feature seems simple enough. Users should be able to scale a recipe, so they can make half or twice the servings.

However, our first data model says that an ingredient is each line of the ingredients list. So what happens when we double "4 boneless, skinless chicken thighs"?

Two times '4 boneless, skinless chicken thighs' produces the whole line written out twice, crossed out in red, with the handwritten note: we wanted 8 thighs, not the ingredient twice.

There are ways we could get this to work. There are programmatic approaches, and we could use an LLM to do the multiplying. But that's a real trade-off you have to be aware of: the programmatic approach has edge cases, and the LLM has costs that add up across millions of recipes.

For this feature, a good data model is one that separates the amount from the ingredient name. An even better data model handles the surprisingly rich ingredient entry, accounting for measurements, units and more.

The ingredient split into its amount, 4, and what it counts. As data, it has a quantity of kind count with amount 4, and the name 'boneless, skinless chicken thigh'. Times 2, the amount becomes 8.

With that model, we can easily scale the entire recipe. Our application can do something that cookbooks simply can't.

The seven Lemon Garlic Chicken ingredients as written, each mapped to a structured quantity and then doubled: 8 chicken thighs, 2 tsp salt, 1 tsp black pepper, 2 tbsp olive oil, 6 cloves garlic, 1 cup chicken broth and 2 lemons.

Every application is different and requires a different data model, based on its current and expected features. You should model only what you need (and what's on your roadmap), so a recipe app without scaling may not need this.

While scaling the ingredients isn't that complex on its own, it gives us the foundation for extracting richer data from recipes. Let's see what other features we can support with a better data model.

Categories

Extracting the quantities for ingredients isn't the only feature we had in mind. We quickly started experimenting with the idea of ingredient categories, because chicken thighs, garlic, broth and lemon juice are very different ingredients with very different roles in the recipe.

The Lemon Garlic Chicken ingredient list with four lines circled and annotated by hand: chicken thighs are the main event, garlic is big flavor, chicken broth becomes the sauce, and lemon wakes the whole dish.

The vision for RecipeHub may have started with recipe collaboration based on GitHub, but that's not the only part of the application inspired by code. We work with code all day and rely on syntax highlighting to help us understand it, to tell apart keywords, variables, classes and everything else. It helps you understand code much more intuitively, and we wanted to do the same thing for recipes.

Four ingredients mapped to categories and their role in the recipe: chicken thighs are protein, garlic is aromatic, chicken broth is liquid, and lemon is acid.

By defining ingredient categories, we can classify ingredients and help cooks understand what each ingredient does for a recipe. We can provide the same semantic understanding that code editors provide, but for chefs at home. This categorization is part of how we intend to improve how well each cook turns out. But it's not the only thing we're doing.

Cook mode

As we mentioned in the first article, one real pain point we kept coming back to was recipes that have you adding a half dozen ingredients in a single step. You've already started cooking, your hands might be dirty, and now you have to remember how many cups, tablespoons and teaspoons of each you need.

Step 3 of a recipe adds onions, carrots, celery, leeks, garlic and tomato paste. Six of them have no amount in the step, so the cook has to go back to the ingredients list for each one.

This is a perfect example of a trade-off the original cookbook format had to make. Leaving out the amount for each ingredient in the steps saved space, and spared editors from double-checking countless cloves, cups and tablespoons. But we can easily account for this in our app: our data model, plus testing, makes something like this trivial.

Steps 3 and 4 in RecipeHub's cook mode. Ingredients are colored by category, the heat level and cooking times are highlighted, and below each step a row of chips lists every ingredient it uses with its amount.

This provides a much richer view of the step, calling out the ingredients by category and highlighting key details like time and temperature. In a single glance, you can see everything you need to cook the step properly, without worrying about forgetting something.

It all goes back to the user experience you're looking to provide. Once we decided we wanted to help people actually cook the recipes, we knew we needed this.

If just one user cooking at home can glance across the kitchen and remember to add the herbs thanks to their bright green color, our data model did its job.

Next course

This article is just a taste of RecipeHub's features and data model. For our next course, we'll explore how we combined everything into one complete product spec. Then we'll cover how ARC generated all of the code.

If you'd like to follow along, be sure to join our mailing list. And if you'd like to learn more about ARC, and how our spec-driven development platform can help build your next application, you can contact us directly at [email protected].

Originally published on the ARC blog.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.