Skip to Content

Database Schema Documentation

This document describes the database schema used in the application. It includes all tables, enums, their fields, types, constraints, and relationships.

The backend uses a PostgreSQL database.

Enums

difficulty_enum

  • easy
  • medium
  • hard

gender_enum

  • male
  • female

diet_enum

  • no_diet
  • vegetarian
  • vegan
  • pescatarian

Table: users

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedUser ID
emailTEXTNOT NULL, UNIQUEUser email
first_nameTEXTNOT NULLFirst name
last_nameTEXTNOT NULLLast name
passwordTEXTNOT NULLHashed password
pictureTEXTProfile picture URL
usernameTEXTNOT NULL, UNIQUEUnique username
followersINTEGERNOT NULL, DEFAULT 0Number of followers
followsINTEGERNOT NULL, DEFAULT 0Number of followed users

Table: recipes

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedRecipe ID
sourceTEXTOriginal source
original_idTEXTOriginal external ID
nameTEXTNOT NULLRecipe name
created_atDATENOT NULL, DEFAULT NOW()Creation timestamp
preparation_timeINTEGERNOT NULLTime to prepare
cooking_timeINTEGERNOT NULLTime to cook
tagsTEXT[]NOT NULLArray of tags
steps_countINTEGERNOT NULLNumber of steps
stepsTEXT[]NOT NULLStep-by-step instructions
descriptionTEXTNOT NULLRecipe description
ingredients_countINTEGERNOT NULLNumber of ingredients
ingredientsJSONB[]NOT NULLList of ingredients
caloriesREALCaloric value
total_fatREALTotal fat
sugarREALSugar content
sodiumREALSodium content
proteinREALProtein content
saturated_fatREALSaturated fat
carbohydratesREALCarbohydrates
cholesterolREALCholesterol
fiberREALFiber
likesINTEGERNOT NULL, DEFAULT 0Like count
author_nameTEXTName of author
author_idINTEGERFK → users.idAuthor user ID
imagesTEXT[]NOT NULLImage URLs
difficultyENUMNOT NULL (difficulty_enum)Difficulty level
servingsINTEGERNumber of servings
serving_sizeINTEGERServing size
searchableTSVECTORDEFAULT TRUEFull-text search vector

Indexes

  • searchable_idx on searchable

Table: recipe_likes

ColumnTypeConstraintsDescription
recipe_idINTEGERPK, FK → recipes.id, ON DELETE CASCADELiked recipe ID
user_idINTEGERPK, FK → users.idUser who liked recipe

Table: preferences

ColumnTypeConstraintsDescription
idINTEGERPK, FK → users.idUser ID
activity_levelREALNOT NULLActivity level
weightREALNOT NULLUser weight
heightREALNOT NULLUser height
genderENUMNOT NULL (gender_enum)Gender
ageINTEGERNOT NULLUser age
allergensTEXT[]NOT NULLKnown allergens
dietENUMNOT NULL (diet_enum)Dietary preference

Table: posts

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedPost ID
sourceTEXTSource of post
author_idINTEGERFK → users.idAuthor user ID
ratingINTEGERNOT NULLUser rating
recipe_idINTEGERNOT NULL, FK → recipes.id ON DELETE CASCADELinked recipe ID
contentTEXTNOT NULLText content
author_nameTEXTName of post author
original_idTEXTOriginal external post ID
original_recipe_idTEXTExternal recipe ID
created_atDATENOT NULL, DEFAULT NOW()Creation date
likes_countINTEGERDEFAULT 0Number of likes

Table: post_likes

ColumnTypeConstraintsDescription
post_idINTEGERPK, FK → posts.id, ON DELETE CASCADELiked post ID
user_idINTEGERPK, FK → users.idUser who liked post

Table: followers

ColumnTypeConstraintsDescription
follower_idINTEGERPK, FK → users.idFollower user ID
followed_idINTEGERPK, FK → users.idFollowed user ID
ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedRecord ID
recipe_idINTEGERNOT NULL, FK → recipes.id ON DELETE CASCADEFeatured recipe ID

Table: dietary-plans

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedPlan ID
start_dateDATENOT NULLPlan start date
targetREALNOT NULLTarget weight/calorie

Table: dietary_logs

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedLog ID
caloriesREALNOT NULLCalories logged
detailsJSONBNOT NULLLog detail JSON
created_atTIMESTAMPNOT NULL, DEFAULT NOW()Time of logging
user_idINTEGERNOT NULL, FK → users.id ON DELETE CASCADELinked user ID

Table: chats

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedChat ID
nameTEXTNOT NULLChat name/title
created_atTIMESTAMPNOT NULL, DEFAULT NOW()Creation time
updated_atTIMESTAMPNOT NULL, DEFAULT NOW()Last update
user_idINTEGERNOT NULL, FK → users.idCreator user ID

Table: chat_messages

ColumnTypeConstraintsDescription
idINTEGERPK, auto-generatedMessage ID
roleTEXTNOT NULLRole (user/system/etc.)
partsJSONB[]NOT NULLMessage content parts
created_atTIMESTAMPNOT NULL, DEFAULT NOW()Message timestamp
chat_idINTEGERNOT NULL, FK → chats.id ON DELETE CASCADELinked chat ID
user_idINTEGERNOT NULL, FK → users.idSender user ID

Relationships Summary

  • recipes.author_idusers.id
  • recipe_likes.user_idusers.id
  • recipe_likes.recipe_idrecipes.id
  • preferences.idusers.id
  • posts.author_idusers.id
  • posts.recipe_idrecipes.id
  • post_likes.user_idusers.id
  • post_likes.post_idposts.id
  • followers.follower_idusers.id
  • followers.followed_idusers.id
  • featured_recipes.recipe_idrecipes.id
  • dietary_logs.user_idusers.id
  • chats.user_idusers.id
  • chat_messages.chat_idchats.id
  • chat_messages.user_idusers.id
Last updated on