NutriTrack is an innovative app designed to help users track their food consumption, nutritional information, and environmental impact. By providing valuable insights into dietary decisions and statistics, NutriTrack not only promotes healthier habits but also rewards users for their progress.
NutriTrack leverages the following key technologies:
The points system is designed to motivate users to make healthier dietary choices by awarding points for tracking foods. These points are awarded on each tracking entry the user made based on the nutritional information and CO2 emissions.
Points Based on Diet Type:
Points Based on CO2 Emissions:
Points Based on Caloric Content:
Before setting up the project, ensure you have the following software installed on your machine:
Clone the project repository from GitHub:
git clone https://github.com/Clausioporosis/nutritrack.git
cd nutritrack
The project includes a docker-compose.yml file to set up the PostgreSQL database, pgAdmin, and run the application. Ensure you are in the project's root directory and use the following command to start the services:
docker-compose up -d
The application will be accessible at http://localhost:8080.
docker-compose down
NutriTrack implements various security measures to protect user data and ensure secure access to the API.
The application uses JSON Web Tokens (JWT) for authentication. Upon successful login, a token is issued to the user, which must be included in the header of subsequent requests.
For user-related operations, the user ID is securely extracted from the JWT token provided in the request header. This process ensures that each request is authenticated, and the user ID is reliably obtained from the token payload. The extracted user ID is then used to perform operations specific to the authenticated user across various APIs, including the Food API, Tracking API, and User Stats API. This mechanism guarantees that all data and actions are accurately associated with the correct user.
Below is the database schema for NutriTrack, providing a visual overview of how the data is structured and related:
Endpoint: /api/auth/register
POST
{
"username": "string",
"email": "string",
"password": "string",
"firstName": "string",
"lastName": "string"
}
Endpoint: /api/auth/authenticate
POST
{
"username": "string",
"password": "string"
}
{
"token": "string"
}
Endpoint: /api/users
GET
Endpoint: /api/users/{id}
GET
Endpoint: /api/users/search?keyword={keyword}
GET
Endpoint: /api/users/me
GET
{
"id": 0,
"username": "string",
"email": "string",
"firstName": "string",
"lastName": "string"
}
Endpoint: /api/users/{id}
DELETE
Endpoint: /api/foods
POST
{
"title": "string",
"brand": "string",
"category": "string",
"nutrition": {
"calories": 0.0,
"protein": 0.0,
"carbs": 0.0,
"fat": 0.0
},
"sustainability": {
"co2perKg": 0.0,
"dietType": "OMNIVORE|VEGETARIAN|VEGAN"
},
"portions": [
{
"label": "String",
"quantity": 0.0
}
],
"liquid": false
}
Endpoint: /api/foods/user
GET
Endpoint: /api/foods/{id}
GET
{
"id": 0,
"title": "string",
"brand": "string",
"category": "string",
"nutrition": {
"calories": 0.0,
"protein": 0.0,
"carbs": 0.0,
"fat": 0.0
},
"sustainability": {
"co2perKg": 0.0,
"dietType": "OMNIVORE|VEGETARIAN|VEGAN"
},
"portions": [
{
"id": 0,
"label": "string",
"quantity": 0.0
}
],
"liquid": false
}
Endpoint: /api/foods/{id}
PUT
{
"title": "string",
"brand": "string",
"category": "string",
"nutrition": {
"calories": 0.0,
"protein": 0.0,
"carbs": 0.0,
"fat": 0.0
},
"sustainability": {
"co2perKg": 0.0,
"dietType": "OMNIVORE|VEGETARIAN|VEGAN"
},
"portions": [
{
"id": 0,
"label": "String",
"quantity": 0.0
},
{
"label": "String",
"quantity": 0.0
}
],
"liquid": false
}
Endpoint: /api/foods/user/simple
GET
Endpoint: /api/foods/user/simple/search?title={title}
GET
{
"id": 0,
"title": "string",
"brand": "string",
"category": "string",
}
Endpoint: /api/foods/{id}
DELETE
Endpoint: /api/foods/{id}/hard-delete
DELETE
Endpoint: /api/tracking
POST
portionId = null
, the tracking quantity will be directly used as the weight, meaning if portionId = null
and quantity = 260
, the weight of the tracked item would be 260 g or ml, depending on the type.{
"foodId": 0,
"portionId": 0,
"quantity": 0.0
}
{
"id": 0,
"food": {
"id": 0,
"title": "string",
"brand": "string",
"category": "string",
"isLiquid": false
},
"portion": {
"id": 1,
"label": "string",
"quantity": 0.0
},
"quantity": 0.0,
"timestamp": [
0,
0,
0,
0,
0,
0,
0
]
}
Endpoint: /api/tracking/{id}
PUT
{
"portionId": 0,
"quantity": 0.0
}
Endpoint: /api/tracking/user
GET
{
"id": 0,
"food": {
"id": 0,
"title": "string",
"brand": "string",
"category": "string",
"isLiquid": false
},
"portion": {
"id": 0,
"label": "string",
"quantity": 0.0
},
"quantity": 0.0,
"timestamp": [
0,
0,
0,
0,
0,
0,
0
]
}
Endpoint: /api/tracking/user/date?date={YYYY-MM-DD}
GET
{
"trackings": [
{
"id": 0,
"food": {
"id": 0,
"title": "string",
"brand": "string",
"category": "string",
"isLiquid": false
},
"portion": {
"id": 0,
"label": "string",
"quantity": 0.0
},
"quantity": 0.0,
"timestamp": [
0,
0,
0,
0,
0,
0,
0
]
}
],
"summary": {
"totalCalories": 0.0,
"totalProtein": 0.0,
"totalCarbs": 0.0,
"totalFat": 0.0,
"totalCo2": 0.0,
"totalVeganMeals": 0,
"totalVegetarianMeals": 0,
"dailyPoints": 0
}
}
Endpoint: /api/tracking/{id}
DELETE
Endpoint: /api/user/total
GET
Endpoint: /api/user/date?date={YYYY-MM-DD}
GET
{
"totalCalories": 0.0,
"totalProtein": 0.0,
"totalCarbs": 0.0,
"totalFat": 0.0,
"totalCo2": 0.0,
"totalVeganMeals": 0,
"totalVegetarianMeals": 0,
"totalPoints": 0
}
Open an Issue
develop
branch.Develop and Test
git clone https://github.com/your-username/nutritrack.git
cd nutritrack
git checkout -b issue-number-branch-name
Commit Changes
git commit -m "Fixes #issue-number: Description of the feature or fix"
Push to your Fork
git push origin issue-number-branch-name
Open a Pull Request
develop
branch of the original repository. In the PR description, include a reference to the issue using keywords like "Fixes|Resolves|Closes #issue-number". This will automatically link the PR to the issue and close the issue when the PR is merged.NutriTrack uses several open-source components. Below is a list of these components and their respective licenses:
postgres:16.2
dpage/pgadmin4
maven:3.8.3-openjdk-17-slim
Author: Claudio Schmidt Clausioporosis
A full list of contributors can be found on GitHub Insights.
This software is proprietary and all rights are reserved by the author.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.