Skip to content

AI-powered nutrition platform with comprehensive food analysis, subscription tiers, and personalized health insights. Next.js + TypeScript + PostgreSQL.

Notifications You must be signed in to change notification settings

Ashraful-Fuqha/FoodAI

Repository files navigation

FoodAI - AI-Powered Nutrition Analysis Platform

FoodAI Banner Next.js TypeScript Prisma PostgreSQL

Live Demo: food-ai-ten.vercel.app

FoodAI is a comprehensive nutrition analysis platform that provides AI-powered insights, detailed nutritional facts, and personalized health recommendations for any food item. Built with modern technologies and featuring a subscription-based model with tiered access to premium features.

✨ Features

πŸ” Core Features

  • AI-Powered Food Analysis: Get comprehensive insights on pros, cons, and health benefits
  • Detailed Nutritional Facts: Complete macronutrient and micronutrient breakdown
  • Search History: Track and revisit your nutrition exploration journey
  • Responsive Design: Seamless experience across desktop and mobile devices
  • Dark/Light Mode: Toggle between themes for comfortable viewing

πŸ’Ž Premium Features (Pro/Premium Plans)

  • Unlimited Searches: No monthly limits on food analysis
  • Organ-Specific Health Impact: Detailed analysis of how foods affect different organs
  • Cooking Tips & Meal Suggestions: Personalized recommendations for food preparation
  • Food Pairing Recommendations: Discover optimal food combinations
  • Better Alternatives: Get suggestions for healthier substitutes

πŸš€ Premium-Only Features

  • Meal Plan Generator: Create personalized nutrition plans
  • Export Functionality: Download insights as PDF/CSV
  • API Access: Integrate FoodAI data into your applications
  • Advanced Analytics: Comprehensive nutrition tracking dashboard

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 15.4.4 with App Router
  • Language: TypeScript 5.0
  • Styling: Tailwind CSS with custom components
  • UI Components: Radix UI primitives
  • Authentication: NextAuth.js v5
  • State Management: React Hooks (useState, useEffect)

Backend

  • Runtime: Node.js
  • Database: PostgreSQL with Prisma ORM
  • Authentication: NextAuth.js with multiple providers
  • Payment Processing: Razorpay integration
  • AI Integration: Google Gemini API
  • Nutrition Data: Nutritionix API

Infrastructure

  • Deployment: Vercel (99% uptime)
  • Database Hosting: PostgreSQL (Cloud)
  • Storage: Prisma with migration system
  • Email: Resend for transactional emails

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm/yarn
  • PostgreSQL database
  • Google Gemini API key
  • Nutritionix API credentials
  • Razorpay account (for payments)

Installation

  1. Clone the repository

    git clone https://github.com/Ashraful-Fuqha/FoodAI.git
    cd FoodAI
  2. Install dependencies

    npm install
  3. Set up environment variables Create a .env.local file in the root directory:

    # Database
    PRISMA_DATABASE_URL="postgresql://..."
    
    # NextAuth
    NEXTAUTH_SECRET="your-nextauth-secret"
    NEXTAUTH_URL="http://localhost:3000"
    
    # Google Gemini AI
    GEMINI_API_KEY="your-gemini-api-key"
    
    # Nutritionix API
    NUTRITIONIX_APP_ID="your-app-id"
    NUTRITIONIX_API_KEY="your-api-key"
    
    # Razorpay
    RAZORPAY_KEY_ID="your-key-id"
    RAZORPAY_KEY_SECRET="your-key-secret"
    
    # Email (Resend)
    RESEND_API_KEY="your-resend-key"
  4. Set up the database

    npx prisma generate
    npx prisma db push
  5. Run the development server

    npm run dev
  6. Open http://localhost:3000 in your browser

πŸ“Š Database Schema

The application uses a comprehensive PostgreSQL schema with the following key models:

  • User: Authentication and profile management
  • Subscription: Plan management (FREE/PRO/PREMIUM)
  • Payment: Razorpay transaction records
  • Usage: Monthly search tracking
  • SearchHistory: User food search history
  • Account/Session: NextAuth.js authentication tables

πŸ” Authentication & Authorization

  • Multiple Auth Providers: Google, GitHub, Email/Password
  • Secure Session Management: NextAuth.js with JWT
  • Email Verification: Resend integration for account verification
  • Password Hashing: bcryptjs for secure password storage
  • Route Protection: Middleware-based authentication checks

πŸ’³ Subscription System

Plan Tiers

  • Free: 10 monthly searches, basic features
  • Pro (β‚Ή49/month): Unlimited searches, advanced insights
  • Premium (β‚Ή99/month): Everything + meal plans, export, API access

Payment Integration

  • Razorpay: Secure payment processing
  • Webhook Verification: Cryptographic signature validation
  • Automatic Plan Management: Usage limits and feature access control

πŸ§ͺ Key Features Implementation

AI-Powered Insights

// Google Gemini API integration for food analysis
const insights = await getFoodAIInsights(foodName);
// Returns: pros, cons, health benefits, organ impact, cooking tips

Usage Tracking

// Automatic usage increment on successful search
await incrementUsage(userId);
// Enforces plan limits and prevents overuse

Subscription Management

// Real-time subscription status checking
const subscription = await getUserSubscription(userId);
// Controls feature access based on plan tier

πŸ“± Responsive Design

  • Mobile-First Approach: Optimized for all screen sizes
  • Touch-Friendly Interface: Easy navigation on mobile devices
  • Progressive Web App Ready: Fast loading and offline capabilities
  • Dark Mode Support: Automatic theme switching

πŸ”„ API Routes

Public Endpoints

  • GET /api/auth/* - Authentication endpoints
  • POST /api/auth/signin - User sign in

Protected Endpoints

  • GET /api/subscription/status - Get user subscription details
  • POST /api/subscription/cancel - Cancel current subscription
  • POST /api/razorpay/create-order - Create payment order
  • POST /api/razorpay/verify-payment - Verify payment success
  • DELETE /api/history/[id] - Delete search history entry

πŸš€ Deployment

The application is deployed on Vercel with the following configuration:

{
  "build": "npx prisma generate && npx next build",
  "start": "next start"
}

Environment Setup

  • Database migrations run automatically on build
  • Environment variables configured in Vercel dashboard
  • CDN optimization for static assets

πŸ§ͺ Testing & Quality

  • TypeScript: Full type safety throughout the application
  • Error Handling: Comprehensive error boundaries and try-catch blocks
  • Loading States: User-friendly loading indicators
  • Form Validation: Client-side and server-side validation

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ™ Acknowledgments

  • Google Gemini AI for powerful food analysis
  • Nutritionix for comprehensive nutrition database
  • Razorpay for seamless payment processing
  • Vercel for reliable hosting platform
  • Next.js Team for the amazing framework

πŸ“ž Contact

Mjafarsadiq D - mjafarsadiqdharwad@gmail.com

Project Link: https://github.com/Ashraful-Fuqha/FoodAI

Live Demo: https://food-ai-ten.vercel.app


⭐ Star this repo if you find it helpful!

About

AI-powered nutrition platform with comprehensive food analysis, subscription tiers, and personalized health insights. Next.js + TypeScript + PostgreSQL.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published