saas-platform-patterns

Implements SaaS monetization patterns for NestJS including licensing, subscriptions, and checkout flows.

Updated Jun 14, 2026
One-click install
npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill saas-platform-patterns-ironkid90-s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: saas-platform-patterns
Source: https://github.com/ironkid90-s/lucky5-v7/tree/main/.ptah/skills/saas-platform-patterns
Command: npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill saas-platform-patterns-ironkid90-s

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building a monetizable SaaS backend requires coordinating plan configuration, license key management, subscription state machines, checkout validation, and trial lifecycle logic, and wiring these incorrectly leads to duplicate charges, leaked premium features, and provider lock-in. ## Core Features & Use Cases - Plan Configuration and Feature Gating: Define tiers as static TypeScript config with feature flags and usage limits, enforced server-side via NestJS guards like @RequireFeature. - License Lifecycle Management: Generate 256-bit license keys, manage status transitions (active, expired, revoked, paused), and expose a rate-limited public verification endpoint with caching. - Subscription State Machine: Handle payment provider webhooks (created, activated, canceled, past_due, paused, resumed) with provider-agnostic handlers that provision licenses and emit internal events. - Checkout and Trial Flows: Pre-checkout validation, customer portal sessions, price ID mapping, trial reminders, and auto-downgrade on trial expiry. - Use Case: A NestJS team adding a freemium model to their API uses this Skill to scaffold plans.config.ts, a LicenseService, webhook-driven SubscriptionService, and a checkout controller without coupling business logic to Stripe or Paddle. ## Quick Start Ask the AI to implement a freemium monetization layer for a NestJS backend with community, pro, and enterprise tiers including license verification and subscription webhook handling.

Frequently Asked Questions about saas-platform-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a subscription state machine in NestJS?

Create a SubscriptionService with handler methods for each payment provider webhook event such as created, activated, canceled, and past_due. Each handler updates the Prisma subscription record, provisions or revokes licenses, and emits internal events via EventEmitter2 for side effects like emails.

How do I generate and verify license keys in a NestJS app?

Generate keys with crypto.randomBytes(32) as hex with a prefix like lic_, store them in a Prisma License model with status and plan fields, and expose a rate-limited POST /licenses/verify endpoint. Cache verification results in memory or Redis with a 5-minute TTL.

Should subscription plans be stored in the database or config files?

Store plans as a static TypeScript config file rather than database records. This keeps pricing changes in version control, avoids schema migrations for plan tweaks, and enables type-safe feature checks at compile time.

Does this approach work with Stripe, Paddle, and LemonSqueezy?

Yes, the patterns are provider-agnostic by design. Payment provider SDKs sit behind an abstraction layer, and webhook events are mapped to generic internal handlers, so swapping providers only requires changing the adapter, not business logic.

How do I handle trial expiration and auto-downgrade?

Track trials with a trial_ prefix on the plan slug and a trialEnd timestamp, then run a scheduled cron task that finds expired trials, marks subscriptions as expired, and provisions a community-tier license. Send reminder emails at 7, 3, and 1 days before expiry.

Why should feature gating be enforced server-side instead of in the frontend?

Frontend feature flags can be modified by users, so they should only control UI visibility. Always verify plan membership server-side using a NestJS guard like PlanGuard with a @RequireFeature decorator before executing protected endpoint logic.