Skip to content

Latest commit

 

History

History
286 lines (196 loc) · 4.6 KB

File metadata and controls

286 lines (196 loc) · 4.6 KB

NutriPick Setup Guide

Prerequisites

  1. Node.js (v18 or higher)
  2. MongoDB (v5.0 or higher)
  3. npm or yarn

Installation Steps

1. Install MongoDB

Windows:

# Download MongoDB Community Server from:
# https://www.mongodb.com/try/download/community

# Or use Chocolatey:
choco install mongodb

# Start MongoDB service:
net start MongoDB

macOS:

brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community

Linux:

# Ubuntu/Debian
sudo apt-get install mongodb

# Start MongoDB
sudo systemctl start mongod
sudo systemctl enable mongod

Alternative: Use MongoDB Atlas (Cloud)

  1. Go to https://www.mongodb.com/cloud/atlas
  2. Create a free cluster
  3. Get your connection string
  4. Update server/.env with your connection string

2. Install Dependencies

# Install server dependencies
cd server
npm install

# Install frontend dependencies
cd ../frontend
npm install

3. Configure Environment Variables

Server (.env)

GROQ_API_KEY="your_groq_api_key_here"
DATABASE_URL="mongodb://localhost:27017/nutripick"
PORT=4000

Frontend (.env)

NEXT_PUBLIC_API_URL=http://localhost:4000/api

4. Initialize Database

cd server

# Generate Prisma Client
npm run db:generate

# Push schema to MongoDB
npm run db:push

5. Start the Application

Development Mode

Terminal 1 - Start Backend:

cd server
npm run dev

Terminal 2 - Start Frontend:

cd frontend
npm run dev

Production Mode

# Build frontend
cd frontend
npm run build
npm start

# Start backend
cd ../server
npm start

Verify Installation

  1. Check Backend: Open http://localhost:4000

    • You should see the API welcome message
  2. Check Database:

    cd server
    npm run db:studio
    • Opens Prisma Studio to view your database
  3. Check Frontend: Open http://localhost:3000

    • You should see the NutriPick homepage

API Endpoints

Food Analysis

  • POST /api/food/analyze - Analyze food image
  • GET /api/food/analyses - Get all analyses
  • GET /api/food/analyses/:id - Get specific analysis

Eateries

  • POST /api/eateries - Create eatery
  • GET /api/eateries - Get all eateries
  • GET /api/eateries/:id - Get specific eatery
  • POST /api/menu/analyze - Analyze menu image

Canteen

  • POST /api/canteen/analyze - Analyze canteen meal
  • GET /api/canteen/meals - Get all meals
  • GET /api/canteen/stats - Get statistics

Products

  • POST /api/products/scan - Scan product barcode
  • GET /api/products/:id - Get product details

Troubleshooting

MongoDB Connection Issues

Error: "MongoServerError: connect ECONNREFUSED" Solution:

# Check if MongoDB is running
# Windows:
net start MongoDB

# macOS/Linux:
sudo systemctl status mongod

Prisma Client Issues

Error: "PrismaClient is unable to be run in the browser" Solution:

cd server
npm run db:generate

Port Already in Use

Error: "EADDRINUSE: address already in use" Solution:

# Windows:
netstat -ano | findstr :4000
taskkill /PID <PID> /F

# macOS/Linux:
lsof -ti:4000 | xargs kill -9

CORS Issues

Error: "CORS policy: No 'Access-Control-Allow-Origin' header" Solution: Ensure frontend .env has correct API URL:

NEXT_PUBLIC_API_URL=http://localhost:4000/api

Database Management

View Database

cd server
npm run db:studio

Reset Database

cd server
npm run db:push -- --force-reset

Backup Database

mongodump --db nutripick --out ./backup

Restore Database

mongorestore --db nutripick ./backup/nutripick

Development Tips

  1. Hot Reload: Both frontend and backend support hot reload in dev mode

  2. API Testing: Use tools like Postman or Thunder Client to test API endpoints

  3. Database Inspection: Use Prisma Studio (npm run db:studio) to view and edit data

  4. Logs: Check console output for detailed error messages

Production Deployment

Environment Variables

Set these in your production environment:

DATABASE_URL="mongodb+srv://user:pass@cluster.mongodb.net/nutripick"
GROQ_API_KEY="your_production_key"
PORT=4000
NODE_ENV=production

Build Commands

# Frontend
cd frontend
npm run build

# Backend
cd server
npm run db:generate
npm start

Support

For issues or questions:

  1. Check the logs in console
  2. Review DATABASE_ARCHITECTURE.md for API documentation
  3. Ensure all environment variables are set correctly
  4. Verify MongoDB is running and accessible