Skip to content

feat: add XP gamification system#1525

Open
weiwei-gitch wants to merge 1 commit into
aryandas2911:mainfrom
weiwei-gitch:main
Open

feat: add XP gamification system#1525
weiwei-gitch wants to merge 1 commit into
aryandas2911:mainfrom
weiwei-gitch:main

Conversation

@weiwei-gitch

Copy link
Copy Markdown

Description
Implements a full XP (Experience Points) gamification system for DailyForge. Users now earn XP for completing tasks based on priority, maintain daily streaks for consistency bonuses, and progress through 10 levels. XP is displayed on the Dashboard, Profile, and Analytics pages with animated toast notifications on reward.

Related Issue
Closes #1179

Changes Made

  • Added xp, level, streak, lastActivityDate, and xpHistory fields to the User model
  • Created backend/utils/xpUtils.js with XP values, level thresholds, streak calculation, and streak bonus logic
  • Task completion in taskController.js now awards XP based on priority (Low: 10, Medium: 20, High: 35) with streak milestone bonuses (3/7/14/30 days)
  • New GET /api/xp endpoint returns level info, progress percent, streak, and recent XP history
  • Created XPContext.jsx for global XP state management and toast triggering
  • Created XPToast.jsx — animated floating +XP earned! notification (bottom-right)
  • Created XPProgressBar.jsx — compact card for Dashboard, full card for Profile
  • Dashboard stats row now includes XP level card with progress bar and streak
  • Profile page has a new XP & Progress section with level badge, progress bar, streak pill, and recent XP history
  • Analytics key metrics grid now shows Total XP card with level name

Checklist

  • Code runs locally
  • Followed project structure
  • No console errors
  • Properly tested changes
  • Linked the issue

Notes for Reviewers

  • XP values and level thresholds are defined in backend/utils/xpUtils.js and mirrored in frontend/src/utils/xpUtils.js — easy to tune
  • Streak is calculated server-side using UTC dates to avoid timezone issues
  • XP is only awarded once per task completion (checks status === "Completed" on update)
  • XPContext gracefully handles unauthenticated state — safe to render anywhere

- Add xp, level, streak, lastActivityDate, xpHistory fields to User model
- Create backend/utils/xpUtils.js with XP values, level thresholds, streak logic
- Award XP on task completion in taskController (priority-based + streak bonuses)
- New GET /api/xp endpoint via xpController + xpRoutes
- Expose xp/level/streak in all authController user payloads
- Add frontend/src/utils/xpUtils.js with getLevelInfo() helper
- Add XPContext (global XP state, triggerXPReward, toast management)
- Add XPToast component (animated floating +XP notification)
- Add XPProgressBar component (compact for Dashboard, full for Profile)
- Wire XPProvider into main.jsx, XPToast into App.jsx
- useTasks: fire triggerXPReward after successful task completion
- Dashboard: XPProgressBar compact card in stats row
- Profile: XP & Progress card with level, progress bar, streak, recent history
- Analytics: Total XP metric card in key metrics grid
@aryandas2911

Copy link
Copy Markdown
Owner

resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# feat: Add XP points system for completing routines and tasks

2 participants