# Materialized Views for Analytics ## Module Platform ## Status VERIFIED ## Description Materialized views with indexes, VEX validity filters, and deterministic arrays are used for analytics with a dedicated maintenance service for refresh. ## Implementation Details - **PlatformAnalyticsMaintenanceService**: `src/Platform/StellaOps.Platform.WebService/Services/PlatformAnalyticsMaintenanceService.cs` -- BackgroundService that periodically refreshes 4 materialized views (`mv_supplier_concentration`, `mv_license_distribution`, `mv_vuln_exposure`, `mv_attestation_coverage`) using `REFRESH MATERIALIZED VIEW CONCURRENTLY`; supports daily rollup backfill, configurable interval, and run-on-startup mode via `PlatformAnalyticsMaintenanceOptions` - **PlatformAnalyticsQueryExecutor**: `src/Platform/StellaOps.Platform.WebService/Services/PlatformAnalyticsQueryExecutor.cs` -- executes analytical queries against materialized views - **PlatformAnalyticsService**: `src/Platform/StellaOps.Platform.WebService/Services/PlatformAnalyticsService.cs` -- service layer for analytics queries (suppliers, licenses, vulnerabilities, backlog, attestation coverage, vulnerability/component trends) - **AnalyticsEndpoints**: `src/Platform/StellaOps.Platform.WebService/Endpoints/AnalyticsEndpoints.cs` -- REST API at `/api/analytics` with 7 endpoints: suppliers, licenses, vulnerabilities, backlog, attestation-coverage, trends/vulnerabilities, trends/components; all require `AnalyticsRead` authorization - **Source**: Feature matrix scan ## E2E Test Plan - [ ] Verify materialized views refresh concurrently without blocking reads - [ ] Test daily rollup backfill covers configured BackfillDays range - [ ] Verify analytics endpoints return correct data from materialized views - [ ] Test analytics service returns 503 when analytics storage is not configured - [ ] Verify trend endpoints return daily data points for specified time windows ## Verification - Verified on 2026-02-11 via `run-001`. - Tier 0 source checks passed for maintenance, query executor, analytics service, and analytics endpoints. - Tier 1 build + targeted test gates passed across webservice and analytics projects. - Tier 2 behavioral checks passed with fresh user-surface/API and integration evidence: - backfill + `REFRESH MATERIALIZED VIEW CONCURRENTLY` maintenance path (`PlatformAnalyticsMaintenanceServiceTests`) - unconfigured endpoint path returns `503` (`AnalyticsEndpointsTests`, 7 routes) - configured endpoint success payloads and trend points (`AnalyticsEndpointsSuccessTests`) - analytics service cache/normalization behavior for suppliers, vulnerabilities, backlog, attestation coverage, and trend windows (`PlatformAnalyticsServiceTests`) - materialized-view + stored-procedure integration behavior in Docker PostgreSQL (`AnalyticsSchemaIntegrationTests`, 22 tests) - Evidence: - `docs/qa/feature-checks/runs/platform/materialized-views-for-analytics/run-001/tier0-source-check.json` - `docs/qa/feature-checks/runs/platform/materialized-views-for-analytics/run-001/tier1-build-check.json` - `docs/qa/feature-checks/runs/platform/materialized-views-for-analytics/run-001/tier2-integration-check.json`