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) β
βββββββββββββββ ββββββββββββββββ ββββββββββββββββββ ββββββββββββββββ
- 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
| 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 |
| 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 |
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
- Python 3.12+
- Node.js 18+
- PostgreSQL with pgvector extension
- Cohere API key or OpenAI API key
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 ..cp src/.env.example src/.envOpen 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=OPENAIProduction mode (single port 5000 β builds React then serves via FastAPI):
bash start.sh
# β http://localhost:5000Development mode (hot-reload on both frontend and backend):
bash dev.sh
# Frontend β http://localhost:5000 (Vite HMR)
# Backend β http://localhost:8000 (uvicorn --reload)Base URL: http://localhost:5000/api/v1
Interactive docs: /api/docs (Swagger UI) Β· /api/redoc
| 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 |
| 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
}| 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": []
}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
| 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.
| 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 |
Before deploying:
- Set
JWT_SECRET_KEYto a cryptographically strong random value - Set
ALLOWED_ORIGINSto your actual domain (not*) - Set your
COHERE_API_KEYorOPENAI_API_KEY - Ensure
src/.envis 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;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-nameImportant: Do not modify src/controllers/ProcessController.py β this file is part of the core RAG pipeline and is intentionally preserved as-is.
MIT License β see LICENSE for details.
