Analytics Service
The Analytics service provides business intelligence, dashboards, and reporting for each tenant. It aggregates data from all other services to provide actionable insights.
Architecture
Webshop ──────┐
Warehouse ────┤ (RabbitMQ events)
CRM ──────────┤──▶ Analytics Backend (Laravel 12)
Webhook ──────┘ │
├──▶ PostgreSQL (analytics schema)
├──▶ Redis (cached reports)
└──▶ Tenant Frontend (dashboards)
Key Features
Dashboards
- Real-time sales overview (today, week, month, year)
- Revenue charts and trends
- Top-selling products
- Customer acquisition metrics
- Inventory health indicators
Reports
- Sales reports by period, category, product
- Customer reports (new, returning, lifetime value)
- Inventory reports (stock levels, turnover rates)
- Custom report builder with filters
- Export to CSV/PDF
Event Processing
- Consumes events from all other services via RabbitMQ
- Aggregates data into materialized views for fast queries
- Time-series data storage for trend analysis
API Endpoints
Base URL: https://{tenant}.vecton.hu/api/analytics (production) | http://localhost:8014/api (dev)
Dashboards
| Method | Endpoint | Description |
|---|---|---|
| GET | /dashboard | Main dashboard data |
| GET | /dashboard/sales | Sales overview |
| GET | /dashboard/customers | Customer metrics |
| GET | /dashboard/inventory | Inventory health |
Reports
| Method | Endpoint | Description |
|---|---|---|
| GET | /reports/sales | Sales report (filterable by date range) |
| GET | /reports/products | Product performance report |
| GET | /reports/customers | Customer analytics report |
| GET | /reports/inventory | Inventory report |
| GET | /reports/{id}/export | Export report as CSV/PDF |
Query Parameters
Common filters available on most endpoints:
| Parameter | Type | Description |
|---|---|---|
from | date | Start date (ISO 8601) |
to | date | End date (ISO 8601) |
granularity | string | hourly, daily, weekly, monthly |
category_id | integer | Filter by product category |
format | string | Response format: json, csv |
Events Consumed
| Event | Source | Usage |
|---|---|---|
order.created | Webshop | Revenue tracking, order metrics |
order.status_changed | Webshop | Fulfillment metrics |
product.stock_changed | Webshop | Inventory tracking |
stock.received | Warehouse | Supply metrics |
customer.created | CRM | Acquisition metrics |
campaign.sent | CRM | Marketing ROI |
email.opened | CRM | Engagement metrics |
Database Schema
| Table | Description |
|---|---|
daily_sales | Aggregated daily sales metrics |
product_metrics | Product performance data |
customer_metrics | Customer behavior aggregates |
inventory_snapshots | Daily inventory levels |
event_log | Raw event history |
Configuration
| Variable | Description | Default |
|---|---|---|
APP_URL | Service base URL | http://localhost:8014 |
DB_SCHEMA | Database schema | analytics |
CACHE_TTL | Report cache duration (minutes) | 15 |
Development
cd tenant/tenant-backend-analytics
composer install
php artisan migrate --seed
php artisan serve --port=8014