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

Description

Backend Next.js API route handler that receives parameterized report queries from the Report Builder UI, applies strict tenant-scoped WHERE clauses to all generated PostgreSQL queries, and returns paginated results. Exposes report template CRUD against the reports table so users can persist and reload reusable filter configurations. Never exposes raw SQL or internal table names to clients; all permitted dimensions and metrics are resolved through the Report Schema Registry.

Feature: Custom Reports

custom-report-service

Sources & reasoning

Core business logic layer translating user-selected dimensions into safe, tenant-scoped PostgreSQL queries. Cursor-based pagination is required for NHF-scale data. Strict tenant scoping prevents cross-org data leakage. Template persistence allows power users to save organization-specific report shapes without developer involvement.

No source references — this artifact was included based on reasoning alone (see above).

Responsibilities

  • Execute tenant-scoped parameterized PostgreSQL queries for ad-hoc report requests
  • Enforce tenant isolation on every query via organization_id WHERE clause
  • Persist and retrieve saved report templates from the reports table
  • Return cursor-paginated results suitable for NHF-scale datasets
  • Reject dimension or filter values not present in the Report Schema Registry

Interfaces

runReport(params: ReportParams, orgId: string): Promise<PaginatedReportResult>
saveTemplate(template: ReportTemplate): Promise<ReportTemplate>
listTemplates(orgId: string): Promise<ReportTemplate[]>
deleteTemplate(templateId: string, orgId: string): Promise<void>

Relationships

Dependencies (2)

Components this component depends on

Dependents (2)

Components that depend on this component

Related Data Entities (2)

Data entities managed by this component