Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Oct 30, 2025

🎯 Summary

This PR provides a complete implementation plan for Issue #17: Splitting bonus and real energy accounts to improve user engagement and limit referral abuse.

Key Features Implemented

  1. Separate Energy Accounts

    • 💎 Real Energy: Purchased energy that never expires
    • 🎁 Bonus Energy: Free energy from referrals/daily awards that expires after 2 years
  2. Daily Activity Requirement

    • ✅ Daily bonus only granted if user was active yesterday (spent any energy)
    • 📊 Tracks last_spending_date and total_spent_yesterday
    • 🎯 Encourages regular platform usage
  3. FIFO Spending Priority

    • Oldest bonus energy used first (prevents hoarding)
    • Then real energy
    • Automatic cleanup of fully spent bonuses
  4. 2-Year Expiration on Bonuses

    • Each bonus grant tracked individually with expiration date
    • Automatic cleanup during daily cron job
    • Warnings 30 days before expiration
  5. User Notifications

    • Daily bonus granted
    • Referral activated
    • Bonus expiring soon
    • Bonus expired

📂 Implementation Files

This PR contains:

  • ISSUE-17-DESIGN.md: Comprehensive design document with architecture details
  • implementation/IMPLEMENTATION_SUMMARY.md: Step-by-step implementation guide
  • implementation/api-gateway/: Updated backend services (5 files)
    • TokensRepository.js: New spending logic with FIFO
    • TokensService.js: Updated balance checks
    • CompletionsService.js: Updated energy deduction
    • ReferralService.js: Daily activity check in cron
    • tokensController.js: New API endpoints
  • implementation/telegram-bot/: Updated bot interface (3 files)
    • MiddlewareAward.py: Enhanced notifications
    • balance_command.py: New balance display
    • Service integration examples
  • implementation/tests/: Comprehensive unit tests

🔄 Migration Strategy

Phase 1: Deploy api-gateway with backward compatibility

  • New fields optional
  • Old logic still works
  • Zero downtime

Phase 2: Run migration endpoint

POST /token/migrate?masterToken=ADMIN_TOKEN
  • Adds new fields to all existing tokens
  • Keeps existing energy as "real energy"
  • Initializes bonus tracking

Phase 3: Deploy telegram-bot updates

  • New balance display
  • Notification handling

Phase 4: Monitor

  • Daily cron job logs
  • User activity patterns
  • Notification delivery

📊 Data Structure Changes

Before:

{
  tokens_gpt: 10000  // Single balance
}

After:

{
  tokens_gpt: 10000,              // Real energy
  bonus_tokens: 5000,             // Total bonus
  bonus_history: [                // Individual grants
    {
      amount: 5000,
      granted_date: "2025-10-30T00:00:00Z",
      expires_date: "2027-10-30T00:00:00Z",  // 2 years!
      remaining: 5000,
      source: "daily_award"
    }
  ],
  last_spending_date: "2025-10-30",
  total_spent_yesterday: 150
}

🧪 Testing

Includes comprehensive unit tests for:

  • ✅ Migration (backward compatibility)
  • ✅ FIFO spending logic
  • ✅ Expiration cleanup
  • ✅ Activity tracking
  • ✅ Balance calculations
  • ✅ Edge cases

📈 Expected Impact

User Engagement:

  • ⬆️ Daily active users (must use to get bonus)
  • ⬆️ User retention (regular activity encouraged)

