Skip to main content

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

MethodEndpointDescription
GET/dashboardMain dashboard data
GET/dashboard/salesSales overview
GET/dashboard/customersCustomer metrics
GET/dashboard/inventoryInventory health

Reports

MethodEndpointDescription
GET/reports/salesSales report (filterable by date range)
GET/reports/productsProduct performance report
GET/reports/customersCustomer analytics report
GET/reports/inventoryInventory report
GET/reports/{id}/exportExport report as CSV/PDF

Query Parameters

Common filters available on most endpoints:

ParameterTypeDescription
fromdateStart date (ISO 8601)
todateEnd date (ISO 8601)
granularitystringhourly, daily, weekly, monthly
category_idintegerFilter by product category
formatstringResponse format: json, csv

Events Consumed

EventSourceUsage
order.createdWebshopRevenue tracking, order metrics
order.status_changedWebshopFulfillment metrics
product.stock_changedWebshopInventory tracking
stock.receivedWarehouseSupply metrics
customer.createdCRMAcquisition metrics
campaign.sentCRMMarketing ROI
email.openedCRMEngagement metrics

Database Schema

TableDescription
daily_salesAggregated daily sales metrics
product_metricsProduct performance data
customer_metricsCustomer behavior aggregates
inventory_snapshotsDaily inventory levels
event_logRaw event history

Configuration

VariableDescriptionDefault
APP_URLService base URLhttp://localhost:8014
DB_SCHEMADatabase schemaanalytics
CACHE_TTLReport cache duration (minutes)15

Development

cd tenant/tenant-backend-analytics
composer install
php artisan migrate --seed
php artisan serve --port=8014