A comprehensive full-stack web application that helps you stay hydrated throughout the day with smart reminders and detailed analytics. Built with modern web technologies and featuring push notifications, offline support, and beautiful visualizations.
- JWT-based authentication with email and password
- Secure password hashing using bcrypt
- User profile management and settings
- Web Push Notifications that work even when the website is closed
- Hourly reminders from 1 AM to 12 PM
- VAPID keys for secure notification delivery
- Custom notification actions (Log Water, Snooze)
- 10-second audio alert when notification is clicked
- Quick logging with preset amounts (Half Glass, Full Glass, Bottle, Large Bottle)
- Custom amount input (1-2000ml)
- Real-time progress tracking toward daily goals
- Recent intake history with timestamps
- Interactive charts using Chart.js
- Multiple view options: Daily, Weekly, Monthly, Hourly
- Time-range filtering and customizable periods
- Peak consumption hour analysis
- Progress summaries and statistics
- Responsive design built with React and Tailwind CSS
- Beautiful gradient backgrounds and smooth animations
- Mobile-first approach with excellent desktop experience
- Dark mode support and accessibility features
- Progressive Web App (PWA) with offline support
- Service Worker for background notifications
- MongoDB database with efficient indexing
- RESTful API with comprehensive error handling
- Real-time data synchronization
- Node.js with Express.js framework
- MongoDB with Mongoose ODM
- JWT for authentication
- bcryptjs for password hashing
- web-push for notifications
- node-cron for scheduled tasks
- React 18 with modern hooks
- Vite for fast development and building
- Tailwind CSS for styling
- Chart.js with React integration
- Axios for API calls
- React Router for navigation
- Service Worker for PWA functionality
- VAPID keys for secure push notifications
- Environment variables for configuration
- ESLint and Prettier for code quality
hydration-app/
βββ backend/
β βββ server.js # Express server setup
β βββ models/ # MongoDB schemas
β β βββ User.js
β β βββ WaterLog.js
β β βββ Subscription.js
β βββ routes/ # API endpoints
β β βββ auth.js
β β βββ water.js
β β βββ notifications.js
β βββ utils/ # Utility functions
β β βββ jwt.js
β β βββ webPush.js
β β βββ generateVapidKeys.js
β βββ cron/ # Scheduled tasks
β β βββ notifications.js
β βββ .env.example # Environment template
β βββ package.json
βββ frontend/
β βββ public/
β β βββ sw.js # Service Worker
β β βββ manifest.json # PWA manifest
β β βββ sounds/
β β βββ alert.mp3 # Notification sound
β βββ src/
β β βββ components/ # React components
β β β βββ WaterLogger.jsx
β β β βββ Analytics.jsx
β β β βββ NotificationToggle.jsx
β β β βββ AudioAlert.jsx
β β βββ pages/ # Page components
β β β βββ Login.jsx
β β β βββ Signup.jsx
β β β βββ Dashboard.jsx
β β βββ api/ # API integration
β β β βββ api.js
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β βββ .env.example # Environment template
β βββ package.json
βββ README.md # This file
- Node.js 16+ and npm
- MongoDB (local installation or Atlas cloud)
- Modern web browser with push notification support
# Clone the repository
git clone <repository-url>
cd hydration-app
# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm installBackend (.env):
cd backend
cp .env.example .envEdit backend/.env:
NODE_ENV=development
PORT=5000
FRONTEND_URL=http://localhost:3000
MONGODB_URI=mongodb://localhost:27017/hydration-app
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
VAPID_EMAIL=mailto:your-email@example.comFrontend (.env):
cd frontend
cp .env.example .envEdit frontend/.env:
VITE_API_URL=http://localhost:5000/apiVAPID keys are required for push notifications:
cd backend
npm run generate-vapidCopy the generated keys to your backend/.env file:
VAPID_PUBLIC_KEY=your-generated-public-key
VAPID_PRIVATE_KEY=your-generated-private-keyTerminal 1 - Backend:
cd backend
npm run devTerminal 2 - Frontend:
cd frontend
npm run devThe app will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- Sign up for a new account or login with existing credentials
- Enable push notifications in the Settings tab for hourly reminders
- Set your daily water goal (default: 2000ml)
- Start logging your water intake using the quick buttons or custom amounts
- Use preset buttons: Half Glass (100ml), Full Glass (200ml), Bottle (500ml), Large Bottle (1000ml)
- Enter custom amounts up to 2000ml per entry
- View real-time progress toward your daily goal
- See recent entries with timestamps
- Daily View: Track intake over days/weeks/months
- Weekly View: See weekly patterns and trends
- Monthly View: Long-term hydration habits
- Hourly View: Discover your peak drinking times
- Receive hourly reminders from 1 AM to 12 PM
- Click notifications to open the app with sound alert
- Use notification actions for quick logging
- Disable/enable anytime in Settings
Backend:
npm start # Start production server
npm run dev # Start development server with nodemon
npm run generate-vapid # Generate VAPID keys for push notificationsFrontend:
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production buildAuthentication:
POST /api/auth/signup- Create new user accountPOST /api/auth/login- User loginGET /api/auth/me- Get current userPUT /api/auth/profile- Update user profile
Water Logging:
POST /api/water/log- Log water intakeGET /api/water/logs- Get water logs with paginationDELETE /api/water/logs/:id- Delete water log entry
Analytics:
GET /api/water/analytics/today- Today's summaryGET /api/water/analytics/daily- Daily analyticsGET /api/water/analytics/weekly- Weekly analyticsGET /api/water/analytics/monthly- Monthly analyticsGET /api/water/analytics/hourly- Hourly breakdown
Notifications:
GET /api/notifications/vapid-public-key- Get VAPID public keyPOST /api/notifications/subscribe- Subscribe to push notificationsPOST /api/notifications/unsubscribe- Unsubscribe from notificationsPOST /api/notifications/test- Send test notification
Users Collection:
{
email: String (unique, required),
password: String (hashed, required),
name: String,
dailyGoal: Number (default: 2000),
notificationsEnabled: Boolean (default: true),
createdAt: Date,
updatedAt: Date
}WaterLogs Collection:
{
userId: ObjectId (required),
amountMl: Number (required, 1-2000),
type: String (half-glass, full-glass, half-liter, liter, custom),
notes: String,
timestamp: Date (default: now),
createdAt: Date,
updatedAt: Date
}Subscriptions Collection:
{
userId: ObjectId (required),
endpoint: String (unique, required),
keys: {
p256dh: String (required),
auth: String (required)
},
userAgent: String,
isActive: Boolean (default: true),
lastNotificationSent: Date,
failedAttempts: Number (default: 0),
createdAt: Date,
updatedAt: Date
}Production Environment Variables:
Backend:
NODE_ENV=production
PORT=5000
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/hydration-app
JWT_SECRET=your-very-secure-jwt-secret-for-production
VAPID_PUBLIC_KEY=your-production-vapid-public-key
VAPID_PRIVATE_KEY=your-production-vapid-private-key
VAPID_EMAIL=mailto:your-production-email@domain.com
FRONTEND_URL=https://your-domain.comFrontend:
VITE_API_URL=https://your-api-domain.com/api- Heroku (Backend) + Netlify/Vercel (Frontend)
- DigitalOcean App Platform (Full-stack)
- AWS EC2 with MongoDB Atlas
- Docker containers with Docker Compose
Backend:
npm install --production
npm startFrontend:
npm run build
# Serve the dist/ folder with a static server1. Push Notifications Not Working:
- Check if VAPID keys are properly configured
- Verify HTTPS is enabled in production
- Ensure browser supports push notifications
- Check service worker registration
2. Database Connection Issues:
- Verify MongoDB is running (local) or connection string is correct (Atlas)
- Check firewall settings and network connectivity
- Ensure database user has proper permissions
3. CORS Errors:
- Verify
FRONTEND_URLin backend environment variables - Check if both frontend and backend are running on correct ports
- Ensure credentials are properly configured
4. Authentication Issues:
- Verify JWT secret is consistent
- Check token expiration settings
- Ensure cookies/localStorage is not being cleared
Enable debug logging:
# Backend
DEBUG=hydration-app:* npm run dev
# Frontend
VITE_DEBUG=true npm run devThis project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
If you have any questions or need help:
- Check the Issues page
- Create a new issue with detailed description
- Include logs and environment details
- Follow the issue template
- Chart.js for beautiful data visualizations
- Tailwind CSS for rapid UI development
- MongoDB for flexible data storage
- Express.js for robust API development
- React ecosystem for modern frontend development
Built with β€οΈ for better hydration habits
Stay hydrated and healthy! π§