A full-stack calorie tracking application built with React, NestJS, and Google AI (Gemini) for intelligent meal recognition.
- AI-Powered Meal Recognition: Take a photo of your meal and get instant nutritional analysis
- Real-time Calorie Tracking: See your daily targets, consumed calories, and remaining macros
- Macro Tracking: Track protein, carbs, and fats with visual progress bars
- Daily Summary: View all your meals and progress for the day
cal-ai/
├── backend/ # NestJS backend API
│ ├── src/
│ │ ├── ai/ # Google AI integration
│ │ ├── meals/ # Meals module (controller, service, DTOs)
│ │ └── config/ # Configuration module
│ └── .env # Environment variables
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ └── services/ # API service
│ └── package.json
└── shared/ # Shared TypeScript types
└── types.ts
- Node.js 18+ and npm
- Google AI Studio API key (Get it here)
- Navigate to backend directory:
cd backend- Install dependencies:
npm install- Create
.envfile (copy from.env.example):
cp .env.example .env- Add your Google AI API key to
.env:
GOOGLE_AI_API_KEY=your_api_key_here
PORT=3001
- Start the backend server:
npm run start:devThe backend will run on http://localhost:3001
- Navigate to frontend directory:
cd frontend- Install dependencies:
npm install- Start the development server:
npm run devThe frontend will run on http://localhost:3000
Get today's summary including targets, consumed, remaining, and meals.
Query Parameters:
date(optional): Date in YYYY-MM-DD format
Response:
{
"date": "2024-01-15",
"targets": {
"calories": 2000,
"protein": 150,
"carbs": 250,
"fats": 65
},
"consumed": {
"calories": 500,
"protein": 45,
"carbs": 60,
"fats": 20
},
"remaining": {
"calories": 1500,
"protein": 105,
"carbs": 190,
"fats": 45
},
"meals": [...]
}Analyze a meal image using Google AI.
Request:
- Form data with
imagefile
Response:
{
"foodItems": ["grilled chicken", "rice", "vegetables"],
"calories": 650,
"protein": 45,
"carbs": 60,
"fats": 20,
"confidence": 0.85
}Log a meal to the daily summary.
Request Body:
{
"name": "Grilled Chicken with Rice",
"foodItems": ["grilled chicken", "rice"],
"calories": 650,
"protein": 45,
"carbs": 60,
"fats": 20
}Response: Updated daily summary
- Start both servers (backend on port 3001, frontend on port 3000)
- Open the app in your browser at
http://localhost:3000 - View your daily targets - See calories, protein, carbs, and fats goals
- Take a photo - Click "Take Photo & Analyze Meal" button
- Review analysis - The AI will analyze your meal and show nutritional breakdown
- Confirm meal - Review the projected remaining calories and confirm to add the meal
- Track progress - See your remaining calories and macros update in real-time
- Frontend: React 18, TypeScript, Vite
- Backend: NestJS, TypeScript
- AI: Google Gemini Pro Vision API
- State Management: React Hooks
- HTTP Client: Axios
- Currently uses in-memory storage (meals are lost on server restart)
- Default user is "default-user" (authentication not implemented yet)
- Default targets are 2000 calories, 150g protein, 250g carbs, 65g fats
- For production, replace in-memory storage with a database (Firebase Firestore, PostgreSQL, etc.)
- User authentication (Firebase Auth)
- Database integration (Firebase Firestore)
- User profile and personalized targets
- BMI calculation and goal-based recommendations
- Weight tracking
- Historical data and charts
- Barcode scanning
- Meal plan suggestions
MIT