Skip to content

anandteertha/NutriBite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NutriBite

CI/CD Python Node.js FastAPI React MySQL Redis License

A comprehensive nutrition tracking and recommendation application

Built with FastAPI, React, MySQL, and Redis

FeaturesSetupAPI DocsTests

Features

  • FastAPI Backend: RESTful API with MySQL database and Redis caching
  • BCNF-Normalized Database: Efficient, normalized MySQL schema
  • React Frontend: Modern, responsive UI with reusable components
  • RAG-Based Recommender: AI-powered food recommendations using Retrieval-Augmented Generation
  • User Preferences: Customizable food preferences and dietary restrictions
  • Daily Reports: Automated nutrition analysis and recommendations
  • SOLID Principles: Clean, maintainable code following SOLID principles
  • Comprehensive Testing: Pytest for backend, Cypress for frontend
  • CI/CD Pipeline: Automated testing and deployment with GitHub Actions

Tech Stack

Backend

  • FastAPI
  • SQLAlchemy (ORM)
  • MySQL
  • Redis (caching/sessions)
  • Pydantic (validation)
  • LangChain (RAG)
  • OpenAI API
  • Pytest

Frontend

  • React 18
  • React Router
  • TanStack Query (React Query)
  • Axios
  • Vite
  • Cypress

Project Structure

NutriBite/
├── backend/
│   ├── app/
│   │   ├── api/          # API routes
│   │   ├── core/         # Core configuration
│   │   ├── models/       # Database models
│   │   ├── schemas/      # Pydantic schemas
│   │   └── services/     # Business logic
│   ├── database/
│   │   └── schema.sql    # Database schema
│   ├── tests/            # Pytest tests
│   └── requirements.txt
├── frontend/
│   ├── src/
│   │   ├── components/   # Reusable components
│   │   ├── contexts/     # React contexts
│   │   ├── pages/        # Page components
│   │   └── services/     # API services
│   ├── cypress/          # Cypress tests
│   └── package.json
└── .github/
    └── workflows/        # CI/CD pipelines

Setup

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • MySQL 8.0+
  • Redis 7+

Backend Setup

  1. Navigate to backend directory:
cd backend
  1. Create and activate virtual environment:
python -m venv nutribite
# On Windows:
.\nutribite\Scripts\Activate.ps1
# On Linux/Mac:
source nutribite/bin/activate
  1. Install dependencies:
pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configuration (DATABASE_URL, REDIS_URL, SECRET_KEY, etc.)
  1. Set up database:
mysql -u root -p < database/schema.sql
  1. Run the server:
python run.py
# Or: uvicorn app.main:app --reload

Frontend Setup

  1. Navigate to frontend directory:
cd frontend
  1. Install dependencies:
npm install
  1. Start development server:
npm run dev

Running Tests

Backend Tests

cd backend
pytest tests/ -v

Frontend Tests

cd frontend
npm run test        # Headless mode
npm run test:open   # Interactive mode

API Documentation

Once the backend is running, visit:

Database Schema

The database follows BCNF (Boyce-Codd Normal Form) normalization:

  • Users: User accounts and profiles
  • Foods: Food catalog with nutrition information
  • Meals: Meal instances
  • MealFoods: Junction table for meals and foods
  • UserPreferences: User nutrition targets and preferences
  • DietaryRestrictions: User dietary restrictions
  • Goals: User fitness goals
  • DailyReports: Daily nutrition summaries

Key Features

Reusable Components

  • FoodSelector: Search and select foods with quantity
  • PreferenceForm: Manage user preferences and dietary restrictions

RAG Recommender

The recommender uses Retrieval-Augmented Generation to provide personalized food recommendations based on:

  • User preferences
  • Dietary restrictions
  • Target calories
  • Historical meal data

Caching Strategy

  • User data cached in Redis
  • Food search results cached
  • Meal data cached for performance

CI/CD

The project includes GitHub Actions workflows for:

  • Automated backend testing
  • Frontend build and Cypress tests
  • Code linting
  • Coverage reporting

Development

Running in Development Mode

Backend:

cd backend
.\nutribite\Scripts\Activate.ps1  # Windows
python run.py

Frontend:

cd frontend
npm run dev

The frontend will be available at http://localhost:3000 and the backend API at http://localhost:8000.

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Follow SOLID principles
  2. Write tests for new features
  3. Update documentation
  4. Ensure all tests pass
  5. Follow the existing code style

Project Status

✅ Backend API complete
✅ Frontend UI complete
✅ Database schema implemented
✅ RAG recommender integrated
✅ Test suite configured
✅ CI/CD pipeline set up

License

This project is licensed under the MIT License - see the LICENSE file for details.


Note: Update the GitHub username in the badges above (yourusername) to match your repository.

About

A simple project to learn react with fastapi and redis cache system

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors