Clausioporosis / NutriTrack

SWT Project
0 stars 0 forks source link

NutriTrack

The Sustainable Nutrition Tracking App

Table of Contents

  1. Project Overview
  2. Technologies Used
  3. Points System
  4. Environment Setup
  5. Security
  6. Database Schema
  7. API Documentation
  8. Contribution
  9. Licenses

Project Overview

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.

Technologies Used

NutriTrack leverages the following key technologies:

Points System

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.

Functionality

Environment Setup

Prerequisites

Before setting up the project, ensure you have the following software installed on your machine:

Cloning the Repository

Clone the project repository from GitHub:

git clone https://github.com/Clausioporosis/nutritrack.git
cd nutritrack

Docker Setup

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:

Running the Application

docker-compose up -d

The application will be accessible at http://localhost:8080.

Stopping the Services

docker-compose down

Additional Notes

Security

NutriTrack implements various security measures to protect user data and ensure secure access to the API.

Authentication

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.

Extracting User ID from JWT Token

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.

Database Schema

Below is the database schema for NutriTrack, providing a visual overview of how the data is structured and related:

NutriTrack PostgreSQL Schema using DrawSQL

API Documentation

Authentication API

Endpoint: /api/auth/register

Endpoint: /api/auth/authenticate

User API

Endpoint: /api/users

Endpoint: /api/users/{id}

Endpoint: /api/users/search?keyword={keyword}

Endpoint: /api/users/me

User Response Body

{
     "id": 0,
     "username": "string",
     "email": "string",
     "firstName": "string",
     "lastName": "string"
}

Endpoint: /api/users/{id}

Food API

Endpoint: /api/foods

Endpoint: /api/foods/user

Endpoint: /api/foods/{id}

Food Response Body

    {
        "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}

    {
        "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

Endpoint: /api/foods/user/simple/search?title={title}

Simple Food Response Body

    {
        "id": 0,
        "title": "string",
        "brand": "string",
        "category": "string",
    }

Endpoint: /api/foods/{id}

Endpoint: /api/foods/{id}/hard-delete

Tracking API

Endpoint: /api/tracking

Endpoint: /api/tracking/{id}

Endpoint: /api/tracking/user

Endpoint: /api/tracking/user/date?date={YYYY-MM-DD}

Endpoint: /api/tracking/{id}

User Stats API

Endpoint: /api/user/total

Endpoint: /api/user/date?date={YYYY-MM-DD}

Stats Response Body

    {
        "totalCalories": 0.0,
        "totalProtein": 0.0,
        "totalCarbs": 0.0,
        "totalFat": 0.0,
        "totalCo2": 0.0,
        "totalVeganMeals": 0,
        "totalVegetarianMeals": 0,
        "totalPoints": 0
    }

Contribution

How to Contribute

  1. Open an Issue

    • Start by opening an issue on the repository to describe the bug you've found or the feature you'd like to add. Be as detailed as possible.
    • Once the issue is created, use the GitHub interface to create a new branch directly from the issue page. This ensures that your branch is linked to the issue. Make sure to base your new branch on the develop branch.
  2. Develop and Test

    • Clone your forked repository to your local machine.
    git clone https://github.com/your-username/nutritrack.git
    cd nutritrack
    • Checkout the branch created from the issue.
    git checkout -b issue-number-branch-name
    • Implement your changes and thoroughly test them.
  3. Commit Changes

    • Commit your changes with a meaningful commit message, referencing the issue number.
    git commit -m "Fixes #issue-number: Description of the feature or fix"
  4. Push to your Fork

    • Push your branch to your forked repository.
    git push origin issue-number-branch-name
  5. Open a Pull Request

    • Open a pull request from your branch to the 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.
    • Provide a detailed description of your changes and any additional context or information that might be helpful for the review.

Issues

Licenses

NutriTrack uses several open-source components. Below is a list of these components and their respective licenses:

Spring Boot Starter Web

Spring Boot Starter Test

Spring Boot Devtools

Spring Boot Maven Plugin

PostgreSQL

pgAdmin

Maven

Authors and Contributors

Author: Claudio Schmidt Clausioporosis

Contributors

A full list of contributors can be found on GitHub Insights.

Proprietary License

This software is proprietary and all rights are reserved by the author.

Terms

  1. The Software may not be used for any commercial purpose without the explicit written permission of the copyright holder.
  2. The Software may not be modified, merged, published, distributed, sublicensed, or sold without the explicit written permission of the copyright holder.
  3. Redistributions of the Software in source or binary forms must retain the above copyright notice, this list of conditions, and the following disclaimer.

Disclaimer

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.