Making FoodIntake, Part I
Tags: mobile, database, buildinpublic
Published: 2024-04-11 13:25:50

*Welcome to the jungle* of [FoodIntake app](https://foodintake.space/)

It started by gathering information about competitors and comparison of their features. I looked for data quality, usability, and simplicity. I tried several apps to see what they have and why they are popular and have noted for myself the best of them. 

I separated my app into two parts: **goals** and **logging**.

## Goals / Purpose to use

There are two main problems or goals the app is trying to solve: weight management and healthy eating.

### Weight management

To set goals and target weight I used a standard questionnaire for retrieving required parameters for formulas.

To calculate dietary norms and daily calorie intakes I used formulas from several research papers:

{% embed https://vimeo.com/933269225?share=copy %}

*Dietary Reference Intakes DRI The Essential Guide to Nutrient Requirements, 2006, National Academy of Sciences*

[Dietary. Reference Intakes for Energy. Washington, DC: The National Academies Press. National Academies of Sciences, Engineering, and Medicine. 2023.](https://doi.org/10.17226/26818) 

[Optimal Diet Strategies for Weight Loss and Weight Loss Maintenance, J Obes Metab Syndr. 2021](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8017325/)

I hardcoded them onto client side but I think it worth to get them from the backend and update quickly if needed. 

I also covered all calculations by Swift unit tests to verify that for different age groups, sexes and physical activity levels valid calorie norm is calculated.

![AMDR and DRI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/489ijvxqaeqyzzn47r5a.png)

There were two complex issue I have encountered which slowed me down a bit: 

First was related to units conversions, it appeared that on iOS there’s no easy way to convert back and forth feet with inches and meters without loosing some precision.

Second one was related to calculating and displaying AMDR ranges (Acceptable Macronutrient Distribution Range). I have created a custom double range slider for this. In SwiftUI nature of observability of data changes didn’t allow me to save ranges updates on change or after change without limiting UI I wanted to show so such settings is possible to update in the cloud only by pressing “Save” button after a change was made.

Its quite convenient to see your progress overtime if your original goal is mostly related to weight management, so the last piece of the part if showing a user his weight progress on a chart overtime

Swift Charts are quite good for the task:

![Weight Chart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1zrttdkd255ixdfrcqh.png)

I usually log my weight once per two weeks to see how I am going. But checking the graph gives me motivation.

Because logging of progress happens rarely but information checking is more often I wanted to utilise as much as possible space for those things which are used more often. I wanted to keep minimal UX but informative and easy to use.

I have added integration with HealthKit for this and anytime user updates his data in settings or logs new weight it is written into the store.

I have minimised the chart to fit it into swiping horizontally TabView and made the chart tappable for weight logging, aligned time range buttons vertically to the left of the graph with simple abbreviation. I think this progress chart is neat.

### Healthy eating

This topic is quite hard and I am covering it a lot in [FoodIntake blog](https://blog.foodintake.space/) doing researches about [processed and unprocessed foods](https://blog.foodintake.space/processed-and-unprocessed-foods/), [fats](https://blog.foodintake.space/can-fats-be-healthy/), fiber, food hacks and digestion boosters.

Now FoodIntake app has 3 the most important metrics about healthy eating: macronutrients, daily safe AMDR (Acceptable Macronutrient Distribution Range ), hint labels about food quality.

There are two types of food quality labelling: [nutriscore](https://blog.foodintake.space/nutriscore/) and [nova group](https://blog.foodintake.space/processed-and-unprocessed-foods/)

Nutriscore is calculated from macronutrients. Nova group analyses ingredients.

Both of them can give a user an overall picture of how good food is

I use my replicas of OFF (Open Food Facts) and FDC (Food Data Central) databases. I run them in kubernetes and host in Digital Ocean.

![Nutri-Score and Nova-Group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw0kwmvg6b9zhyfe2r9k.png)

I will tell more about the databases in the next series where I cover logging/tracking part.