Skip to content

bounswe/bounswe2025group9

Repository files navigation

Visit our website 👇

Nutrihub Logo

Or watch our website and mobile demos.


About Us

We are Computer Engineering students studying at Boğaziçi University.
We are taking the course CmpE 451: Introduction to Software Engineering together.
To learn more about the team and the project, visit our Wiki Page.

bounswe2025group9

CmpE 352 Codebase

Installation

Project Overview

NutriHub is a comprehensive platform that helps users discover and manage affordable and healthy food options. The project consists of three main components:

  • Frontend (React + TypeScript)
  • Backend (Django)
  • Mobile App (React Native)

Prerequisites

  • Docker and Docker Compose
  • Node.js (v20 or later)
  • Python (3.11 or later)
  • MySQL (8.0)

Quick Start with Docker

The easiest way to run the entire project is using Docker Compose:

  1. Clone the repository:
git clone https://github.com/bounswe/bounswe2025group9.git
cd bounswe2025group9
  1. Environment Variables:

See the .env.example file in the root directory for required environment variables. Create a .env file and add your configurations.

cp .env.example .env
# edit .env to add your configurations
source .env

The given .env.example is sufficient for local development as is.

  1. Start all services:
docker-compose up --build -d

This will start:

Production Deployment

  1. Environment Variables:
  • Use BUILD=PROD in your .env file for production settings. This switches the frontend build to use frontend/nginx.conf instead of frontend/nginx-dev.conf. The basic difference is that the production config uses https and redirects http traffic to https, while the dev config only serves http traffic.
  • Set PORT=80 for production web hosting, it will allow http traffic to be redirected to https. (see nginx.conf for details)
  • Make sure to set strong passwords for MYSQL_PASSWORD, MYSQL_ROOT_PASSWORD and DJANGO_SECRET_KEY.
  • FatSecret API credentials are required only if db initialization scripts are invoked.
  1. SSL Certificates:
  • For production, you need to set up SSL certificates for secure https connections. Use Let's Encrypt service to obtain free SSL certificates.
  • Start the app in development mode to expose port 80, then use Certbot to obtain and install the certificates.
docker-compose up --build -d # with BUILD=DEV and PORT=80
  • Following command will create a docker container to run certbot and obtain the certificates. Make sure to replace <email> with your email address and set the correct domain names.
sudo docker run --rm\
    -v $(pwd)/certbot/www:/var/www/certbot\
    -v $(pwd)/certbot/conf:/etc/letsencrypt\
    certbot/certbot certonly\
    --webroot\
    --webroot-path=/var/www/certbot\
    --email <email> # your email here\
    --agree-tos\
    --no-eff-email\
    -d nutrihub.fit\   # domain to deploy
    -d www.nutrihub.fit

This will store the obtained certificates under certbot/ directory. After obtaining the certificates, you can restart the application with production settings:

# from .env file, set:
#   BUILD=PROD 
#   PORT=80
docker-compose up --build -d

FatSecret API Integration

To use the food data features, you need to set up FatSecret API credentials:

  1. Go to FatSecret Platform API
  2. Create a new account to get your API credentials
  3. Add the following environment variables to your environment variables in the backend directory:
    FATSECRET_CONSUMER_KEY=your_consumer_key
    FATSECRET_CONSUMER_SECRET=your_consumer_secret
    

Note: The API credentials are required for:

  • Food search functionality
  • Nutritional information retrieval
  • Food database integration

Building Android APK with Docker

Prerequisites

  • Docker with at least 8GB RAM allocated, gradle build fails with OOM otherwise

Build Instructions

cd mobile/nutrihub

# Build the Docker image
docker build -t nutrihub-apk .

# Create a temporary container
docker create --name nutrihub-temp nutrihub-apk

# Extract the APK
docker cp nutrihub-temp:/app/android/app/build/outputs/apk/release/app-release.apk ./nutrihub.apk

# Clean up
docker rm nutrihub-temp

Troubleshooting

If build fails with "Gradle daemon disappeared":

  • Increase Docker memory to 8GB+ in Docker settings
  • Restart Docker

Manual Setup

Backend Setup

!! We assume that mysql database is available and running with django@localhost user and mydb database. !!

  1. Navigate to the backend directory:
cd backend
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements-dev.txt
  1. Set up environment variables:
source setup.sh  # On Windows: .\setup.sh
  1. Run migrations:
python manage.py makemigrations
python manage.py migrate
  1. Start the development server:
python manage.py runserver 9000

Frontend Setup

  1. Navigate to the frontend directory:
cd frontend
  1. Install dependencies:
npm install
  1. Start the development server:
npm start
  1. If frontend cannot reach the backend, make sure to set the correct API base URL in the environment variables. You can set backend path with VITE_API_BASE_URL="http://localhost:8080/api" environment variable, where 8080 is the port where your backend is running.

Mobile App Setup

  1. Navigate to the mobile directory:
cd mobile/nutrihub
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev

Database Setup

The project uses MySQL as the database. When running with Docker, the database is automatically configured. For manual setup:

  1. Create a MySQL database named mydb
  2. Create a user with the following credentials:
    • Username: django
    • Password: djangopass

Running Tests

Backend Tests

cd backend
python manage.py test

Frontend Tests

cd frontend
npm test

Mobile App Tests

cd mobile/nutrihub
npm test

Development Tools

Code Formatting

The project uses Black for Python code formatting:

cd backend
black .

Pre-commit Hooks

Pre-commit hooks are set up for the backend:

cd backend
pre-commit install

Project Structure

bounswe2025group9/
├── backend/           # Django backend
├── frontend/         # React frontend
├── mobile/           # React Native mobile app
└── docker-compose.yml

Contributing

  1. Create a new branch for your feature
  2. Make your changes
  3. Run tests
  4. Submit a pull request

License

This project is part of the CmpE 451 course at Boğaziçi University.