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

Analytics — Code Map

API

  • apps/api/src/analytics/analytics.module.ts
  • apps/api/src/analytics/analytics.controller.ts — REST surface, role guards, toCsv helper, EXPORT_TABS enum.
  • apps/api/src/analytics/analytics.service.ts — all aggregation methods. INTERVAL_MONTHS and MEMBERSHIP_ENDED_AT constants; typed response interfaces (AnalyticsRevenueSummary, RevenueTrendPoint, PlanDistributionEntry, MembersSummary, MembersActivation, AtRiskMember, …).
  • apps/api/src/payments/services/receipts.sql.tsRECEIPT_AT, SIGNED_RECEIPT_CENTS, MONEY_MOVED: the one definition of “money received” shared with PaymentAnalyticsService.
  • apps/api/src/analytics/analytics.service.driver.ts — DB test driver.
  • apps/api/src/analytics/analytics.service.unit.spec.ts — service tests (incl. the month-end millisecond regression).
  • apps/api/src/analytics/analytics.service.int.spec.ts — real-Postgres pins for the growth CTE, signed receipts and committed presale revenue.
  • apps/api/src/analytics/analytics.controller.unit.spec.ts — controller tests.

Agent surface

  • apps/api/src/ai/agent/tools/leaves/analytics.tools.ts — twelve analytics.* tool actions, each delegating to a service method.
  • libs/shared/src/lib/agent-schemas/analytics.ts — Zod schemas for the agent tool inputs.

Web

  • apps/web/src/app/[lang]/(protected)/dashboard/analytics/ — page tree with per-tab routes.
  • apps/web/src/components/analytics/* — KPI cards, charts, tables.
  • apps/web/src/components/overview/v2/revenue-panel.tsx — overview tile: 12 months of net receipts + PROJECTED_MONTHS outlined bars of mrr + committed from committedFrom; footer “Expected monthly”.
  • apps/web/src/components/overview/v2/growth-panel.tsx — overview tile over members/growth.
  • apps/web/src/lib/api/analytics.ts — typed client wrappers using useApi.

Insights cross-reference

  • apps/api/src/insights/insights.service.ts — the agent tool analytics.org_insights delegates here.

Schema dependencies

  • libs/db/src/lib/schema/payments.tssubscriptions, payment_transactions.
  • libs/db/src/lib/schema/memberships.tsmemberships.
  • libs/db/src/lib/schema/users.tsusers.
  • libs/db/src/lib/schema/scheduling.tsclass_sessions, bookings, class_types.
  • libs/db/src/lib/schema/workouts.tsworkouts, workout_assignments, personal_records.
  • libs/db/src/lib/schema/invitations.tsinvitations.
  • libs/db/src/lib/schema/organizations.tsorganizations.