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.
- 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)
- Natural conversations with a virtual nutritionist
- Personalized advice based on your profile
- Responses in your preferred language
- Specific recommendations according to your fitness goals
- Basic information: age, gender, height, weight
- Fitness objectives: weight loss, muscle gain, maintenance
- Training frequency
- Recommendations tailored to your profile
- Smart rate limiting without database
- Protection against prompt injection and malicious content
- Multiple security layers
- Flexible configuration for different environments
- Next.js 15 - React framework with App Router
- React 19 - User interface library
- TypeScript - Static typing
- Tailwind CSS - Utility-first CSS framework
- Radix UI - Accessible and unstyled components
- Lucide React - Modern SVG icons
- Zustand - Lightweight state management
- 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
- pnpm - Fast package manager
- PostCSS - CSS processor
- ESLint - Code linting
- Prettier - Code formatting
- Node.js 18+
- pnpm (automatically installs if you use npm)
git clone <repository-url>
cd food-analyzernpm install -g pnpm # if you don't have pnpm installed
pnpm installCreate 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 protectionspnpm devThe application will be available at http://localhost:3000
pnpm build
pnpm startThe 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.
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
Contributions are welcome! If you have ideas to improve the project:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Open a Pull Request
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