ForkFit Docs
ServerDatabase

Recipes & Nutrition

Database tables representing food items, raw food costs, portions, recipes, and user food tracking logs.

Recipes & Nutrition

This module represents the primary nutrition records, recipe formulations, raw food item properties, dynamic cost structures, and daily calorie consumption logs.

Migrated by: 00003_create_recipes_and_nutrition.sql


1. Food Catalog & Costs

food_items

Defines base food items and their macronutrient distributions per 100 grams.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Food item identifier.
    nametextNOT NULL UNIQUE-Descriptive food name.
    descriptiontext--Food item details.
    calories_per_100gnumeric(6,2)NOT NULL-Calorie count per 100g.
    protein_per_100gnumeric(5,2)NOT NULL-Protein content (g) per 100g.
    carbs_per_100gnumeric(5,2)NOT NULL-Carbohydrates content (g) per 100g.
    fat_per_100gnumeric(5,2)NOT NULL-Fat content (g) per 100g.
    fiber_per_100gnumeric(5,2)NOT NULL0.00Dietary fiber (g) per 100g.
    sodium_mg_per_100gnumeric(10,2)NOT NULL0.00Sodium level (mg) per 100g.
    micronutrientsjsonbNOT NULL'{}'Key-value store for vitamins and minerals.
    barcodetext--UPC/EAN barcode string.
    is_verifiedbooleanNOT NULLfalseTrue if verified by nutrition experts.
    food_codetextUNIQUE-Internal/standard system code.
    primary_sourcetext--Origin source registry (e.g. 'Anuvaad INDB').
    raw_food_cost_iduuidREFERENCES raw_food_costs(id) ON DELETE SET NULL-Optional link to raw food cost pattern.
    created_attimestamptzNOT NULLnow()Record creation timestamp.
    updated_attimestamptzNOT NULLnow()Record change timestamp.

raw_food_costs

Defines price guidelines per 100 grams for generic food patterns in India (utilized by the Budget Agent for dynamic cost evaluation).

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Cost pattern identifier.
    food_patterntextNOT NULL UNIQUE-Pattern for name matching (e.g. 'chicken').
    cost_per_100gnumeric(10,2)NOT NULL-Price per 100 grams in India.
    price_currencytextNOT NULL'INR'Price currency code.
    created_attimestamptzNOT NULLnow()Record creation timestamp.
    updated_attimestamptzNOT NULLnow()Record change timestamp.

food_item_portions

Specifies portion equivalence factors to convert serving units (e.g., cups, slices) into grams.

  • Schema: id (PRIMARY KEY), food_item_id (foreign key food_items), serving_unit (e.g. 'cup'), grams_equivalent (checking > 0), created_at, updated_at. Joint unique index on (food_item_id, serving_unit).

2. Recipe Structure

recipes

Header metadata for food recipes.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Unique recipe identifier.
    owner_iduuidREFERENCES users(id) ON DELETE SET NULL-User owner. Null indicates a public system recipe.
    parent_recipe_iduuidREFERENCES recipes(id) ON DELETE SET NULL-Reference to parent recipe (for alternatives/variations).
    titletextNOT NULL-Recipe title.
    descriptiontext--Recipe brief description.
    instructionstext[]NOT NULL-Array list of recipe execution steps.
    prep_time_minutesinteger--Preparation time in minutes.
    cook_time_minutesinteger--Cooking duration in minutes.
    servingsnumeric(4,2)NOT NULL1.00Default servings yield.
    cuisinetext--Regional classification (e.g. 'North Indian').
    coursetext--Course category (e.g. 'Lunch', 'Breakfast').
    dietary_tagstext[]NOT NULL'{}'Dietary categories (e.g. {'Vegan', 'Gluten-Free'}).
    source_urltext--Original recipe URL source link.
    is_publicbooleanNOT NULLfalseTrue if visible to other platform users.

recipe_food_items

Junction table tracking recipe food item requirements.

  • Schema: recipe_id (foreign key recipes), food_item_id (foreign key food_items), quantity (numeric), unit (e.g. 'g'), grams_equivalent (computed weight), notes. Joint primary key on (recipe_id, food_item_id).

3. Daily Food Logging

food_logs

Saves historical nutrient intakes consumed by users.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Log identifier.
    user_iduuidNOT NULL-Foreign key referencing users.id (ON DELETE CASCADE).
    logged_attimestamptzNOT NULLnow()Date and time consumed.
    meal_typetextNOT NULL-Meal segment: 'breakfast', 'lunch', 'dinner', or 'snack'.
    recipe_iduuidREFERENCES recipes(id) ON DELETE SET NULL-Referencing recipe if logged as a whole dish.
    food_item_iduuidREFERENCES food_items(id) ON DELETE SET NULL-Referencing food item if logged individually.
    custom_food_nametext--Fallback text label if item not in catalog.
    quantitynumeric(6,2)NOT NULL-Logged quantity.
    unittextNOT NULL-Unit (e.g. 'servings', 'grams').
    caloriesnumeric(6,2)NOT NULL-Denormalized calorie total at logging time.
    proteinnumeric(5,2)NOT NULL-Denormalized protein summary (g).
    carbsnumeric(5,2)NOT NULL-Denormalized carbohydrate summary (g).
    fatsnumeric(5,2)NOT NULL-Denormalized fat summary (g).
    micronutrients_snapshotjsonbNOT NULL'{}'Snapshot of micro nutrients at entry time.
    created_attimestamptzNOT NULLnow()Log creation timestamp.

On this page