ForkFit Docs
ServerDatabase

Database Schema

PostgreSQL relational schema and migrations structure for the ForkFit database.

Database Schema

ForkFit utilizes PostgreSQL as its core transactional datastore. Schema migrations are managed sequentially and executed automatically on server startup.


Migration Steps

Migrations are located in server/db/migrations/ and cover the following schema namespaces:

Identity & Access Management (00001_create_iam.sql)

Sets up users, sessions, roles, permissions, and roles-to-permissions mapping tables.

Profiles & Biometrics (00002_create_profiles_and_biometrics.sql)

Defines user profiles, preferences, medical safety audits, biometric logs (weight, height, body fat), workout logs, and goals.

Recipes & Nutrition (00003_create_recipes_and_nutrition.sql)

Configures food items, raw food costs, custom recipes, food items-to-recipes mapping, and user food logs.

Planning & Shopping (00004_create_planning_and_shopping.sql)

Sets up active meal plans, individual meal plan items, pantry items, and shopping lists.

Chat & Feedback (00005_create_chat_and_feedback.sql)

Defines chat threads, message records, and system feedback.

AI Orchestration & Memory (00006_create_ai_orchestration_and_memory.sql)

Supports LangGraph trace steps, agent execution statuses, and semantic user preferences (memories).

Background Jobs & Notifications (00007_create_background_jobs_and_notifications.sql)

Queues background tasks and stores transactional mail logs.

System Audits & Indices (00008_create_audit_logs_and_indexing.sql)

Governs user-action audit logs and registers performant indexes on search fields.


Entity-Relationship Overview

Here is a simplified diagram of how the primary tables connect:

users (no attributes) user_sessions (no attributes) user_profiles (no attributes) biometric_logs (no attributes) user_goals (no attributes) food_logs (no attributes) meal_plans (no attributes) chat_threads (no attributes) medical_safety (no attributes) recipes (no attributes) recipe_food_items (no attributes) food_items (no attributes) raw_food_costs (no attributes) meal_plan_items (no attributes) chat_messages (no attributes) has sessions has profile logs biometrics sets goals records food selects plans chats in assesses safety contains used in links to contains contains

Schema Reference

1. Identity & Access Management (IAM)

  • users: Email credentials, verified status, full name, password hashes, and timestamps.
  • user_sessions: Session tokens, client IP, device user-agents, expiration dates.
  • roles / permissions: RBAC entities supporting administrative operations.

2. Nutrition & Planner

  • food_items: Caloric count, protein (g), fat (g), carbs (g), category flags, and optional raw food cost link.
  • recipes: Title, instructions, preparation time, and nutritional sums.
  • food_logs: Daily logs tracking consumed foods and cumulative macronutrient summaries.
  • meal_plans: Meal configurations scheduled for user calendars.
  • shopping_lists: Automated shopping requirements generated from recipes.

On this page