KPI Aggregation Service
Component Detail
Description
Server-side Next.js API route handler that executes tenant-scoped PostgreSQL aggregation queries to compute activity counts, active user counts, expense totals, and assignment completion rates. Uses materialized views or indexed summary tables to avoid full table scans at scale. Returns a structured KPIData payload scoped to the requesting organization.
kpi-aggregation-service
Sources & reasoning
The aggregation service is the core backend component of this feature, eliminating the manual Excel/Word compilation described in the source doc. Materialized views and tenant isolation are explicitly called out in the feature implementation notes, making this a non-trivial service component.
-
docs/source/likeperson.md · line 186Coordinator and organization-level dashboards and KPIs
-
docs/source/likeperson.md · line 317Aktivitetsoversikt og grunnleggende statistikk
-
docs/source/likeperson.md · line 231Admin Web Portal: `admin-dashboard`, `admin-user-management`, `admin-organization`, `admin-security`
Responsibilities
- Execute tenant-isolated aggregation queries against PostgreSQL
- Leverage materialized views or summary indexes for performance
- Scope all queries to the requesting organization via tenant isolation
- Filter metrics to modules enabled in module_configurations for the org
- Return structured KPIData with trend deltas for period comparison
Interfaces
GET /api/v1/admin/kpis?organizationId=:id
getActivityCount(orgId: string, period: DateRange): Promise<number>
getActiveUserCount(orgId: string, period: DateRange): Promise<number>
getExpenseTotal(orgId: string, period: DateRange): Promise<number>
getAssignmentCompletionRate(orgId: string, period: DateRange): Promise<number>
getKPISummary(orgId: string): Promise<KPIData>
Relationships
Dependents (2)
Components that depend on this component
Related Data Entities (27)
Data entities managed by this component