Cursor Rules TemplatesCursor Rules Template

Cursor Rules Template: Stripe Subscription Dashboard with Usage-based Pricing

Cursor rules template for building a Stripe based subscription dashboard with usage based pricing invoices coupons and admin analytics

cursor-rules-templatecursor-rules-stripe-subscription-dashboardStripesubscriptionbillingusage-based-pricinginvoicescouponsadmin-analyticsCursor AInodejspostgresql

Target User

Developers building Stripe based subscription dashboards

Use Cases

  • Stripe subscription management with usage based pricing
  • Invoicing and coupon orchestration
  • Admin analytics and reporting
  • Cursor AI guided implementation

Markdown Template

Cursor Rules Template: Stripe Subscription Dashboard with Usage-based Pricing

Framework Role & Context:
- Stack: Node.js (Express) backend, PostgreSQL, Stripe Node SDK
- Role: Backend engineer wiring Stripe billing with a custom dashboard

Code Style and Style Guides:
- Use ESLint with a strict rule set, and Prettier for formatting
- Prefer async/await with try/catch error handling
- Write JSDoc for key functions

Architecture & Directory Rules:
- Keep domain logic under /src/billing and /src/payments
- DB access via a thin repository layer; avoid eager ORM coupling
- Separate webhooks into /src/webhooks/stripe
- Use environment based configs

Authentication & Security Rules:
- Server side only; never expose Stripe keys to the client
- Validate user tokens for every billing API call
- Validate Stripe webhook signatures with your secret

Database and ORM patterns:
- PostgreSQL with explicit migrations and seeding
- Tables: customers, subscriptions, usage_records, invoices, coupons
- Use parameterized queries to prevent SQL injection

Testing & Linting Workflows:
- Unit tests for billing services; integration tests hitting Stripe in test mode
- CI runs on push; pre-commit hooks for lint and tests

Prohibited Actions and Anti-patterns for the AI:
- Do not call client side Stripe API keys
- Do not bypass webhook verification
- Do not mix billing logic with UI rendering

Overview

Cursor rules configuration for a Stripe based subscription dashboard stack with usage based pricing, invoices, coupons and admin analytics powered by Cursor AI. This template helps you deliver a secure scalable backend and clear data model.

When to Use These Cursor Rules

  • Building a metered usage based pricing model using Stripe
  • Generating invoices and applying coupons in automated flows
  • Admin analytics for subscriptions, revenue, churn and coupon performance
  • Integrating Cursor AI rules to keep architecture aligned and auditable

Copyable .cursorrules Configuration

Framework Role & Context:
- Stack: Node.js (Express) backend, PostgreSQL, Stripe Node SDK
- Role: Backend engineer wiring Stripe billing with a custom dashboard

Code Style and Style Guides:
- Use ESLint with a strict rule set, and Prettier for formatting
- Prefer async/await with try/catch error handling
- Write JSDoc for key functions

Architecture & Directory Rules:
- Keep domain logic under /src/billing and /src/payments
- DB access via a thin repository layer; avoid eager ORM coupling
- Separate webhooks into /src/webhooks/stripe
- Use environment based configs

Authentication & Security Rules:
- Server side only; never expose Stripe keys to the client
- Validate user tokens for every billing API call
- Validate Stripe webhook signatures with your secret

Database and ORM patterns:
- PostgreSQL with explicit migrations and seeding
- Tables: customers, subscriptions, usage_records, invoices, coupons
- Use parameterized queries to prevent SQL injection

Testing & Linting Workflows:
- Unit tests for billing services; integration tests hitting Stripe in test mode
- CI runs on push; pre-commit hooks for lint and tests

Prohibited Actions and Anti-patterns for the AI:
- Do not call client side Stripe API keys
- Do not bypass webhook verification
- Do not mix billing logic with UI rendering

Recommended Project Structure

/src
  /billing
    invoice.ts
    subscription.ts
    usage.ts
  /webhooks
    stripe.ts
  /repositories
  /models
  /config
  /middleware
  /services
  /tests
  index.ts
  server.ts

Core Engineering Principles

  • Clear separation of concerns between billing domain and UI
  • Idempotent webhook handling and event replay resilience
  • Securing secrets and client side isolation
  • Explicit data models for customers, subscriptions, invoices, and usage
  • Automated tests for all critical flows

Code Construction Rules

  • Use Stripe webhooks with signature verification and idempotency keys
  • Model usage based pricing with metered events and Stripe Usage Records
  • Store only Stripe identifiers and tokens server side; never store raw payment data
  • Use server side rendering for sensitive dashboards; never embed keys in client code
  • Keep coupon and promotion logic centralized and auditable

Security and Production Rules

  • Enable TLS everywhere and rotate API keys periodically
  • Validate all inputs and enforce least privilege for Stripe actions
  • Protect webhook endpoints behind a firewall and log all billing actions

Testing Checklist

  • Unit tests for billing services and repository methods
  • Integration tests for Stripe event handling and invoice generation
  • End to end tests for coupon application and usage based pricing
  • CI pipeline runs lint, tests, and security checks

Common Mistakes to Avoid

  • Exposing Stripe keys on the client side
  • Skipping webhook signature verification
  • Mixing business logic with UI code
  • Ignoring idempotency in webhook processing

Related Cursor rules templates

Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.

FAQ

What is the purpose of this Cursor Rules Template for Stripe?

This Cursor Rules Template provides a complete, copyable .cursorrules configuration and project guidelines for building a Stripe based subscription dashboard with usage based pricing invoices coupons and admin analytics using Cursor AI.

Does this template support usage based pricing with metered billing?

Yes. The rules include usage based pricing modeling, metered usage events, limits, and automatic prorations via Stripe Usage Records and Subscriptions, aligned with Cursor AI decision making.

How should I structure the repository for this stack?

Follow the Recommended Project Structure: a Node.js backend, a PostgreSQL database, Stripe integration, and a webhook handler. Avoid client side Stripe keys and store only tokenized data server side.

What are the security requirements for Stripe webhooks?

Verify webhook signatures using Stripe signing secret, implement idempotent event handling, and never rely on client supplied data for billing actions.

What tests should I include?

Include unit tests for services, integration tests for Stripe events, and end to end tests for invoice generation coupon application and metered usage. Use CI to run tests on push.

How does this Cursor rules template handle usage based pricing at scale?

The template defines a metered usage model using Stripe Usage Records tied to subscriptions with audit logs and safeguards to prevent billing drift at scale.