Compliance & Risk Constraints¶
This spec documents the feature constraints for the compliance scorecards, risk scoring, and findings feeds so every new dashboard or automation can depend on a single source of truth (backend/src/services/compliance.service.ts, backend/src/services/risk.service.ts, and backend/src/routes/findings.ts).
1. Data Scope & Demo Handling¶
- Tenant scoping: All compliance/risk APIs filter projects by the authenticated user’s role (customer, auditor, manager, admin) while guarding
isDemodata viashowDemoflags pulled fromDEMO_MANAGER_IDandshouldShowDemoData. Demo projects may only surface to users without managers or when explicitly allowed; otherwise every query enforcesisDemo: false. - Project gating: Queries list only projects shared with the user (
projectShares), assigned customers/auditors, or demo buckets. Dashboard statistics and risk/finding filters reuse the exact same where clauses to keep totals aligned.
2. Compliance Service Guarantees¶
- Compliance score:
ComplianceService.getComplianceStatsaverages each project’sprojectControls.progressto produce anoverallScoreand per-projectprogress. This score powers the customer dashboard and ensures 0-100 values even when controls are missing. - Detailed overview:
getDetailedComplianceOverviewreturns the same control set, calculatescompletionPercentage(fully verified controls) plusaverageProgress(aggregated progress), and surfaces the top-five missing controls for help widgets. - Unified summary:
getUnifiedComplianceSummarystitchesgetDetailedComplianceOverview,RiskService.getCustomerRiskOverview, andAgentManagementService.getAgentStatsso AI tools and dashboards can show compliance + risk + agent counts in one call. - Graph projection:
getProjectionproxies tographServiceUrl/api/projection, passing user metadata and evidence counts. Failures log warnings but return an empty array so dashboards remain resilient.
3. Risk & Findings Behavior¶
- Risk scoring:
RiskService.calculateRiskScoreweights severities (Critical=100, High=50, Medium=25, Low=10, Info=5), caps results at 100, and definesHigh(>=80),Medium(>=40),Lowotherwise. Only open/in-progress findings feed this score. - Findings API:
GET /api/findingsapplies identical demo-aware filtering and allows severity/status/category/integration pagination.GET /api/findings/statsmirrors the same filter to keep dashboard counts deterministic. - Finding detail:
GET /api/findings/:idreturns integration data, agent info, assigned/resolved metadata, and comment threads, keeping results in sync with Prisma relations. - Backend integration: Findings feed into compliance dashboards, risk calculations, and the AI assistant’s summary. Any new feature that mutates findings must respect the demo gating and severity weighting described in this spec.
4. Operational Expectations¶
- Health & resilience: Compliance endpoints catch Graph Service (
axios) failures, returning503when the external service is down but otherwise letting Prisma errors bubble so Observability can alert. - Telemetry links: The compliance summary includes
criticalGapsfrom missing controls andtotalFindingsfrom the risk service; ensure new dashboards surface both values for parity. - Agent context: The unified summary expects agent stats from
AgentManagementService. When adding new agent metrics or filters, extend that service before touching the dashboard endpoint.
References¶
backend/src/services/compliance.service.tsbackend/src/services/risk.service.tsbackend/src/services/agent-management.service.tsbackend/src/routes/findings.tsbackend/src/routes/compliance.ts