Skip to content

fix: source sector compliance baseline from DB instead of hardcoded scores#81

Merged
munisp merged 2 commits into
mainfrom
devin/1784663272-sector-baseline-dbdriven
Jul 21, 2026
Merged

fix: source sector compliance baseline from DB instead of hardcoded scores#81
munisp merged 2 commits into
mainfrom
devin/1784663272-sector-baseline-dbdriven

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Full-stack audit of NDSEP main (frontend↔backend wiring, service/middleware integration, DB schema/indexes, AI/ML, and mock/placeholder/hardcoding scan). The platform is in good shape overall; this PR fixes the one clear "hardcoded value that should be DB-driven" the scan surfaced — a static BASELINE_SCORES map in SectorComplianceDetail that even carried an explicit // TODO: migrate to DB-driven config note.

The page already fetched real data everywhere else; only the "baseline" comparison figure was baked into the bundle, so it never changed per audit cycle without a redeploy. It now reads the latest sector_benchmarks snapshot via the existing sectorBenchmarks.list router.

-const BASELINE_SCORES = { fintech: 87, healthcare: 92, energy: 78, insurance: 85, telecom: 81 };
...
-{BASELINE_SCORES[sector] && <div>Baseline: {BASELINE_SCORES[sector]}%</div>}
+const benchmarkQuery = trpc.sectorBenchmarks.list.useQuery({ sector }, { enabled: !!sector });
+const baselineScore = Math.round(Number(benchmarkQuery.data?.[0]?.avg_compliance_score)) // null-safe
+{baselineScore != null && <div>Sector baseline: {baselineScore}%</div>}

Renders nothing when no benchmark row exists (no hardcoded fallback).

Audit findings (no code change needed, documented for reference)

  • Frontend→backend wiring: every trpc.<ns>.<proc> call in the client resolves to a registered router — 0 missing backends.
  • Middleware: helmet, CORS, Redis-backed rate limiting, CSRF, compression all wired in server/_core/index.ts; emitMutationEvent present across routers.
  • DB: 117 tables, 268 CREATE INDEX statements across migrations (incl. production-indexes.sql, 0021_performance_indexes.sql).
  • AI/ML: real trained XGBClassifier models (.joblib) + SHAP + Ray ML engine + FastAPI services; CPU inference verified (~1.3ms/batch). tRPC routers call the Python workers with labeled deterministic fallbacks when a worker is offline.
  • Remaining "mock" hits are labeled offline fallbacks (e.g. KnowledgeGraph demo when FalkorDB is down, StreamingEvents simulator when the WebSocket isn't connected) — graceful degradation, not deceptive data.

Verification

  • tsc --noEmit — 0 errors
  • npm run build — succeeds

Link to Devin session: https://app.devin.ai/sessions/7b19b09de740454faef61082df9c86da
Requested by: @munisp

…cores

Replace the hardcoded BASELINE_SCORES map (and its 'migrate to DB' TODO) in
SectorComplianceDetail with the DB-driven sectorBenchmarks.list query, so the
sector baseline reflects the latest sector_benchmarks snapshot rather than
static values baked into the bundle.

Co-Authored-By: Patrick Munis <pmunis@gmail.com>
@munisp munisp self-assigned this Jul 21, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author
Original prompt from Patrick

NDSEP continued session id 638573251e5f4e859a5f3b205afec3cd

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Update the phase21 test that previously asserted the hardcoded baseline
scores (fintech: 87, healthcare: 92) to instead assert the page sources the
baseline from trpc.sectorBenchmarks.list, and guard against reintroducing the
hardcoded BASELINE_SCORES map.

Co-Authored-By: Patrick Munis <pmunis@gmail.com>
@munisp
munisp merged commit 46b8dcc into main Jul 21, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant