Skip to content

Santipac/nutrianalyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯— AI Food Nutrition Analyzer

An intelligent web application that analyzes food and provides detailed nutritional information using AI. Designed for health-conscious users who want to better understand what they eat and receive personalized advice.

🌟 Features

πŸ“Š Complete Nutritional Analysis

  • Macronutrient analysis: Proteins, carbohydrates, fats, and fiber
  • Micronutrient information: Essential vitamins and minerals
  • Calorie counting: Accurate estimation of caloric content
  • Health score: Overall food healthiness evaluation (0-100)

πŸ€– Smart Nutritional Chat

  • Natural conversations with a virtual nutritionist
  • Personalized advice based on your profile
  • Responses in your preferred language
  • Specific recommendations according to your fitness goals

πŸ‘€ Personalized Profiles

  • Basic information: age, gender, height, weight
  • Fitness objectives: weight loss, muscle gain, maintenance
  • Training frequency
  • Recommendations tailored to your profile

πŸ›‘οΈ Backend Protection

  • Smart rate limiting without database
  • Protection against prompt injection and malicious content
  • Multiple security layers
  • Flexible configuration for different environments

πŸš€ Technologies & Libraries

Frontend

Backend & AI

  • Vercel AI SDK - AI model integration
  • OpenAI GPT-3.5 Turbo - Language model for analysis and chat
  • Next.js API Routes - Backend endpoints
  • Edge Runtime - Optimized execution

Development Tools

  • pnpm - Fast package manager
  • PostCSS - CSS processor
  • ESLint - Code linting
  • Prettier - Code formatting

πŸ› οΈ Installation & Setup

Prerequisites

  • Node.js 18+
  • pnpm (automatically installs if you use npm)

1. Clone the repository

git clone <repository-url>
cd food-analyzer

2. Install dependencies

npm install -g pnpm  # if you don't have pnpm installed
pnpm install

3. Configure environment variables

Create a .env.local file in the project root:

# Required
OPENAI_API_KEY=your_openai_key_here

# Optional - Rate Limiting (default values)
CHAT_MAX_REQUESTS=20           # Requests per minute for chat
NUTRITION_MAX_REQUESTS=10      # Requests per minute for analysis
GLOBAL_MAX_REQUESTS=100        # Global requests every 5 minutes

# Optional - Security
MAX_REQUEST_SIZE=51200         # 50KB maximum per request
MAX_MESSAGE_LENGTH=2000        # Maximum characters per message
ENABLE_RATE_LIMITING=true      # Enable protections

4. Run in development

pnpm dev

The application will be available at http://localhost:3000

5. Build for production

pnpm build
pnpm start

πŸ”’ Security

The project includes multiple protection layers:

  • Rate Limiting: Prevents abuse with endpoint-specific limits
  • Content validation: Detects prompt injection and malicious content
  • Size limits: Controls request and message sizes
  • Robust identification: IP + User Agent for user identification
  • Flexible configuration: Adjust limits according to environment

See complete documentation in the security configuration file.

πŸ—οΈ Project Architecture

src/
β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”œβ”€β”€ api/               # Backend endpoints
β”‚   β”‚   β”œβ”€β”€ chat/          # Nutritional chat
β”‚   β”‚   └── nutrition-analysis/ # Food analysis
β”‚   β”œβ”€β”€ chat/              # Chat page
β”‚   └── page.tsx           # Main page
β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ analysis/          # Analysis components
β”‚   β”œβ”€β”€ chat/              # Chat components
β”‚   β”œβ”€β”€ onboarding/        # Profile form
β”‚   └── ui/                # Base components (Radix UI)
β”œβ”€β”€ lib/                   # Utilities and configuration
β”‚   β”œβ”€β”€ rate-limiter.ts    # Rate limiting system
β”‚   β”œβ”€β”€ security-middleware.ts # Security middleware
β”‚   β”œβ”€β”€ config.ts          # Central configuration
β”‚   └── utils.ts           # General utilities
β”œβ”€β”€ stores/                # Global state (Zustand)
β”œβ”€β”€ interfaces/            # TypeScript types
└── helpers/               # Helper functions

🀝 Contributing

Contributions are welcome! If you have ideas to improve the project:

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

πŸ“„ License

This project is under the MIT License - see the LICENSE file for details.

This means you can:

  • βœ… Use the code commercially
  • βœ… Modify the code
  • βœ… Distribute the code
  • βœ… Private use
  • βœ… Include in proprietary projects

No restrictions. Use it however you want, learn from it, improve it, share it.


Developed as a portfolio project to demonstrate skills in:

  • Full-Stack development with Next.js and TypeScript
  • AI API integration (OpenAI)
  • State management and component architecture
  • Security implementation without database
  • Modern and accessible UI/UX design

Releases

No releases published

Packages

 
 
 

Contributors