The system is built on a flexible database architecture, this makes it scalable and can easily be expanded to accomodate more requirements. Let's get started:
- meals:
- id
- name
- description
- timestamps
- items:
- id
- name
- description
- timestamps
- allergies:
- id
- name
- description
- timestamps
- users:
- id
- name
- password
- timestamps
- meal_items:
- meal_id
- item_id
- type: enum(main, side).
- timestamps
- item_allergies:
- item_id
- allergy_id
- timestamps
- user_allergies:
- user_id
- allergy_id
- timestamps
The system is divided into 3 categories of endpoints: data, relationships and recommender.
This group contains logic to create, update and fetch entities: meals, items, allergies and users.
For example, to fetch meals, use GET /api/meals
and to save or update, use POST /api/meals
.
The same applies to the other entities.
This group contains logic for querying and manipulating relationships between the entities.
The 3 relationships are meal-items
, item-allergies
and user-allerges
.
Every meal has 3 or more item (1 main plus 2 or more side items). This relationship is captured in the meal_items
table.
Every item has zero or more allergies. The item_allergies
table holds this information.
Every user has zero or more allergies. The user_allergies
table captures this association.
This group holds what the API is all about: Making recommendations! Both endpoints perform the same base logic of fetching recommendations for a given user_id as follows:
- Fetch all of the users' allergies from the
user_allergies
table. - Use the above allergies to fetch all items that have that allergy using the
item_allergies
table. Lets call these the unsafe items. - Use the unsafe items to fetch the meals that would be affected from the
meal_items
table. We call these the unsafe meals. - Finally, fetch all meals that are not unsafe meals and return as recommended meals.