I’m writing a simple personal project where the goal is to let users create their own nutritional tables (what you plan to eat in a day with a recap of the macro/calories).
The underline database should be relatively simple but as a newbie I’ll like some feedback on a certain aspect.
I plan to have these two main tables:
- “users”, where I save the data provided during sign in
- “diet plans”, where I save a name and description (user input) and a reference to the user ID which said plan belongs to
Now, what are the elements of each diet plan? I plan to fetch data with an api based on the element requested by the user. For example, if they want to add a banana I’ll provide choices from which to select a definitive product, based on the results of the api so that users don’t have to input the macro by themselfs.
That’s not all tho, because I want to let users create their own “meals”. For example, if they want to eat a slice of ownmade cake, it makes sense that they first have to create said meal by specifying its ingredients (fetched again through the api)…
To recap, the “diet plans” entries can either be a simple ingredient fetched through the api, or a combination of these that must be already saved in the database through a dedicated form.
My doubts regards how and what to save in regards to the ingredients and relative macros.
For sure there must by a table “recepies”, where I at least provide an ID, name and description, and a reference to the creator/user
What to do for everything regarding the single ingredients tho? The simplest solution would be to not store any hard data but only their unique reference for direct retrieval from the api everytime they’re needed.
In this scenario I’ll have to add two additional tables to the database (so 5 in total):
- “diet elements” where as columns I would have a reference to the diet, the identifier for the api, the reference id for the corresponding recipe, maybe other generic data like portions/grams and specific meal they belong to (dinner, breakfast etc..). The catch is that every row would either have the api id or the recipe reference blank.
- “recipe elements” which would be very simple because I’ll only need the api id for said element, a reference to the meal they are part of, quantity/portions.
Another option is to save somewhere some data regarding the macros without having to fetch, and compute them so many times for basically anything done inside the app/website. For example, “diet elements” could have additional columns where I save the macros of each element, where, remember, the latter is an item from the api or a personal meal created by the users as I already explained.
The catch? Well, if the api changes the macro for an item then the updated values wouldn’t be reflected on the app/website for already existing diet. Granted, I’m not sure how often that happens
Toughts?