A full-stack web application for tracking daily nutrition intake with AI-powered recommendations. Built with vanilla JavaScript frontend and Flask backend, powered by Firebase for authentication and Firestore for data storage.
- Secure Sign Up & Login - Firebase-based authentication with email verification
- User Session Management - Persistent login with JWT tokens
- Data Isolation - Each user's data is completely isolated and secure
- Real-time Macro Tracking - Track calories, protein, carbs, and fats
- Daily Summary - View all meals logged for the day
- Progress Bars - Visual representation of macro consumption vs. goals
- Quick Add Meal - Easily add meals from a form or food database
- Add Meals - Log meals manually or from the 223-food database
- Food Database - Search through 223+ pre-loaded foods with nutritional data
- Delete Meals - Remove meals if logged incorrectly
- Meal Types - Categorize meals as breakfast, lunch, dinner, or snack
- Set Personal Goals - Define daily calorie and macro targets
- Edit Goals - Modify goals at any time
- Reset to Defaults - Quickly reset to recommended values
- Goal Tracking - Monitor progress against your personal goals
- Smart Alerts - Get notified when exceeding or falling short on macros
- Personalized Suggestions - AI recommends foods to help meet your goals
- Weekly Insights - View trends and patterns in your nutrition over time
- Eating Patterns - AI detects your eating habits and patterns
- Weekly Trends - Average daily consumption across macros
- Daily History - View detailed breakdown for each day of the week
- Pattern Detection - Identify your nutrition habits and tendencies
- Responsive Design - Works perfectly on desktop, tablet, and mobile
- HTML5, CSS3, Vanilla JavaScript - No heavy frameworks, fast and lightweight
- Firebase SDK - Real-time authentication
- CSV Parser - Efficient food database loading
- Responsive Design - Mobile-first approach
- Flask 2.3.3 - Lightweight Python web framework
- Firebase Admin SDK - Server-side Firebase operations
- Python 3 - Backend logic and AI recommendations
- CORS Enabled - Seamless frontend-backend communication
- Firebase Authentication - Secure user authentication
- Firestore - Real-time NoSQL database
- JWT Tokens - Bearer token authentication for API calls
AI-Nutrition-tracker/
├── frontend/
│ ├── index.html # Main HTML file
│ ├── assets/
│ │ ├── css/
│ │ │ └── styles.css # Responsive styling (1,189 lines)
│ │ ├── js/
│ │ │ ├── app.js # Main app logic (1,097 lines)
│ │ │ └── firebase-config.js # Firebase configuration
│ │ └── data/
│ │ └── foods.csv # 223 foods database
│ └── README.md
├── backend/
│ ├── run.py # Flask entry point
│ ├── requirements.txt # Python dependencies
│ ├── Procfile # Deployment configuration
│ ├── serviceAccountKey.json # Firebase credentials (in .gitignore)
│ └── app/
│ ├── __init__.py # Flask app factory
│ ├── models/
│ │ ├── meal.py # Meal data model
│ │ └── user_goals.py # User goals model
│ ├── routes/
│ │ ├── auth.py # Authentication endpoints
│ │ ├── goals.py # Goals management endpoints
│ │ ├── meals.py # Meal management endpoints
│ │ ├── recommendations.py # AI recommendations
│ │ └── summary.py # Daily summary endpoints
│ ├── services/
│ │ └── ai_recommendations.py # AI logic
│ └── utils/
│ ├── firebase_config.py # Firebase setup
│ └── decorators.py # Auth decorators
└── README.md
- Python 3.8+
- Node.js (optional, for frontend development)
- Firebase account & project
- Google Cloud credentials
git clone https://github.com/vaibhav8a/AI-Nutrition-tracker.git
cd AI-Nutrition-tracker-
Create Python Virtual Environment
cd backend python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
pip install -r requirements.txt
-
Configure Firebase
- Go to Firebase Console
- Create a new project or use existing one
- Generate a service account key (Project Settings → Service Accounts)
- Save as
backend/serviceAccountKey.json
-
Create
.envFile (in backend folder)FLASK_PORT=5001 FLASK_DEBUG=True FIREBASE_DATABASE_URL=https://your-project.firebaseio.com
-
Start Backend Server
python run.py
Backend will run on
http://localhost:5001
-
Navigate to Frontend
cd ../frontend -
Configure Firebase (if needed)
- Edit
assets/js/firebase-config.js - Add your Firebase project credentials
- Edit
-
Start Frontend Server
python3 -m http.server 8000
Frontend will run on
http://localhost:8000 -
Open in Browser
- Navigate to
http://localhost:8000 - Create an account or login
- Navigate to
POST /api/auth/signup- Register new userPOST /api/auth/login- Login user
GET /api/goals/get- Get user's goalsPOST /api/goals/set- Set/update goalsPOST /api/goals/reset- Reset to defaults
POST /api/meals/add- Add a mealGET /api/meals/daily/{date}- Get meals for a specific dateDELETE /api/meals/delete/{date}/{mealId}- Delete a meal
GET /api/summary/today- Get today's nutrition summary
GET /api/recommendations/today- Get daily recommendationsGET /api/recommendations/weekly-trends- Get weekly insights
The app comes with 223 pre-loaded foods organized by category:
- Proteins - Chicken, beef, fish, eggs, tofu, etc.
- Carbs - Rice, pasta, bread, potatoes, oats, etc.
- Fats - Olive oil, nuts, seeds, avocado, etc.
- Vegetables - Broccoli, carrots, spinach, tomatoes, etc.
- Fruits - Apples, bananas, berries, oranges, etc.
- Dairy - Milk, yogurt, cheese, etc.
Each food includes:
- Calories per serving
- Protein content (g)
- Carbs content (g)
- Fats content (g)
- Go to
http://localhost:8000 - Click "Sign Up"
- Enter email and password
- Account created and automatically logged in
- A modal will appear asking for daily nutrition goals
- Enter target calories, protein, carbs, and fats
- Click "Save Goals"
- Go to "Add Meal" page
- Choose to:
- Search Food Database - Find from 223+ foods
- Custom Meal - Enter custom nutritional values
- Select meal type (breakfast, lunch, dinner, snack)
- Click "Add Meal"
- See today's nutrition summary
- Track progress towards your goals
- View all meals logged today
- Go to "Insights" page
- See weekly averages
- View eating patterns detected by AI
- Review daily history
- Go to "Settings" page
- Edit or reset your daily goals
- View your account information
- Push code to GitHub
- Connect Railway to your GitHub repo
- Set environment variables (Firebase credentials)
- Railway auto-detects
Procfileand starts the app
- Push code to GitHub
- Connect Vercel to your GitHub repo
- Set build output to
frontenddirectory - Update
API_BASE_URLinapp.jsto your Railway backend URL
[See detailed deployment guide in project documentation]
- Firebase Authentication - Industry-standard auth
- JWT Tokens - Secure API communication
- CORS Enabled - Only allow frontend requests
- Environment Variables - Sensitive data in .env files
- Git Ignore -
serviceAccountKey.jsonnever committed
The app is fully responsive:
- Desktop (900px+) - 3-column layout
- Tablet (768px-899px) - 2-column layout
- Mobile (320px-767px) - 1-column stacked layout
- Ensure backend is running:
python run.pyfrom/backend - Check
API_BASE_URLinapp.jsmatches backend URL - Verify CORS is enabled in backend
- Check
firebase-config.jshas correct credentials - Ensure Firebase SDK script is loaded (check browser console)
- Verify Firebase project exists and is active
- Clear browser cache and reload
- Check browser console for JavaScript errors
- Ensure modal classes are correctly applied
- Verify
foods.csvexists infrontend/assets/data/ - Check browser Network tab for 404 errors
- Ensure CSV is properly formatted
foods.csv format:
Food Name,Calories,Protein,Carbs,Fats
Chicken Breast,165,31,0,3.6
Brown Rice,111,2.6,23,0.9
...
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available under the MIT License.
Vaibhav Srivastava
- GitHub: @vaibhav8a
- Project: AI-Nutrition-tracker
- Firebase for authentication and database
- Flask for backend framework
- Community feedback and contributions
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review troubleshooting section above
Happy tracking! 🥗💪