Skip to content

feat: Real-time bot statistics on homepage with Redis caching #252

@BillChirico

Description

@BillChirico

Summary

Pull real bot statistics from Discord and display them on the public homepage. Stats should be cached in Redis to avoid hammering the Discord API on every page load.

Metrics to Display

  • Server count — number of guilds the bot is in
  • Total members — aggregate member count across all guilds
  • Commands served — total slash command invocations (tracked in DB)
  • Active conversations — current AI conversation count
  • Uptime — bot process uptime
  • Messages processed — total messages handled

Implementation

Backend (/api/public/stats)

  • New public endpoint (no auth required, rate-limited)
  • Collect stats from Discord client (client.guilds.cache.size, member counts, etc.)
  • Query DB for command usage, message counts
  • Cache results in Redis with configurable TTL (default: 5 minutes)
  • Return JSON payload with all metrics + cachedAt timestamp

Frontend (Homepage)

  • Animated counter components for each stat
  • Auto-refresh on an interval (e.g., every 60s)
  • Graceful fallback if API is unavailable (show last known or placeholder)
  • Mobile-responsive grid layout

Redis Caching

  • Key: bot:stats:public
  • TTL: 300s (5 min) — configurable via config.stats.cacheTtlSeconds
  • Invalidate on significant events (guild join/leave) or let TTL expire naturally

Acceptance Criteria

  • /api/public/stats returns server count, member count, uptime, and at least 2 other metrics
  • Response is served from Redis cache on subsequent requests within TTL
  • Homepage renders stats with animated counters
  • Stats degrade gracefully when Redis or Discord data is unavailable
  • Endpoint is rate-limited (30 req/min, matching existing public endpoints)
  • Tests cover the API endpoint and caching logic

Closes #(self)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions