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-EmailX-User-Role
- Only users with
ADMINrole 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)โ
| Param | Description |
|---|---|
from | Start date (YYYY-MM-DD) |
to | End 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โ
| Status | Meaning |
|---|---|
| 401 | Unauthorized |
| 403 | Forbidden |
| 500 | Analytics 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.