A production-ready client-facing rate limit status and usage dashboard built with React and TypeScript. The component displays real-time API rate limit monitoring with visual indicators, endpoint usage breakdowns, and automated alerts.
-
src/components/RateLimitDashboard.tsx(473 lines)- Main React component with full functionality
- TypeScript with strong typing
- Includes all sub-components (ProgressBar, StatusBadge, Alert, EndpointUsageRow)
- Helper functions for calculations and formatting
- Mock data generator for demo mode
- State management with React hooks
-
src/pages/rate-limits.tsx(16 lines)- Standalone page for the dashboard
- Accessible at
/rate-limitsroute - Integrated with Docusaurus Layout
-
src/css/custom.css(630 lines added)- Complete styling for all components
- Responsive design (desktop, tablet, mobile)
- Accessible color contrasts
- Smooth animations and transitions
- Dark mode support via CSS variables
-
RATE_LIMIT_DASHBOARD.md(301 lines)- Complete component documentation
- API integration guide
- Configuration options
- Usage examples
- Development notes
-
docusaurus.config.ts(updated)- Added rate-limits route to navbar
- Overall Usage Card: Progress bar with percentage, used/limit/remaining stats
- Plan Details Card: Current tier, reset time, countdown timer
- Endpoint Usage Table: Per-endpoint request counts with status colors
- Status Indicators: OK (green), Warning (orange), Critical (red)
- Real-time Updates: Auto-refresh every 30 seconds (configurable)
- Manual refresh button
- Auto-refresh toggle checkbox
- Last updated timestamp
- Navigation links to documentation and support
- Critical (90%+ usage): "Your requests may be throttled soon"
- Warning (70-90% usage): "Consider optimizing your API usage"
- OK (<70% usage): "Your rate limit usage is healthy"
- Built-in tips for optimization
- Links to API documentation
- Links to support channels
- Best practices for rate limit management
GET /api/rate-limit-status
Authorization: Bearer {api_token}
Content-Type: application/json
Response:
{
"tier": "Pro",
"requestsLimit": 5000,
"requestsUsed": 1250,
"requestsRemaining": 3750,
"resetTime": "2024-07-30T15:30:00Z",
"resetTimestamp": 1722352200000,
"percentageUsed": 25,
"endpoints": [
{
"path": "/api/transactions",
"method": "GET",
"requestsUsed": 500,
"limit": 1000
},
// ... more endpoints
]
}- Open
src/components/RateLimitDashboard.tsx - Find the line:
const DEMO_MODE = true; - Change to:
const DEMO_MODE = false; - Rebuild:
npm run buildornpm start
The component will then fetch from your real API endpoint.
Change the auto-refresh interval (in milliseconds):
const POLLING_INTERVAL = 30000; // 30 secondsThe component expects the endpoint at /api/rate-limit-status. If your endpoint differs, modify the fetch URL in the fetchStatus function.
The component uses localStorage token:
'Authorization': `Bearer ${localStorage.getItem('api_token')}`Modify this to use your authentication mechanism.
status: Current rate limit dataloading: Fetch stateerror: Error message if fetch failsalerts: Array of alert messagesautoRefresh: Toggle for auto-pollinglastUpdated: Timestamp of last fetch
useCallback: Optimized fetch functionuseEffect: Initialization and polling setupuseState: All state management
ProgressBar: Reusable progress visualizationStatusBadge: Health status indicatorAlert: Alert message displayEndpointUsageRow: Table row with endpoint data
--ifm-color-primary: Main accent color--ifm-font-color-base: Text color--ifm-background-surface-color: Surface color--ifm-color-emphasis-*: Emphasis levels
- OK Status: #49cc90 (green)
- Warning Status: #fca130 (orange)
- Critical Status: #f93e3e (red)
- Desktop: Full layout, side-by-side cards
- Tablet (≤768px): Single column, condensed table
- Mobile (≤480px): Stack layout, minimal padding
- Memoization: useCallback for fetch function
- Debouncing: Not needed here but structure allows it
- Polling: Configurable interval, stops if component unmounts
- Error Boundaries: Graceful error handling
- Semantic HTML: Proper heading hierarchy, button elements
- ARIA Labels: On interactive elements and dynamic regions
- Color Contrast: WCAG AA compliant
- Keyboard Navigation: Full support
- Screen Reader Support: Semantic structure, clear labels
- Component loads with mock data
- Progress bar updates correctly
- Status badges show appropriate colors
- Alerts display based on usage threshold
- Manual refresh button works
- Auto-refresh toggle enables/disables polling
- Last updated timestamp updates
- Responsive design works on mobile
- No console errors
- All links work
The component comes with realistic demo data that cycles through various usage scenarios:
npm start # Start dev server
# Navigate to http://localhost:3001/proxypay/rate-limitsThe dashboard is already integrated! You can:
- View at
/rate-limitsin your docs site - Access from navbar: "Rate Limits" link
import RateLimitDashboard from '@site/src/components/RateLimitDashboard';
export default function MyPage() {
return (
<Layout>
<RateLimitDashboard />
</Layout>
);
}// In your application's dashboard component
import RateLimitDashboard from '@site/src/components/RateLimitDashboard';
export default function Dashboard() {
return (
<div className="dashboard-grid">
<RateLimitDashboard />
</div>
);
}app.get('/api/rate-limit-status', authenticateToken, (req, res) => {
const userId = req.user.id;
const rateLimit = getRateLimitForUser(userId);
res.json({
tier: rateLimit.tier,
requestsLimit: rateLimit.limit,
requestsUsed: rateLimit.used,
requestsRemaining: rateLimit.limit - rateLimit.used,
resetTime: new Date(rateLimit.resetAt).toISOString(),
resetTimestamp: rateLimit.resetAt.getTime(),
percentageUsed: Math.round((rateLimit.used / rateLimit.limit) * 100),
endpoints: getEndpointUsage(userId),
});
});@app.get("/api/rate-limit-status")
async def get_rate_limit_status(current_user: User = Depends(get_current_user)):
rate_limit = db.get_rate_limit(current_user.id)
return {
"tier": rate_limit.tier,
"requestsLimit": rate_limit.limit,
"requestsUsed": rate_limit.used,
"requestsRemaining": rate_limit.limit - rate_limit.used,
"resetTime": rate_limit.reset_at.isoformat(),
"resetTimestamp": int(rate_limit.reset_at.timestamp() * 1000),
"percentageUsed": round((rate_limit.used / rate_limit.limit) * 100),
"endpoints": get_endpoint_usage(current_user.id),
}- Check browser console for errors
- Verify DEMO_MODE is set correctly
- Ensure all files are in correct directories
- Verify authentication token is in localStorage
- Check CORS headers if API on different domain
- Verify endpoint URL matches backend
- Clear cache:
rm -rf .docusaurus node_modules/.cache - Rebuild CSS:
npm run build - Check CSS is linked in Layout component
- Check polling interval value
- Verify useEffect cleanup is called
- Check browser DevTools network tab
- Historical Trends: Graph showing usage over time
- Export Data: Download usage reports (CSV/PDF)
- Predictions: Estimate when limit will be exhausted
- Webhooks: Subscribe to rate limit events
- Custom Thresholds: User-configurable alert levels
- API Key Usage: Break down by API key
- Usage Forecasting: Based on historical patterns
- Billing Integration: Show cost impact of usage
- Full documentation: See
RATE_LIMIT_DASHBOARD.md - Component code:
src/components/RateLimitDashboard.tsx - Styles:
src/css/custom.css(Rate Limit section) - Page:
src/pages/rate-limits.tsx - Config:
docusaurus.config.ts
src/
├── components/
│ ├── RateLimitDashboard.tsx [NEW - 473 lines]
│ └── ApiReference.tsx [unchanged]
├── pages/
│ ├── rate-limits.tsx [NEW - 16 lines]
│ ├── index.tsx [unchanged]
│ └── api.tsx [unchanged]
└── css/
└── custom.css [MODIFIED - 630 lines added]
Root files:
├── docusaurus.config.ts [MODIFIED - navbar updated]
├── RATE_LIMIT_DASHBOARD.md [NEW - 301 lines]
└── RATE_LIMIT_DASHBOARD_IMPL.md [This file]
-
View Dashboard
npm start # Navigate to http://localhost:3001/proxypay/rate-limits -
Test Production Integration
- Edit
src/components/RateLimitDashboard.tsx - Change
const DEMO_MODE = false; - Ensure backend provides
/api/rate-limit-status
- Edit
-
Customize Styling
- Edit
src/css/custom.css - Search for "Rate Limit Dashboard" section
- Modify colors, spacing, fonts as needed
- Edit
The Rate Limit Dashboard is a complete, production-ready component that:
✅ Displays real-time rate limit status
✅ Shows endpoint-level usage breakdown
✅ Provides smart alerts and recommendations
✅ Auto-refreshes with user control
✅ Fully responsive on all devices
✅ Accessible to all users
✅ Works in demo mode out-of-the-box
✅ Integrates with your backend API
✅ Well-documented and maintainable
✅ No external UI library dependencies
Ready for production deployment!