Database Schema

Full schema documentation. See also db/migrate/ in the repo.

Food Knowledge Graph

food_sensitivity_categories

ColumnTypeNotes
idbigintPK
namestring”Histamine”, “FODMAPs”, etc.
slugstring”histamine”, “fodmap”, etc. Unique index.
descriptiontext

Seeded with 7 categories: histamine, fodmap, salicylate, oxalate, lectin, glutamate, capsaicin.

ingredients

ColumnTypeNotes
idbigintPK
namestringRaw name as received (e.g. “whole milk”)
canonical_namestringNormalized form (e.g. “milk”)

canonical_name handles OFF’s inconsistent ingredient naming at ingest time.

foods

ColumnTypeNotes
idbigintPK
namestring
open_food_facts_idstringOFF product ID
barcodestringEAN/UPC

food_category_memberships

ColumnTypeNotes
food_idbigintFK → foods
food_sensitivity_category_idbigintFK → food_sensitivity_categories
severityintegerenum: low=0, medium=1, high=2

Unique index on [food_id, food_sensitivity_category_id].

ingredient_food_mappings

ColumnTypeNotes
ingredient_idbigintFK → ingredients
food_idbigintFK → foods

Users

users

ColumnTypeNotes
idbigintPK
namestring
emailstringUnique index

user_suspect_foods

ColumnTypeNotes
user_idbigintFK → users
food_idbigintFK → foods
added_attimestamp

Unique index on [user_id, food_id].


Meal Plans

meal_plans

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
starts_ondate
ends_ondate

meal_plan_slots

ColumnTypeNotes
idbigintPK
meal_plan_idbigintFK → meal_plans
scheduled_fordatetime
meal_idbigintFK → meals, nullable

meal_id is null when the slot exists but no recipe is assigned yet. Separates scheduling skeleton from recipe assignment.

washout_windows

ColumnTypeNotes
idbigintPK
meal_plan_idbigintFK → meal_plans
sensitivity_category_idbigintFK → food_sensitivity_categories
start_datedate
end_datedate

Active washout = today falls between start_date and end_date. The hypothesis engine queries these before surfacing suggestions.

meals

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
eaten_atdatetime
plannedbooleanfalse = off-plan / “cheat”
notestext

meal_ingredients

ColumnTypeNotes
meal_idbigintFK → meals
ingredient_idbigintFK → ingredients
food_idbigintFK → foods, nullable

food_id present if ingredient came from barcode scan. Nullable for manual entry.


Symptom & Control Logging

symptom_types

ColumnTypeNotes
idbigintPK
namestring”Bloating”, “Headache”, etc.
slugstringUnique
categorystring”gut” or “systemic”

Category enables correlation: histamine → systemic, FODMAPs → gut.

Seeded with: bloating, cramping, diarrhea, constipation, headache, migraine, fatigue, brain_fog, skin_rash, hives, nasal_congestion, joint_pain.

symptom_logs

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
symptom_type_idbigintFK → symptom_types
logged_atdatetime
scoreinteger1–5
notestext

daily_controls

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
datedate
sleep_hoursdecimal
sleep_qualityinteger1–5
stress_levelinteger1–5
exercise_intensityintegerenum: none=0, light=1, moderate=2, intense=3
notestext

daily_control_flags

ColumnTypeNotes
idbigintPK
daily_control_idbigintFK → daily_controls
flag_typestringmenstrual_phase, illness, antihistamine, nsaid, alcohol, etc.
valuestringe.g. “luteal”, “true”, “10mg”

Separate extensible table — no schema changes needed to add new confounder types.


Hypothesis Engine

hypothesis_suggestions

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
suggested_food_idbigintFK → foods
reason_category_idbigintFK → food_sensitivity_categories
statusintegerenum: pending=0, accepted=1, rejected=2

Integrations

connected_integrations

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
providerstringapple_health, google_fit, cronometer, clue, etc.
access_tokenstringEncrypted
refresh_tokenstringEncrypted
scopesstring
last_synced_atdatetime

integration_sync_logs

ColumnTypeNotes
idbigintPK
connected_integration_idbigintFK → connected_integrations
synced_atdatetime
records_importedinteger
statusstringsuccess / error

Future: Lab Results

lab_results

ColumnTypeNotes
idbigintPK
user_idbigintFK → users
collected_atdatetime
providerstring

lab_result_markers

ColumnTypeNotes
idbigintPK
lab_result_idbigintFK → lab_results
marker_namestring”DAO”, “plasma_histamine”, “urinary_oxalate”, etc.
valuedecimal
unitstring
reference_range_lowdecimal
reference_range_highdecimal
flagstringnormal / low / high
sensitivity_category_idbigintFK → food_sensitivity_categories, nullable

sensitivity_category_id links lab markers directly to the category graph. A low DAO result → histamine category → boosts confidence of histamine hypothesis suggestions.

This is where Overview and Overview data feeds in.