A comprehensive, full-stack nutrition tracking platform
Revolutionize how individuals monitor their dietary habits and achieve their health goals through intelligent tracking, detailed analytics, and seamless user experience.
- β¨ Features
- π οΈ Tech Stack
- π Quick Start
- βοΈ Installation
- π§ Configuration
- π Google Fit Integration
- π± Usage
- ποΈ Project Structure
- π API Documentation
- π§ͺ Testing
- π Deployment
- π€ Contributing
- π License
- π¬ Support
β
Security Hardened - Environment variables, JWT authentication, bcrypt encryption
β
Google Fit Verified - Ready for OAuth verification and public access
β
Performance Optimized - Code splitting, lazy loading, optimized bundles
β
Clean Architecture - Modular design, error handling, comprehensive logging
|
|
| User Type | Benefits | Key Features |
|---|---|---|
| Individuals | Health improvement, goal achievement | Personal tracking, progress visualization, export reports |
| Healthcare Providers | Patient monitoring, data-driven decisions | Detailed analytics, professional reports, treatment compliance |
| Organizations | Employee wellness, cost reduction | Workplace wellness programs, productivity insights |
- Frontend: React 18 with Vite for fast development and optimized builds
- Backend: Node.js/Express RESTful API with MongoDB database
- Authentication: JWT tokens with bcryptjs password hashing
- Styling: Tailwind CSS with Framer Motion animations
- Data Visualization: Chart.js for interactive analytics
- External APIs: Google Fit integration for fitness data
# Clone the repository
git clone https://github.com/yourusername/calories-tracker.git
cd calories-tracker
# Install dependencies
npm install
# Setup environment variables
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env
# Start the application (Windows)
./run.bat
# Or start manually
# Terminal 1 - Backend
cd backend && npm run dev
# Terminal 2 - Frontend
cd frontend && npm run devπ Access the application:
- Frontend:
http://localhost:5173 - Backend API:
http://localhost:5000
- Node.js (version 16.0.0 or higher)
- MongoDB (local installation or MongoDB Atlas)
- npm or yarn package manager
# 1. Clone the repository
git clone https://github.com/yourusername/calories-tracker.git
cd calories-tracker
# 2. Install root dependencies
npm install
# 3. Install backend dependencies
cd backend
npm install
# 4. Install frontend dependencies
cd ../frontend
npm installCreate backend/.env from the example:
cd backend
cp .env.example .env# Database
MONGODB_URI=mongodb://127.0.0.1:27017/kaloriApp
# Authentication
JWT_SECRET=your-super-secure-jwt-secret-key-here
# Server
PORT=5000
NODE_ENV=development
# CORS (optional)
CLIENT_URL=http://localhost:5173Create frontend/.env from the example:
cd frontend
cp .env.example .env# API Configuration
VITE_API_URL=http://localhost:5000
# Google Fit Integration (optional)
VITE_GOOGLE_CLIENT_ID=your_google_client_id.apps.googleusercontent.com
VITE_GOOGLE_API_KEY=your_google_api_key
β οΈ Security Note: Never commit.envfiles to version control. Keep your secrets secure!
The application includes seamless Google Fit integration for automatic fitness data synchronization. Follow these steps to enable Google Fit connectivity:
- Google Cloud Console account
- Google Fit API enabled
- OAuth 2.0 credentials configured
-
Create a Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select an existing one
- Note your project ID for reference
-
Enable Google Fit API
# Navigate to APIs & Services > Library # Search for "Fitness API" and enable it
-
Create OAuth 2.0 Credentials
- Go to APIs & Services > Credentials
- Click "Create Credentials" > "OAuth 2.0 Client ID"
- Configure the consent screen if prompted
- Select "Web application" as application type
- Add authorized origins:
http://localhost:5173(development)https://yourdomain.com(production)
- Add authorized redirect URIs:
http://localhost:5173/auth/google/callback(development)https://yourdomain.com/auth/google/callback(production)
Update your frontend/.env file with Google Fit credentials:
# Google Fit Integration
VITE_GOOGLE_CLIENT_ID=your_google_client_id_here.apps.googleusercontent.com
VITE_GOOGLE_API_KEY=your_google_api_key_here
# Optional: Google Fit Configuration
VITE_GOOGLE_FIT_SCOPES=https://www.googleapis.com/auth/fitness.activity.read,https://www.googleapis.com/auth/fitness.body.read- Create an API Key
- In Google Cloud Console, go to APIs & Services > Credentials
- Click "Create Credentials" > "API Key"
- Copy the generated API key
- Restrict the API key (recommended):
- Click on the API key to edit
- Under "API restrictions", select "Restrict key"
- Choose "Fitness API" from the list
-
Configure Consent Screen
- Go to APIs & Services > OAuth consent screen
- Choose "External" user type (for public apps)
- Fill in required information:
- App name: "Calories Tracker"
- User support email: your email
- Developer contact information: your email
-
Add Required Scopes
- Click "Add or Remove Scopes"
- Add the following scopes:
https://www.googleapis.com/auth/fitness.activity.readhttps://www.googleapis.com/auth/fitness.body.readhttps://www.googleapis.com/auth/fitness.location.read
-
Add Test Users (for development)
- Add email addresses of users who will test the integration
- Note: Remove this step when publishing to production
For production deployment, you'll need to verify your app:
-
Submit for Verification
- Complete the OAuth consent screen with all required information
- Add privacy policy and terms of service URLs
- Submit for Google's review process
-
Domain Verification
- Verify ownership of your domain
- Add your production URLs to authorized origins
-
Development Testing
cd frontend npm run dev- Navigate to the Activities page (Ψ¨ΩΨ§ΩΨ§Ψͺ Ψ§ΩΨ³Ψ§ΨΉΨ© Ψ§ΩΨ°ΩΩΨ©)
- Click "Ψ§ΩΨ§ΨͺΨ΅Ψ§Ω Ψ¨Ω Google Fit" (Connect to Google Fit)
- Complete the OAuth flow
- Verify data synchronization
-
Debug Mode
- The app includes a Google Fit debug component
- Check browser console for detailed logs
- Use the test functions in
utils/googleFitTest.js
β
Automatic Data Sync: Steps, calories, distance, and heart rate
β
Real-time Updates: Data refreshes every 30 minutes
β
Smart Form Population: Activity forms auto-fill with Google Fit data
β
Connection Status: Visual indicators for connection status
β
Quick Sync Button: One-click data synchronization
β
Persistent Connection: Maintains connection across sessions
Issue: "Google Fit CLIENT_ID is not configured"
- Solution: Ensure
VITE_GOOGLE_CLIENT_IDis set in your.envfile
Issue: "OAuth error: redirect_uri_mismatch"
- Solution: Verify redirect URIs in Google Cloud Console match your app URLs
Issue: "Access blocked: This app's request is invalid"
- Solution: Complete OAuth consent screen configuration and add test users
Issue: "API key not valid"
- Solution: Check API key restrictions and ensure Fitness API is enabled
π Environment Variables: Never commit API keys to version control
π API Key Restrictions: Always restrict API keys to specific APIs and domains
π HTTPS Only: Use HTTPS in production for secure OAuth flows
π Token Storage: Tokens are stored securely in browser localStorage
π Scope Limitation: Request only necessary permissions from users
- User Consent: Users must explicitly consent to Google Fit access
- Data Minimization: Only necessary fitness data is accessed
- Secure Storage: All tokens and data are handled securely
- User Control: Users can disconnect Google Fit at any time
For detailed Google Fit setup instructions, see GOOGLE_FIT_SETUP.md
# Option 1: Quick start (Windows)
./run.bat
# Option 2: Manual start
# Terminal 1 - Backend with auto-reload
cd backend && npm run dev
# Terminal 2 - Frontend with hot reload
cd frontend && npm run dev# Build frontend
cd frontend && npm run build
# Start backend
cd backend && npm start| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm start |
Start production server |
npm run build |
Build for production |
npm test |
Run test suite |
npm run lint |
Run ESLint |
- Frontend: http://localhost:5173
- Backend: http://localhost:5000
- MongoDB: mongodb://localhost:27017
http://localhost:5000/api
| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/register |
Register new user |
POST |
/auth/login |
User login |
POST |
/auth/logout |
User logout |
GET |
/auth/me |
Get current user |
| Method | Endpoint | Description |
|---|---|---|
GET |
/foods |
Get food database |
POST |
/foods |
Add new food |
GET |
/calories |
Get calorie entries |
POST |
/calories |
Add calorie entry |
GET |
/users/profile |
Get user profile |
PUT |
/users/profile |
Update user profile |
GET |
/reports/export |
Export data (PDF/DOCX) |
| Method | Endpoint | Description |
|---|---|---|
POST |
/activities/sync-google-fit |
Sync Google Fit data |
GET |
/activities/fitness-data |
Get fitness data |
π Full API Documentation: Available at
/api/docswhen server is running
calories-tracker/
βββ π backend/ # Node.js Backend
β βββ π api/ # API utilities
β βββ π middleware/ # Auth & validation
β βββ π models/ # MongoDB models
β βββ π routes/ # API endpoints
β βββ π config/ # Configuration
β βββ π server.js # Entry point
β βββ π .env.example # Environment template
βββ π frontend/ # React Frontend
β βββ π public/ # Static assets
β βββ π src/
β β βββ π components/ # Reusable components
β β βββ π pages/ # Route components
β β βββ π context/ # State management
β β βββ π utils/ # Helper functions
β β βββ π services/ # API services
β β βββ π App.jsx # Main component
β βββ π vite.config.js # Vite configuration
β βββ π .env.example # Environment template
βββ π package.json # Root dependencies
βββ π run.bat # Quick start script
βββ π README.md # Documentation
/backend- Express.js API server with MongoDB/frontend- React 18 application with Vite/components- Reusable UI components/pages- Route-based page components/context- Global state management/services- API communication layer
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run backend tests
cd backend && npm test
# Run frontend tests
cd frontend && npm test- Unit Tests - Individual component testing
- Integration Tests - API endpoint testing
- E2E Tests - Full user workflow testing
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prod# Build frontend
cd frontend && npm run build
# Start production server
cd backend && npm startSet these in your deployment platform:
# Backend
MONGODB_URI=mongodb+srv://...
JWT_SECRET=your-production-secret
NODE_ENV=production
# Frontend
VITE_API_URL=https://your-api-domain.com
VITE_GOOGLE_CLIENT_ID=your-google-client-idWe welcome contributions! Please follow these steps:
- Fork the repository
- Clone your fork
- Create a feature branch
- Make your changes
- Test your changes
- Submit a pull request
# Fork and clone
git clone https://github.com/yourusername/calories-tracker.git
cd calories-tracker
# Create feature branch
git checkout -b feature/amazing-feature
# Make changes and commit
git commit -m "Add amazing feature"
# Push to your fork
git push origin feature/amazing-feature- β Follow existing code style
- β Write tests for new features
- β Update documentation
- β Keep commits atomic and descriptive
- β Run linting before submitting
# Lint code
npm run lint
# Format code
npm run format
# Run tests
npm test- π Lighthouse Score: 95+
- π¦ Bundle Size: < 500KB initial load
- β‘ API Response: < 200ms average
- π§ͺ Test Coverage: 85%+
- β Chrome 90+
- β Firefox 88+
- β Safari 14+
- β Edge 90+
This project is licensed under the MIT License.
- β Commercial use - Use in commercial projects
- β Modification - Modify and adapt the code
- β Distribution - Share and distribute
- β Private use - Use privately
- β Liability - No warranty provided
- β Patent use - No patent rights granted
- π Documentation - Check this README and inline docs
- π Bug Reports - Create an issue
- π‘ Feature Requests - Request a feature
- π¬ Discussions - GitHub Discussions
- π§ Email: [email protected]
- π GitHub: @marawan10