Skip to content

feat(backend): Build escrow analytics aggregation service#463

Merged
KuchiMercy merged 1 commit into
StayLitCodes:mainfrom
patopatrish:feat/escrow-analytics-aggregation-service
Jun 30, 2026
Merged

feat(backend): Build escrow analytics aggregation service#463
KuchiMercy merged 1 commit into
StayLitCodes:mainfrom
patopatrish:feat/escrow-analytics-aggregation-service

Conversation

@patopatrish

Copy link
Copy Markdown
Contributor

Closes #424

Summary

  • Rewrites AnalyticsService with comprehensive metrics covering volume, activity, performance, users, and disputes
  • Adds four production-ready endpoints under GET /admin/analytics/{summary,volume,users,disputes} with Cache-Control headers
  • Introduces chart-friendly ChartData ({ labels, values }) for all time-series responses consumed by the frontend (F-20)

Changes

analytics.service.ts

Feature Detail
VolumeMetrics totalVolume, averageAmount, medianAmount over completed escrows
ActivityMetrics Per-status counts: created / active / completed / disputed / cancelled / expired / total
PerformanceMetrics Avg days to funding, completion, and dispute resolution via julianday()
UserMetrics total, active30d, new7d, new30d, new90d
DisputeMetrics disputeRate, resolutionRate, winRate, avgResolutionTimeDays, outcomeDistribution
VolumeTimeSeries Daily 30d, daily 90d, monthly 12m — all as ChartData
UserTimeSeries Weekly active users over 12 weeks
Cache 5 min TTL for summaries; 15 min TTL for time-series
Date range filtering from/to params on volume time-series

analytics.controller.ts

Endpoint Cache-Control Description
GET /admin/analytics/summary max-age=300 Combined summary of all metric groups
GET /admin/analytics/volume max-age=900 Time-series with chart data (daily/weekly/monthly)
GET /admin/analytics/users max-age=300 User metrics + weekly active chart
GET /admin/analytics/disputes max-age=300 Dispute metrics
GET /admin/analytics/top-users max-age=300 Top users by volume (unchanged)

Test plan

  • GET /admin/analytics/summary returns all five metric groups
  • GET /admin/analytics/volume?period=daily returns series + charts.daily30d / daily90d / monthly12m with labels and values arrays
  • GET /admin/analytics/users returns metrics and charts.weeklyActive12w
  • GET /admin/analytics/disputes returns disputeRate, resolutionRate, winRate, avgResolutionTimeDays
  • Second request within TTL is served from in-memory cache (no DB hit)
  • Cache-Control header is present on all responses
  • Date range filtering (?from=2026-01-01&to=2026-06-30) narrows volume results

🤖 Generated with Claude Code

…es#424)

Implements comprehensive admin analytics with caching across four endpoints:
- GET /admin/analytics/summary — combined volume/activity/performance/user/dispute metrics (5 min cache)
- GET /admin/analytics/volume — time-series with chart-friendly labels+values (15 min cache)
- GET /admin/analytics/users — total/active(30d)/new(7/30/90d) metrics + weekly active 12w chart (5 min cache)
- GET /admin/analytics/disputes — dispute rate, resolution rate, win rate, avg resolution time (5 min cache)

Key additions:
- VolumeMetrics: total, average, median escrow amounts
- ActivityMetrics: counts per EscrowStatus (created/active/completed/disputed/cancelled/expired)
- PerformanceMetrics: avg days to funding, completion, and dispute resolution
- UserMetrics: total, active30d, new7d/30d/90d users
- DisputeMetrics: dispute rate, resolution rate, win rate, outcome distribution
- ChartData: { labels, values } format for all time-series responses
- In-memory cache: 5 min TTL for summaries, 15 min TTL for time-series
- Cache-Control response headers on all endpoints
- Date range filtering support on volume endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@patopatrish Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@KuchiMercy KuchiMercy merged commit b10288f into StayLitCodes:main Jun 30, 2026
1 check passed
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(backend): Build escrow analytics aggregation service

2 participants