Skip to Content
Living documentation — last reviewed 2026-05-28
FeaturesSubscriptions PlansSubscriptions & Plans — Code Map

Subscriptions & Plans — Code Map

API

apps/api/src/plans/

  • plans.module.ts
  • plans.controller.ts@Controller('organizations/:orgId/plans'). RequiresFeature('membership_plans') on mutating routes.
  • plans.service.tscreate | findAll | findById | update | remove | purchase. Internal requireFeature helper for service-layer tier checks.
  • plans.service.unit.spec.ts — unit tests.
  • dto/
    • create-plan.dto.ts
    • update-plan.dto.ts
    • purchase-plan.dto.ts{ successUrl, cancelUrl }.

apps/api/src/subscriptions/

  • subscriptions.module.ts
  • subscriptions.controller.ts — both member-scoped (/subscriptions/my/*) and admin-scoped (/subscriptions/:id/*) routes.
  • subscriptions.service.ts — lifecycle. Includes sweepDueCancellations invoked by the cron.
  • cancellation-cron.service.ts@Cron('30 2 * * *') flips cancel_at_period_end rows to cancelled.
  • cancellation-requests.controller.ts — request submission + owner approve/reject.
  • cancellation-requests.service.ts — owns the cancellation_requests table lifecycle.
  • cancellation-flow.int.spec.ts — integration test for the full request → approve → refund handshake.
  • dto/
    • enroll-member.dto.ts

Web (apps/web/src/)

  • app/[lang]/(protected)/dashboard/plans/ — plan CRUD UI.
  • app/[lang]/(protected)/dashboard/payments/ — owner-side payments console (includes a Cancellations tab driven by components/payments/cancellation-requests-list.tsx).
  • app/[lang]/(protected)/dashboard/members/ — admin sub view, freeze/cancel actions.
  • components/subscriptions/cancel-subscription-dialog.tsx — member-facing self-cancel UI.
  • components/payments/cancellation-requests-list.tsx — owner approve/reject UI.
  • components/payments/cancellations-widget.tsx — dashboard counts (pending requests + scheduled cancels).
  • components/member/plan-card.tsx — member-facing subscription summary.

Shared

  • libs/shared/src/lib/schemas/plan.schema.ts — Zod schemas for PlanResponse.
  • libs/shared/src/lib/schemas/membership.schema.tsSubscriptionResponse, SubscriptionWithPlan.

DB

  • libs/db/src/lib/schema/payments.tsplans, subscriptions, cancellation_requests.
  • libs/db/src/lib/schema/enums.tsplanType, planInterval, subscriptionStatus, cancellationRequestStatus, membershipPaymentStatus.
  • libs/db/src/lib/schema/memberships.tsmemberships.paymentStatus is mutated by the renewal cron + webhook processor.

Notifications

  • apps/api/src/notifications/cancellation-notifications.service.tscancellationScheduled, cancellationRequestSubmitted, cancellationRequestApproved, cancellationRequestRejected, newCancellationRequestForOwner, refundCompleted.
  • apps/api/src/notifications/templates/payment-failed.ts, debt-warning.ts, payment-receipt.ts.

Cross-references

  • apps/api/src/payments/services/webhook-processing.service.ts — mutates subscriptions on payment events.
  • apps/api/src/payments/services/recurring-charge.service.ts — mutates subscriptions and memberships.paymentStatus daily.
  • apps/api/src/bookings/ — calls subscriptionsService.deductCredit / refundCredit.
  • apps/api/src/courses/course-checkout.service.ts — uses plan.type='course' rows, bypasses plans.purchase.