How Billing Cycles Work
30-Day Rolling Window
Unlike traditional calendar-month billing, Reportr uses a personal 30-day cycle for each user:- Cycle Start: Begins when you subscribe or when previous cycle ends
- Cycle Duration: Exactly 30 days (720 hours)
- Cycle End: Automatically resets after 30 days
- Tracking: Reports counted only within current cycle
Your billing cycle is independent of calendar months. If you subscribe on January 15th, your cycle runs January 15 - February 14, February 14 - March 16, etc.
Example Timeline
Cycle Initialization
When you create a Reportr account, the system automatically initializes your billing cycle:billingCycleStartset to current timestampbillingCycleEndcalculated as start + 30 days- Values stored in database for tracking
- Report counter starts at zero
Automatic Cycle Resets
Reset Detection
Every time you generate a report or check usage, the system automatically checks if your cycle needs resetting:Reset Process
Report Counting
Cycle-Aware Counting
When checking if you can generate a report, the system counts only reports created within your current cycle:- Fetch current cycle start and end dates
- Count reports where
createdAtis within cycle boundaries - Reports from previous cycles are not counted
- Future-dated reports (if any) are excluded
Example Counting
Viewing Cycle Information
Dashboard Display
Your dashboard shows real-time cycle information:- Cycle start date: When current cycle began
- Cycle end date: When it will reset
- Days remaining: Countdown to reset
- Reports used: Current cycle consumption
- Reports remaining: Available in current cycle
API Response
cycleStart: Beginning of current 30-day windowcycleEnd: When cycle expires and resetsdaysRemaining: Days until automatic resetcycleWasReset: Whether cycle was just reset (true on first check after expiration)reportsUsed: Reports generated in current cycleutilizationPercentage: Usage as percentage of limit
Integration with Plan Limits
Enforcement Flow
The billing cycle system integrates with plan limits:- Fair tracking: Consistent 30-day periods
- Automatic resets: No manual intervention needed
- Predictable: Always know when limits renew
- Accurate: Counts only reports in current cycle
Database Schema
Billing cycle tracking uses these fields in theUser model:
billingCycleStart: Timestamp when current cycle beganbillingCycleEnd: Timestamp when current cycle expiresplan: Current plan tier (determines report limit)
Subscription Changes
When you upgrade or downgrade plans:Immediate Upgrade
Immediate Upgrade
- New plan limits apply instantly
- Billing cycle does not reset
- Report count continues from current cycle
- Example: If you’ve used 18/25 reports and upgrade to Professional (75 limit), you immediately have 57 reports remaining in current cycle
Scheduled Downgrade
Scheduled Downgrade
- Downgrade takes effect at cycle end
- Current cycle continues with old limits
- New limits apply when cycle resets
- Example: Professional user (75 limit) downgrades to Starter (25 limit) mid-cycle. They keep 75-report limit until cycle resets, then drop to 25.
Cancellation
Cancellation
- Access continues until
subscriptionEndDate - Billing cycle continues until end of paid period
- No cycle reset on cancellation
- Plan reverts to FREE when subscription ends
Technical Implementation
Billing cycle management is centralized insrc/lib/billing-cycle.ts:
initializeBillingCycle()- Set up new user cyclescheckAndResetBillingCycle()- Detect and perform resetsgetBillingCycleInfo()- Retrieve current cycle datagetReportsInCurrentCycle()- Count usage in current windowgetDaysUntilReset()- Calculate days remaininggetUsageStats()- Comprehensive usage statistics
src/lib/billing-cycle.ts- Core cycle logicsrc/lib/plan-limits.ts- Integration with limitsprisma/schema.prisma- Database schema
Next Steps
Plan Limits
See detailed limits for each plan tier
Upgrading
Learn how to change your plan