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

Webhooks — Code Map

Module

  • apps/api/src/webhooks/webhooks.module.ts — imports UsersModule and MembershipsModule; registers the Clerk controller.

Controller

  • apps/api/src/webhooks/clerk-webhook.controller.ts — single @Public() POST /webhooks/clerk handler. Verifies the Svix signature, switches on event.type, delegates to user/membership services.

Dependencies

  • apps/api/src/users/users.service.ts
    • findOrCreateFromClerk(clerkId) — creates/loads the DB user.
    • syncFromClerk(clerkId, { email, imageUrl }) — mirrors Clerk profile.
    • deleteSelf(clerkId, { skipClerk: true }) — soft-deletes the local row.
  • apps/api/src/memberships/memberships.service.ts
    • acceptPendingInvitations(clerkId) — promotes invited memberships to active on first sign-up.
  • apps/api/src/event-tracking/event-tracking.service.ts
    • identify(userId, props) + track(userId, event, props) — PostHog fanout.

Raw body capture

  • apps/api/src/main.ts — express json parser is configured with a verify hook that stashes req.rawBody = buf so Svix can re-hash the exact bytes.

Env

  • CLERK_WEBHOOK_SECRET — set in apps/api/.env. Provided by the Clerk dashboard.

Schema

  • libs/db/src/lib/schema/users.tsusers table.
  • libs/db/src/lib/schema/memberships.tsmemberships table (status enum).
  • apps/api/src/payments/providers/cardcom.provider.ts
  • apps/api/src/payments/providers/morning.provider.ts
  • apps/api/src/payments/providers/bit.provider.ts
  • Each exposes its own @Public() controller endpoint.