A gamified nutrition tracking application that helps you level up your health by turning your nutrition goals into quests!
This repository was forked from mern-stack-example which is based on this MongoDB MERN tutorial.
- ๐ฎ Gamified Nutrition Tracking - Turn your nutrition goals into quests
- ๐ค User Account Management - Secure signup and login with JWT authentication
- ๐ Achievement System - Unlock ranks (Bronze, Silver, Gold) based on daily streaks
- ๐ Progress Visualization - Track your nutrition journey with detailed stats
- ๐ง Water Intake Tracking - Monitor daily hydration goals
- ๐ฝ๏ธ Meal Logging - Log meals with detailed nutrition information
- ๐ฏ Custom Nutrition Goals - Set personalized calorie, protein, carbs, fat, and water goals
- ๐ Admin Dashboard - Complete admin panel for user and food management
- ๐ Role-Based Access - Secure admin and member user roles
- ๐ Real-time Stats - Live updates of nutrition progress and game stats
- Frontend: React 19, TypeScript, Vite, CSS3
- Backend: Node.js, Express.js, MongoDB
- Database: MongoDB Atlas
- Authentication: JWT (JSON Web Tokens)
- Password Security: bcryptjs for password hashing
ChompQuest/
โโโ mern/
โ โโโ server/ # Backend API
โ โ โโโ routes/ # API endpoints
โ โ โโโ middleware/ # Authentication middleware
โ โ โโโ db/ # Database connection
โ โ โโโ scripts/ # Utility scripts
โ โโโ chompquest-frontend/ # React frontend
โ โโโ src/
โ โ โโโ components/ # React components
โ โ โ โโโ admin/ # Admin dashboard components
โ โ โ โโโ mainPage/ # Main app components
โ โ โโโ types/ # TypeScript type definitions
โ โโโ public/ # Static assets
- Node.js (v18 or higher)
- MongoDB Atlas account
- npm or yarn
-
Clone the repository
git clone <your-repo-url> cd ChompQuest
-
Set up the backend
cd mern/server npm install -
Configure environment variables Create
mern/server/.envwith your MongoDB Atlas URI and JWT secret:ATLAS_URI=mongodb+srv://<username>:<password>@<your-cluster>.mongodb.net/ PORT=5050 JWT_SECRET=your-super-secret-jwt-key-here
Important:
- Replace
<username>,<password>, and<your-cluster>with your MongoDB Atlas credentials - Generate a strong JWT_SECRET (see JWT Setup section below)
- Never commit your
.envfile to version control
- Replace
-
Start the backend server
npm start
-
Set up the frontend
cd ../chompquest-frontend npm install -
Start the frontend development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173to see ChompQuest in action!
-
Using Node.js crypto module:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))" -
Using OpenSSL:
openssl rand -hex 64
-
Online generator (for development only): Visit a secure random string generator and create a 64+ character string
Add the generated secret to your mern/server/.env file:
JWT_SECRET=your-generated-secret-here-
Run the admin creation script:
cd mern/server node createAdminUser.js -
Follow the prompts to create your admin account
-
Login with admin credentials to access the admin dashboard
- User Management: View, edit, and delete user accounts
- Food Item Management: Add, edit, and delete food items from the database
- Game Stats Management: Modify user points and streaks
- System Overview: Monitor application usage and user activity
POST /user/signup- Create a new user accountPOST /user/login- Authenticate user and receive JWT token
GET /user/profile- Get user profile informationPUT /user/profile- Update user profilePUT /user/change-password- Change user passwordGET /user/game-stats- Get user's game statisticsPUT /user/game-stats- Update user's game statistics
GET /user/nutrition-goals- Get user's nutrition goalsPOST /user/nutrition-goals- Save user's nutrition goalsPUT /user/nutrition-goals- Update user's nutrition goalsPOST /user/nutrition-streak- Update nutrition streak and daily goalsPOST /user/check-daily-goals- Check daily goal completion status
POST /nutrition/meals- Log a new mealGET /nutrition/meals- Get user's meal historyDELETE /nutrition/meals/:id- Delete a meal
POST /nutrition/water- Log water intakeGET /nutrition/water- Get water intake history
GET /admin/users- Get all usersGET /admin/users/:id- Get specific userPUT /admin/users/:id/role- Update user rolePUT /admin/users/:id/game-stats- Update user game statsDELETE /admin/users/:id- Delete userGET /admin/foods- Get all food itemsPOST /admin/foods- Add new food itemPUT /admin/foods/:id- Update food itemDELETE /admin/foods/:id- Delete food item
- Bronze (Rank 1): 0-14 day streak
- Silver (Rank 2): 15-29 day streak
- Gold (Rank 3): 30+ day streak
- Daily Goal Completion: +10 points
- Streak Maintenance: Points accumulate with daily streaks
- Real-time Updates: Points update immediately when goals are met
Users must meet all nutrition goals in a single day:
- Calorie goal
- Protein goal
- Carbohydrate goal
- Fat goal
- Water intake goal
- Frontend:
http://localhost:5173 - Backend:
http://localhost:5050
Backend:
npm start # Start the serverFrontend:
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
npm test # Run tests- JWT Authentication: Secure token-based authentication
- Password Hashing: bcryptjs for secure password storage
- Role-Based Access: Admin and member user roles
- Input Validation: Comprehensive validation for all user inputs
- Protected Routes: Middleware protection for sensitive endpoints
- 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
This project is licensed under the MIT License - see the LICENSE file for details.