Referral System:

  • ✅ Limits abuse (inactive referrers don't benefit)
  • ✅ Rewards active users fairly
  • ✅ Bonus cap remains (30k balance limit)

System Health:

  • ✅ Automatic cleanup of expired bonuses
  • ✅ Clear audit trail per bonus grant
  • ✅ Manageable storage growth

⏱️ Timeline

  • Phase 1 (api-gateway core): 6-8 hours
  • Phase 2 (api-gateway cron): 2-3 hours
  • Phase 3 (telegram-bot): 3-4 hours
  • Phase 4 (testing): 4-5 hours
  • Phase 5 (deployment): 2-3 hours

Total: ~20-25 hours

🔍 Next Steps

  1. Review: Team reviews design and implementation
  2. Approval: Get sign-off from product owner
  3. Implementation: Create PRs in api-gateway and telegram-bot repos
  4. Testing: Comprehensive test coverage
  5. Staging: Deploy to staging environment
  6. Production: Gradual rollout with monitoring

📝 Files Changed

  • ISSUE-17-DESIGN.md (new)
  • implementation/IMPLEMENTATION_SUMMARY.md (new)
  • implementation/api-gateway/*.js (5 files, new)
  • implementation/telegram-bot/*.py (2 files, new)
  • implementation/tests/*.test.js (1 file, new)

🔗 Related


Note: This PR contains implementation plans and code examples. The actual changes need to be applied to the api-gateway and telegram-bot repositories separately.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: undefined
@konard konard self-assigned this Oct 30, 2025
This commit provides a complete implementation plan for issue #17:
splitting bonus and real energy accounts with expiration and activity tracking.

Key Features:
- Bonus energy expires after 2 years
- Daily bonus only granted if user was active yesterday
- FIFO spending: oldest bonus first, then real energy
- User notifications for balance changes and expirations
- Detailed balance display showing real vs bonus breakdown

Files Added:
- ISSUE-17-DESIGN.md: Complete design document with architecture
- implementation/IMPLEMENTATION_SUMMARY.md: Implementation guide
- implementation/api-gateway/*: Updated service & repository files
- implementation/telegram-bot/*: Updated bot commands & middleware
- implementation/tests/*: Comprehensive unit tests

Changes Required in External Repositories:
- api-gateway: 5 files modified (TokensRepository, TokensService, CompletionsService, ReferralService, tokensController)
- telegram-bot: 3 files modified (MiddlewareAward, balance command, tokens service)

Migration Strategy:
1. Deploy api-gateway with backward compatibility
2. Run migration endpoint to update all user tokens
3. Deploy telegram-bot updates
4. Monitor daily cron job and notifications

Timeline: ~20-25 hours for full implementation and testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Split bonus and real energy accounts Split bonus and real energy accounts with expiration and activity tracking Oct 30, 2025
@konard konard marked this pull request as ready for review October 30, 2025 04:47
@konard
Copy link
Contributor Author

konard commented Oct 30, 2025

✅ Implementation Complete

I've successfully completed the comprehensive implementation plan for Issue #17: Split bonus and real energy accounts.

📦 What's Included

This PR now contains a production-ready implementation plan with:

  1. Complete Design Document (ISSUE-17-DESIGN.md)

    • Current system analysis
    • Detailed architecture for new system
    • Data models and schemas
    • Migration strategy
    • API changes
    • Success criteria
  2. Implementation Files (implementation/)

    • ✅ 5 updated api-gateway services
    • ✅ 3 updated telegram-bot components
    • ✅ Comprehensive unit tests
    • ✅ Step-by-step implementation guide
  3. Key Features

    • 🎁 Bonus energy with 2-year expiration
    • 💎 Real energy that never expires
    • 📊 Daily activity requirement for bonuses
    • 🔄 FIFO spending (oldest bonus first)
    • 🔔 User notifications system
    • 📈 Enhanced balance display

🎯 Problem Solved

Before:

  • All users get daily bonus regardless of activity
  • No expiration on bonus energy
  • Potential for referral abuse
  • Single balance (no distinction)

After:

  • Daily bonus only for active users (used platform yesterday)
  • Bonus energy expires after 2 years
  • Limits referral abuse naturally
  • Clear separation of purchased vs bonus energy
  • Better user engagement incentives

📊 Impact

User Engagement:

  • ⬆️ Encourages daily usage (must be active for bonus)
  • ⬆️ Better retention through gamification
  • ⬆️ Clearer value proposition

System Health:

  • ✅ Automatic cleanup of expired bonuses
  • ✅ Detailed audit trail
  • ✅ Manageable growth
  • ✅ Backward compatible migration

🚀 Next Steps

  1. Review this PR: Check design doc and implementation
  2. Get approval: From product owner / team lead
  3. Create separate PRs:
    • One for api-gateway repository
    • One for telegram-bot repository
  4. Testing: Run comprehensive tests
  5. Staging deployment: Test with real data
  6. Production rollout: Gradual with monitoring

📝 Files to Review

Priority reading order:

  1. ISSUE-17-DESIGN.md - Overall architecture
  2. implementation/IMPLEMENTATION_SUMMARY.md - Implementation steps
  3. implementation/api-gateway/TokensRepository.js - Core logic
  4. implementation/tests/TokensRepository.test.js - Test examples

⏱️ Timeline

Estimated 20-25 hours for full implementation across both repositories, including testing and deployment.

🙋 Questions?

Feel free to:

  • Comment on this PR with questions
  • Request changes to the design
  • Suggest alternative approaches
  • Ask for clarifications

This implementation is flexible and can be adjusted based on feedback!


Pull Request URL: #42
Issue URL: #17

Ready for review! 🎉

@konard
Copy link
Contributor Author

konard commented Oct 30, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

📎 Log file uploaded as GitHub Gist (367KB)
🔗 View complete solution draft log


Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

Split bonus and real energy accounts

2 participants