Skip to content

Youssefx64/End-to-End-Nutrition-RAG-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

114 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


NutriAI Logo

NutriAI

AI-powered nutrition intelligence β€” grounded in your own documents

Upload nutrition PDFs β†’ Process & embed β†’ Ask questions β†’ Get precise, evidence-based answers


Python FastAPI React PostgreSQL Vite Tailwind CSS License: MIT


NutriAI Landing RAG JWT Cohere


Overview

NutriAI is a production-ready full-stack SaaS platform that brings AI-powered question answering to your private nutrition knowledge base. Built on Retrieval-Augmented Generation (RAG), every answer is grounded in documents you upload β€” not model hallucinations.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Upload PDF  │───▢│ Chunk + Embed│───▢│ pgvector Index │───▢│  LLM Answer  β”‚
β”‚  or TXT file β”‚    β”‚  (Cohere /   β”‚    β”‚  Vector Search β”‚    β”‚ (RAG-groundedβ”‚
β”‚              β”‚    β”‚   OpenAI)    β”‚    β”‚  Similarity    β”‚    β”‚   response)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

  • RAG Pipeline β€” Upload β†’ Chunk β†’ Embed β†’ Index β†’ Retrieve β†’ Generate
  • Semantic Search β€” Vector similarity search via pgvector or Qdrant
  • Multi-LLM Support β€” Cohere (command-a-03-2025) or OpenAI, switchable via env
  • JWT Authentication β€” Secure register/login with 7-day tokens
  • Premium UI β€” Dark-mode SaaS interface built with Framer Motion animations
  • Single-port Production β€” FastAPI serves the compiled React build on one port
  • Private Knowledge Base β€” Per-user, per-project document isolation
  • Real-time Processing Feedback β€” Step-by-step upload β†’ chunk β†’ index progress UI
  • Swagger & ReDoc β€” Auto-generated API documentation at /api/docs
  • Metrics β€” Prometheus metrics via starlette-exporter

Tech Stack

Backend

Layer Technology
Framework FastAPI 0.110 + Uvicorn
ORM SQLAlchemy 2.0 (async) + asyncpg
Vector DB pgvector (PostgreSQL) Β· Qdrant
LLM / Embeddings Cohere 5.6 Β· OpenAI 2.2
RAG LangChain 0.1
Auth python-jose (JWT) Β· bcrypt 4.1
PDF Parsing PyMuPDF 1.24
Monitoring Prometheus Β· starlette-exporter

Frontend

Layer Technology
Framework React 18 + Vite 5
Routing React Router 6
Styling Tailwind CSS 3
Animations Framer Motion 11
Icons Lucide React
HTTP Axios
Markdown react-markdown
File Upload react-dropzone
Notifications react-hot-toast

Project Structure

nutriai/
β”œβ”€β”€ src/                          # FastAPI backend
β”‚   β”œβ”€β”€ main.py                   # App factory, CORS, routers, static serving
β”‚   β”œβ”€β”€ .env.example              # Environment variable template
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth.py               # POST /register, /login  GET|PUT /me
β”‚   β”‚   β”œβ”€β”€ data.py               # POST /upload, /process
β”‚   β”‚   β”œβ”€β”€ nlp.py                # POST /index/push, /answer  GET /index/info
β”‚   β”‚   └── schema/               # Pydantic request/response models
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ DataController.py     # File validation & path management
β”‚   β”‚   β”œβ”€β”€ NLPController.py      # RAG orchestration
β”‚   β”‚   └── ProcessController.py  # Chunking logic (do not modify)
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ db_schemas/           # SQLAlchemy ORM models
β”‚   β”‚   β”‚   └── user.py           # User model (auto-created on startup)
β”‚   β”‚   └── ProjectModel.py       # Project creation and retrieval
β”‚   └── helpers/
β”‚       └── config.py             # Pydantic Settings (env vars)
β”‚
β”œβ”€β”€ frontend/                     # React + Vite SPA
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx               # Router + auth guards
β”‚   β”‚   β”œβ”€β”€ index.css             # Tailwind + design system tokens
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.jsx   # JWT state management
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.js            # Axios client + interceptors
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   └── Layout.jsx        # Sidebar shell + route transitions
β”‚   β”‚   └── pages/
β”‚   β”‚       β”œβ”€β”€ Landing.jsx       # Public marketing page
β”‚   β”‚       β”œβ”€β”€ Login.jsx         # Split-screen auth
β”‚   β”‚       β”œβ”€β”€ Register.jsx      # Split-screen auth
β”‚   β”‚       β”œβ”€β”€ Dashboard.jsx     # Stats + quick actions
β”‚   β”‚       β”œβ”€β”€ Chat.jsx          # RAG chat interface
β”‚   β”‚       β”œβ”€β”€ Documents.jsx     # Upload + process + index
β”‚   β”‚       └── Profile.jsx       # Account management
β”‚   └── dist/                     # Production build (served by FastAPI)
β”‚
β”œβ”€β”€ start.sh                      # Production startup script
β”œβ”€β”€ dev.sh                        # Development startup (two servers)
β”œβ”€β”€ .gitignore
└── README.MD

Quick Start

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • PostgreSQL with pgvector extension
  • Cohere API key or OpenAI API key

1 β€” Clone & install

git clone https://github.com/Youssefx64/End-to-End-Nutrition-RAG-System.git
cd End-to-End-Nutrition-RAG-System

# Python dependencies
pip install -r src/requirements.txt

# Node dependencies
cd frontend && npm install && cd ..

2 β€” Configure environment

cp src/.env.example src/.env

Open src/.env and fill in:

# Required
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_MAIN_DATABASE=nutriai

# Generate a strong secret:  python3 -c "import secrets; print(secrets.token_hex(32))"
JWT_SECRET_KEY=your_random_secret_here

