Insights — Code Map
Shared contract and copy
| Path | Responsibility |
|---|---|
libs/shared/src/lib/types/insights.types.ts | All InsightId values, five categories, severities, and nullable drilldownHref |
libs/shared/src/lib/i18n/dictionaries/{en,he,ru}.json | insights.items.<id>, all-clear, counts, Ask Spotter copy |
API
| Path | Responsibility |
|---|---|
apps/api/src/insights/insights.module.ts | Insights module wiring |
apps/api/src/insights/insights.controller.ts | Active-membership + staff gate; passes HTTP caller role |
apps/api/src/insights/insights.service.ts | 20-rule orchestration on ONE pooled connection (db.transaction, read only) with the caller’s Sales access resolved before checkout, RULE_ROLES, per-rule populations/severity, unique-member samples and real destinations |
apps/api/src/common/org-date.ts | Org-local today, date arithmetic, timezone-aware UTC boundaries |
apps/api/src/organization-leads/lead-attention.util.ts | Shared lead attention clock, candidate predicate, state ranking |
apps/api/src/payments/services/receipts.sql.ts | Canonical receipt predicates used by finance/report readers; not a replacement for stored-debt or failed-charge insight sources |
apps/api/src/ai/agent/tools/leaves/analytics.tools.ts | Owner/admin read-only analytics.org_insights; delegates with default owner role, unlike role-aware HTTP dispatch |
Web and owning destinations
| Path | Responsibility |
|---|---|
apps/web/src/components/overview/v2/action-center.tsx | Feed, null-safe nonlinked rows, bounded sample links, inline queues, Ask Spotter |
apps/web/src/components/overview/check-ins/check-in-review-queue.tsx | Embedded check-in review workflow |
apps/web/src/components/overview/forms/outstanding-forms-queue.tsx | Existing embedded outstanding-compliance workflow |
apps/web/src/components/overview/v2/overview-v2.tsx | Action Center → Today/tasks → permission/capability-owned trends → coaching roster; no KPI strip |
apps/web/src/app/[lang]/(protected)/dashboard/tasks/page.tsx | Unconditional supported-query hydration/history; real not_completed + type filters |
apps/web/src/components/overview/tasks/task-detail-sheet.tsx | Existing task working surface; no per-task route |
apps/web/src/components/payments/payment-tabs.tsx | Unconditional validated tab hydration, including tab=debt |
apps/web/src/app/[lang]/(protected)/dashboard/schedule/page.tsx | Validated program/date/session redirect; invalid/missing program falls back to Programs |
apps/web/src/app/[lang]/(protected)/dashboard/programs/[id]/page.tsx | Real program schedule tab |
apps/web/src/components/overview/schedule/weekly-calendar.tsx | Existing calendar and session-detail URL context |
apps/web/src/hooks/use-week-url-state.ts | Week query hydration shared by program calendar and stats |
apps/web/src/app/[lang]/(protected)/dashboard/members/members-ribbon.tsx | Total roster/commercial donut, trained/new/churned metrics and imported/at-risk callouts; no Ending soon tile |
apps/web/src/components/overview/members/retention-case-panel.tsx | Per-subscription case work; not the open-case feed’s ending-roster destination |
apps/web/src/components/analytics/reports-screen.tsx | Separate Reports workspace and its KPI snapshot, gated by analytics permission |
Database sources
libs/db/src/lib/schema/payments.ts— subscriptions and payment transactions; request/notice retention state is on subscriptions, not a separatecancellation_requeststable.libs/db/src/lib/schema/{organizations,memberships,users,tasks}.ts— org timezone/SLA, roster scope, sample people/birthdays, task obligations.libs/db/src/lib/schema/scheduling.ts— sessions, types/programs, bookings, and attached workouts.libs/db/src/lib/schema/forms.ts— compliance/check-in occurrences and form metadata.libs/db/src/lib/schema/{leads,conversations}.ts— lead links and inbound attention state.
Existing contract coverage
apps/api/src/insights/ contains:
insights.service.unit.spec.ts/insights.service.driver.tsinsights.connection-fanout.unit.spec.ts— one session per request, and a read count that does not move with how many members sit behind a cardinsights.controller.unit.spec.tsinsight-consolidation.unit.spec.tsinsight-consolidation.int.spec.ts/insight-consolidation.driver.tsforms-missing-roster-scope.int.spec.tscancellations-live-scope.int.spec.ts
Action Center coverage lives in
apps/web/src/components/overview/v2/action-center.int.spec.tsx and its driver.
These paths identify coverage; they are not a new execution/verification claim.