Skip to main content

Analytics Service โ€“ API Reference ๐Ÿ“Š

This document describes the read-only analytics APIs exposed by the Analytics Service in ShopVerse.

These APIs provide business insights and metrics derived from event-driven data pipelines and are accessible only to administrators.


๐ŸŒ Base URLโ€‹


/api/analytics


๐Ÿ” Authentication & Authorizationโ€‹

  • JWT is validated at the API Gateway
  • Gateway injects:
    • X-User-Email
    • X-User-Role
  • Only users with ADMIN role can access analytics APIs
  • Analytics data is never exposed to customers

๐Ÿ“ˆ Dashboard Metricsโ€‹

Fetch high-level business metrics for dashboards.

โžค Endpointโ€‹


GET /api/analytics/dashboard

โžค Role Requiredโ€‹


ADMIN

โžค Success Response (200 OK)โ€‹

{
"totalUsers": 1250,
"totalOrders": 340,
"totalRevenue": 845000,
"ordersToday": 12
}

๐Ÿ’ฐ Revenue Analyticsโ€‹

Fetch revenue-related statistics.

โžค Endpointโ€‹

GET /api/analytics/revenue

โžค Role Requiredโ€‹

ADMIN

โžค Query Parameters (Optional)โ€‹

ParamDescription
fromStart date (YYYY-MM-DD)
toEnd date (YYYY-MM-DD)

โžค Success Response (200 OK)โ€‹

{
"dailyRevenue": [
{
"date": "2026-01-20",
"amount": 125000
},
{
"date": "2026-01-21",
"amount": 98000
}
]
}

๐Ÿ“ฆ Order Analyticsโ€‹

Fetch order statistics.

โžค Endpointโ€‹

GET /api/analytics/orders

โžค Role Requiredโ€‹

ADMIN

โžค Success Response (200 OK)โ€‹

{
"totalOrders": 340,
"ordersByStatus": {
"CREATED": 25,
"CONFIRMED": 300,
"CANCELLED": 15
}
}

๐Ÿ“ก Data Sourceโ€‹

Analytics APIs query data processed through:

Kafka โ†’ Apache Flink โ†’ ClickHouse
  • Kafka stores raw events
  • Flink aggregates & transforms
  • ClickHouse serves fast analytical queries

๐Ÿ”„ Request Flowโ€‹


โš ๏ธ Common Errorsโ€‹

StatusMeaning
401Unauthorized
403Forbidden
500Analytics query failure

๐Ÿ›ก๏ธ Security Notesโ€‹

  • Analytics endpoints are read-only
  • No sensitive user data exposed
  • Access strictly limited to admins
  • Queries are optimized for performance

๐Ÿ“Œ Summaryโ€‹

The Analytics API provides:

  • Real-time business insights
  • Secure, admin-only access
  • High-performance analytical queries
  • Event-driven data accuracy

It enables data-driven decision making in ShopVerse.