Skip to content

aamrindersingh/NutriScan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NutriScan - Intelligent Nutrition Management Platform

Enterprise-Grade Nutrition Tracking β€’ RAG-Based AI Assistant β€’ Real-time Analytics

Neon Next.js Node.js Firebase Gemini TypeScript


Overview

NutriScan is a comprehensive nutrition management platform that leverages cutting-edge AI technology to provide personalized dietary insights and recommendations. Built with modern web technologies and powered by Neon's serverless PostgreSQL database, the platform offers scalable, real-time nutrition tracking capabilities for health-conscious individuals and organizations.

Key Features

πŸ” Intelligent Food Recognition

  • Barcode Scanning: Advanced barcode detection using ZXing library
  • Product Database Integration: Real-time data from OpenFoodFacts API
  • Nutritional Analysis: Comprehensive macro and micronutrient breakdown

πŸ€– RAG-Based AI Chatbot

  • Conversational Interface: Natural language conversations about nutrition and health goals
  • Retrieval-Augmented Generation: Personalized responses based on user history, consumption logs, and preferences
  • Context-Aware Responses: AI maintains conversation context and provides relevant nutritional guidance
  • Personal Health Insights: AI analyzes user data to provide tailored dietary advice and goal tracking support

οΏ½ Intelligent Product Analysis

  • AI-Powered Health Scoring: Comprehensive health assessment of food products (1-100 scale)
  • Nutritional Insights: Detailed analysis of positive aspects and health concerns for each product
  • Alternative Suggestions: AI-recommended healthier alternatives with availability information
  • Personalized Recommendations: Product-specific consumption advice based on user preferences and health goals

οΏ½ Nutrition Tracking & Goals

  • Daily Goal Management: Customizable targets for calories, macros, and micronutrients
  • Consumption Logging: Historical tracking of food intake with detailed nutritional breakdown
  • Progress Monitoring: Real-time updates on daily nutritional goals and achievements
  • User Profiles: Personalized settings and dietary preferences management

Architecture & Technology Stack

Frontend Architecture

  • Framework: Next.js 14 with App Router for optimal performance and SEO
  • Language: TypeScript for type safety and enhanced developer experience
  • Styling: Tailwind CSS with custom component library using Radix UI primitives
  • State Management: React Context API with optimized re-rendering patterns
  • PWA Features: Next-PWA integration for offline functionality and app-like experience
  • Performance: Code splitting, dynamic imports, and image optimization

Backend Infrastructure

  • Runtime: Node.js with Express.js framework for scalable API development
  • Database ORM: Sequelize with advanced query optimization and relationship management
  • Authentication: Firebase Admin SDK for secure token validation and user management
  • Rate Limiting: Express-based throttling for API protection and performance
  • Middleware Stack: Helmet for security, Morgan for logging, Compression for optimization

Database & Storage Solutions

  • Primary Database: Neon PostgreSQL - Serverless, auto-scaling, and branch-based development
  • Authentication Store: Firebase Auth for user credentials and session management
  • Performance Optimization: Database indexing and query optimization scripts
  • Data Integrity: Sequelize migrations and model relationships for consistent data structure

AI & Machine Learning Integration

  • Language Model: Google Gemini Pro for natural language processing and generation
  • RAG Implementation: Custom retrieval system combining user data with nutritional knowledge base
  • External APIs: OpenFoodFacts integration for comprehensive product information
  • Data Processing: Advanced nutrition calculation algorithms and recommendation engines

Getting Started

Prerequisites

  • Node.js 18+ and npm/yarn package manager
  • Neon PostgreSQL database instance
  • Firebase project with Authentication enabled
  • Google Gemini AI API access

Installation & Setup

1. Clone the Repository

git clone https://github.com/aamrindersingh/NutriScan-backend.git
cd NutriScan-backend

2. Backend Configuration

cd backend
npm install

# Configure environment variables
cp .env.example .env
# Edit .env with your configuration values

# Initialize database
npm run init-db

# Start development server
npm run dev

3. Frontend Configuration

cd frontend
npm install

# Configure environment variables
cp .env.local.example .env.local
# Edit .env.local with your configuration values

# Start development server
npm run dev

Environment Configuration

Backend Environment Variables (.env)

# Database Configuration
DATABASE_URL=postgresql://user:[email protected]/nutriscan

# Firebase Configuration
FIREBASE_SERVICE_ACCOUNT_KEY=path/to/your/firebase-service-account.json

# AI Configuration
GEMINI_API_KEY=your_google_gemini_api_key

# Server Configuration
PORT=3001
NODE_ENV=development

# Security
JWT_SECRET=your_jwt_secret_key
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

Frontend Environment Variables (.env.local)

# API Configuration
NEXT_PUBLIC_API_URL=http://localhost:3001

# Firebase Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id

# PWA Configuration
NEXT_PUBLIC_APP_NAME=NutriScan
NEXT_PUBLIC_APP_DESCRIPTION=Intelligent Nutrition Management Platform

Database Schema & Migrations

The application uses Sequelize ORM with the following core entities:

  • Users: Authentication and basic user information
  • Profiles: Extended user profiles with preferences and settings
  • DailyGoals: Customizable nutritional targets and objectives
  • FoodItems: Comprehensive food database with nutritional information
  • ConsumptionLogs: Historical tracking of user food consumption

Running Migrations

cd backend
npm run migrate
npm run seed # Optional: populate with sample data

Development Workflow

Code Structure

backend/
β”œβ”€β”€ config/          # Database and service configurations
β”œβ”€β”€ controllers/     # Business logic and request handlers
β”œβ”€β”€ middlewares/     # Authentication and validation middleware
β”œβ”€β”€ models/          # Sequelize database models
β”œβ”€β”€ routes/          # API route definitions
β”œβ”€β”€ services/        # External service integrations
└── utils/           # Helper functions and utilities

frontend/
β”œβ”€β”€ src/app/         # Next.js app router pages
β”œβ”€β”€ src/components/  # Reusable React components
β”œβ”€β”€ src/contexts/    # React context providers
β”œβ”€β”€ src/hooks/       # Custom React hooks
β”œβ”€β”€ src/lib/         # Utility libraries and configurations
└── src/types/       # TypeScript type definitions

Development Scripts

# Backend
npm run dev          # Start development server with hot reload
npm run build        # Build for production
npm run start        # Start production server
npm run migrate      # Run database migrations
npm run test         # Run test suite

# Frontend
npm run dev          # Start development server
npm run build        # Build optimized production bundle
npm run start        # Start production server
npm run lint         # Run ESLint code quality checks
npm run type-check   # Run TypeScript type checking

Performance & Scalability

Database Optimization

  • Neon Database Features: Serverless PostgreSQL with automatic scaling and branching
  • Connection Pooling: Optimized database connections for high-concurrency scenarios
  • Query Optimization: Indexed searches and optimized JOIN operations
  • Data Archiving: Automated cleanup and archival of historical consumption data

Frontend Performance

  • Bundle Optimization: Code splitting and tree shaking for minimal bundle sizes
  • Image Optimization: Next.js automatic image optimization and lazy loading
  • Caching Strategy: Intelligent caching of API responses and static assets
  • Progressive Loading: Skeleton screens and progressive enhancement

Powered by Neon Database

Serverless PostgreSQL β€’ Auto-scaling β€’ Developer-first

Built for the Modern Web

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published