Skip to main content

Dashboard Module

The admin analytics engine – aggregated business metrics, order fulfillment, inventory alerts, and support ticket counts.

Aggregations Admin $facet


📖 Table of Contents


Base Route : /api/v1/dashboards

All endpoints are admin‑only and require a valid access token with the ADMIN role. Rate limiting applies (100 requests per 15 minutes per IP).


Endpoints Overview

MethodEndpointAccessDescription
GET/metricsAdminFetch aggregated business metrics: revenue, order fulfillment, top products, inventory alerts, user growth, pending support tickets

Optional query parameters startDate and endDate (ISO 8601) define the reporting period. Defaults to a 30‑day rolling window.


Endpoint Details

GET /metrics

Retrieve a complete dashboard snapshot for the authenticated admin. All metrics are computed via MongoDB aggregation pipelines directly at the database layer for optimal performance.

Headers: Authorization: Bearer <admin_access_token>

Query parameters (optional):

ParamTypeDefaultDescription
startDateISO 8601 string30 days before endDateStart of reporting period (inclusive)
endDateISO 8601 stringcurrent dateEnd of reporting period (inclusive)

Example request:

GET /api/v1/dashboards/metrics?startDate=2026-05-01&endDate=2026-05-31

Response (200 OK):

{
"success": true,
"statusCode": 200,
"message": "Dashboard metrics retrieved successfully.",
"data": {
"dateRange": {
"start": "2026-05-01T00:00:00.000Z",
"end": "2026-05-31T23:59:59.999Z"
},
"financials": {
"totalRevenue": 1250000,
"totalOrders": 450,
"averageOrderValue": 2778
},
"orderFulfillment": {
"PENDING": 12,
"PROCESSING": 25,
"SHIPPED": 80,
"DELIVERED": 300,
"CANCELLED": 8,
"RETURN_REQUESTED": 5,
"RETURNED": 20
},
"topSellingProducts": [
{
"productId": "64a7b...",
"sku": "BAN-001",
"name": "Bridal Glass Bangle Set",
"totalSold": 150,
"revenueGenerated": 67500
}
],
"inventoryAlerts": [
{
"productId": "64a7c...",
"sku": "APP-045",
"name": "Cotton Saree",
"currentStock": 3
}
],
"userMetrics": {
"totalRegisteredUsers": 1250,
"newSignupsInPeriod": 45
},
"pendingSupportTickets": 8
},
"timestamp": "2026-05-22T10:30:00.000Z"
}

Validation Rules (Zod)

The DateRangeQuerySchema validates query parameters:

FieldTypeRules
startDateISO 8601 string (coerced to Date)optional, must be ≤ endDate if both provided
endDateISO 8601 string (coerced to Date)optional, must be ≥ startDate if both provided

Refinement: If both dates are present, startDate must be before or equal to endDate. Returns 400 Bad Request otherwise.

The schema uses .strict() – extra query parameters are rejected.


Response Structure

FieldTypeDescription
dateRange.startstring (ISO)Start of the reporting period (UTC midnight)
dateRange.endstring (ISO)End of the reporting period (UTC 23:59:59)
financials.totalRevenuenumberSum of totalAmount for delivered orders in period
financials.totalOrdersnumberCount of delivered orders in period
financials.averageOrderValuenumbertotalRevenue / totalOrders (rounded)
orderFulfillmentobjectCounts per order status (PENDING, PROCESSING, SHIPPED, DELIVERED, CANCELLED, RETURN_REQUESTED, RETURNED)
topSellingProductsarrayTop 5 products by totalSold (from delivered orders)
inventoryAlertsarrayActive products with currentStock < 10, up to 10 results
userMetrics.totalRegisteredUsersnumberAll users with role USER
userMetrics.newSignupsInPeriodnumberNew USER registrations within the date range
pendingSupportTicketsnumberTickets with status OPEN or WAITING_ON_CUSTOMER

Error Responses

StatusCodeExample messageWhen
400BAD_REQUEST"Logical Error: startDate must occur before or at the exact same time as endDate."Invalid date range
401UNAUTHORIZED"Authentication required"Missing or invalid token
403FORBIDDEN"You do not have permission to perform this action"Non‑admin user attempts to access
500INTERNAL_SERVER_ERROR"Failed to compute dashboard aggregations. Please contact engineering."Aggregation pipeline failure

Runbook

For manual testing with Thunder Client / Postman, see ../../testing/dashboard-runbook.md. The runbook covers:

  • Fetching default 30‑day metrics
  • Custom date ranges
  • RBAC firewall (standard user gets 403)
  • Temporal firewall (startDate after endDate)
  • NoSQL injection attempts via date parameters

Real‑time insights, aggregation‑optimised – the Reshma‑Core dashboard engine.