Skip to Content
Living documentation — last reviewed 2026-05-28
FeaturesInsightsInsights — Code Map

Insights — Code Map

Shared contract and copy

PathResponsibility
libs/shared/src/lib/types/insights.types.tsAll InsightId values, five categories, severities, and nullable drilldownHref
libs/shared/src/lib/i18n/dictionaries/{en,he,ru}.jsoninsights.items.<id>, all-clear, counts, Ask Spotter copy

API

PathResponsibility
apps/api/src/insights/insights.module.tsInsights module wiring
apps/api/src/insights/insights.controller.tsActive-membership + staff gate; passes HTTP caller role
apps/api/src/insights/insights.service.ts20-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.tsOrg-local today, date arithmetic, timezone-aware UTC boundaries
apps/api/src/organization-leads/lead-attention.util.tsShared lead attention clock, candidate predicate, state ranking
apps/api/src/payments/services/receipts.sql.tsCanonical 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.tsOwner/admin read-only analytics.org_insights; delegates with default owner role, unlike role-aware HTTP dispatch

Web and owning destinations

PathResponsibility
apps/web/src/components/overview/v2/action-center.tsxFeed, null-safe nonlinked rows, bounded sample links, inline queues, Ask Spotter
apps/web/src/components/overview/check-ins/check-in-review-queue.tsxEmbedded check-in review workflow
apps/web/src/components/overview/forms/outstanding-forms-queue.tsxExisting embedded outstanding-compliance workflow
apps/web/src/components/overview/v2/overview-v2.tsxAction Center → Today/tasks → permission/capability-owned trends → coaching roster; no KPI strip
apps/web/src/app/[lang]/(protected)/dashboard/tasks/page.tsxUnconditional supported-query hydration/history; real not_completed + type filters
apps/web/src/components/overview/tasks/task-detail-sheet.tsxExisting task working surface; no per-task route
apps/web/src/components/payments/payment-tabs.tsxUnconditional validated tab hydration, including tab=debt
apps/web/src/app/[lang]/(protected)/dashboard/schedule/page.tsxValidated program/date/session redirect; invalid/missing program falls back to Programs
apps/web/src/app/[lang]/(protected)/dashboard/programs/[id]/page.tsxReal program schedule tab
apps/web/src/components/overview/schedule/weekly-calendar.tsxExisting calendar and session-detail URL context
apps/web/src/hooks/use-week-url-state.tsWeek query hydration shared by program calendar and stats
apps/web/src/app/[lang]/(protected)/dashboard/members/members-ribbon.tsxTotal 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.tsxPer-subscription case work; not the open-case feed’s ending-roster destination
apps/web/src/components/analytics/reports-screen.tsxSeparate 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 separate cancellation_requests table.
  • 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.ts
  • insights.connection-fanout.unit.spec.ts — one session per request, and a read count that does not move with how many members sit behind a card
  • insights.controller.unit.spec.ts
  • insight-consolidation.unit.spec.ts
  • insight-consolidation.int.spec.ts / insight-consolidation.driver.ts
  • forms-missing-roster-scope.int.spec.ts
  • cancellations-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.