Service Layer high complexity backend
1
Dependencies
2
Dependents
27
Entities
0
Integrations

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.

Feature: Dashboard KPIs

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 186
    Coordinator and organization-level dashboards and KPIs
  • docs/source/likeperson.md · line 317
    Aktivitetsoversikt og grunnleggende statistikk
  • docs/source/likeperson.md · line 231
    Admin 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

Dependencies (1)

Components this component depends on

Dependents (2)

Components that depend on this component