# Pick one LLM provider
COHERE_API_KEY=your_cohere_key_here
# OPENAI_API_KEY=your_openai_key_here
# GENERATION_BACKEND=OPENAI

3 β€” Run

Production mode (single port 5000 β€” builds React then serves via FastAPI):

bash start.sh
# β†’ http://localhost:5000

Development mode (hot-reload on both frontend and backend):

bash dev.sh
# Frontend β†’ http://localhost:5000  (Vite HMR)
# Backend  β†’ http://localhost:8000  (uvicorn --reload)

API Reference

Base URL: http://localhost:5000/api/v1

Interactive docs: /api/docs (Swagger UI) Β· /api/redoc

Authentication

Method Endpoint Description Auth
POST /auth/register Create account β†’ returns JWT β€”
POST /auth/login Sign in β†’ returns JWT β€”
GET /auth/me Get current user Bearer
PUT /auth/me Update profile Bearer

Data Pipeline

Method Endpoint Description Auth
POST /data/upload/{project_id} Upload PDF or TXT file Bearer
POST /data/process/{project_id} Chunk file into DataChunks Bearer

Process request body:

{
  "file_id": "abc123.pdf",
  "chunk_size": 512,
  "overlap_size": 50,
  "do_reset": 0
}

NLP / RAG

Method Endpoint Description Auth
POST /nlp/index/push/{project_id} Embed chunks β†’ push to vector DB Bearer
GET /nlp/index/info/{project_id} Vector DB collection stats Bearer
POST /nlp/index/search/{project_id} Semantic similarity search Bearer
POST /nlp/index/answer/{project_id} RAG question answering Bearer

Answer request body:

{
  "text": "What are the best plant-based protein sources?",
  "limit": 5
}

Answer response:

{
  "signal": "rag_answer_success",
  "answer": "Based on your documents, the top complete plant proteins are...",
  "full_prompt": "...",
  "chat_history": []
}

RAG Architecture

User Question
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   NLPController                      β”‚
β”‚                                                     β”‚
β”‚  1. Embed question  ──▢  Cohere/OpenAI Embeddings   β”‚
β”‚                                                     β”‚
β”‚  2. Vector search   ──▢  pgvector / Qdrant          β”‚
β”‚                          (cosine similarity, top-K) β”‚
β”‚                                                     β”‚
β”‚  3. Build prompt    ──▢  Retrieved chunks           β”‚
β”‚                          + question template        β”‚
β”‚                                                     β”‚
β”‚  4. Generate        ──▢  Cohere command-a-03-2025   β”‚
β”‚                          or OpenAI GPT              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
  Grounded Answer

Environment Variables

Variable Required Default Description
JWT_SECRET_KEY βœ… β€” Random secret for JWT signing
ALLOWED_ORIGINS β€” * CORS origins (comma-separated)
POSTGRES_USERNAME βœ… β€” PostgreSQL username
POSTGRES_PASSWORD βœ… β€” PostgreSQL password
POSTGRES_HOST βœ… localhost PostgreSQL host
POSTGRES_PORT βœ… 5432 PostgreSQL port
POSTGRES_MAIN_DATABASE βœ… β€” Database name
GENERATION_BACKEND β€” COHERE COHERE or OPENAI
EMBEDDING_BACKEND β€” COHERE COHERE or OPENAI
COHERE_API_KEY βœ…* β€” Cohere API key
OPENAI_API_KEY βœ…* β€” OpenAI API key
GENERATION_MODEL_ID β€” command-a-03-2025 LLM model identifier
EMBEDDING_MODEL_ID β€” embed-multilingual-v3.0 Embedding model
VECTOR_DB_BACKEND β€” PGVECTOR PGVECTOR or QDRANT
FILE_MAX_SIZE β€” 10 Max upload size in MB

*One of COHERE_API_KEY or OPENAI_API_KEY is required.


Pages

Route Description
/ Landing page β€” features, how it works, CTA
/register Create account
/login Sign in
/dashboard Knowledge base stats, quick actions, getting started
/chat AI chat β€” RAG-powered Q&A against your documents
/documents Upload, process, and index documents
/profile Edit profile, security info

Production Checklist

Before deploying:

  • Set JWT_SECRET_KEY to a cryptographically strong random value
  • Set ALLOWED_ORIGINS to your actual domain (not *)
  • Set your COHERE_API_KEY or OPENAI_API_KEY
  • Ensure src/.env is not committed (protected by .gitignore)
  • Configure PostgreSQL with the pgvector extension enabled

Generate a strong secret key:

python3 -c "import secrets; print(secrets.token_hex(32))"

Enable pgvector in PostgreSQL:

CREATE EXTENSION IF NOT EXISTS vector;

Contributing

Contributions are welcome! Here's how to get started:

# 1. Fork the repository
# 2. Create a feature branch
git checkout -b feature/your-feature-name

# 3. Make your changes, following existing code patterns
# 4. Test your changes
bash dev.sh

# 5. Commit with a clear message
git commit -m "feat: add your feature description"

# 6. Push and open a Pull Request
git push origin feature/your-feature-name

Important: Do not modify src/controllers/ProcessController.py β€” this file is part of the core RAG pipeline and is intentionally preserved as-is.


License

MIT License β€” see LICENSE for details.


Built with FastAPI Β· React Β· pgvector Β· Cohere


Live Demo Β· Report Bug Β· Request Feature

About

A Retrieval-Augmented Generation (RAG) based multilingual chatbot specialized in nutrition & diet planning. It combines powerful NLP models with a curated nutrition knowledge base to provide personalized diet recommendations, meal plans, and fitness tips based on user input (age, weight, activity level, health goals, dietary preferences).

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors