Payment Database Schema
The payment system uses a flexible database schema designed to support multiple billing models and payment providers while maintaining clean separation of concerns.Schema Design Philosophy
Plans and Subscriptions
The schema focuses on:- Plans for pricing metadata
- Subscriptions for ongoing access
- Payments for charge history
- Change pricing without affecting feature logic
- Support multiple billing models simultaneously
- Switch payment providers easily
Core Models
Plan Model
Located inapps/api/prisma/schema.prisma
Stores subscription plans and their Stripe integration details:
- Links to Stripe products and prices
- Supports multiple billing intervals (monthly, yearly, one-time)
- Currency and amount tracking
- Active/inactive status for plan management
stripePriceId- Links to Stripe Price objectsstripeProductId- Links to Stripe Product objectsinterval- Billing frequency (monthly, yearly, one_time)amount- Price in cents for display purposes
Subscription Model
Tracks active user subscriptions with full Stripe integration:- Links users to their active plans
- Stores Stripe subscription and customer IDs
- Tracks subscription status and billing periods
- Handles cancellation scheduling
- Belongs to a
User - References a
Plan - Synced with Stripe via webhooks
Payment Model
Stores individual Stripe payment intents:- Links users to Stripe payment intents and customers
- Tracks success/failure status
- Records paid timestamps
Indexing Strategy
The schema includes strategic indexes for performance:Primary Lookups
User.email- Authentication and user lookupPayment.stripePaymentIntentId- Payment lookup
Stripe Integration
Plan.stripePriceId- Webhook processingSubscription.stripeSubscriptionId- Webhook processingSubscription.userId- User subscription queries
Relationships Overview
Example Scenarios
Payment History
- Query
Paymentfor user + recent records - Display status and timestamps
- Use Stripe IDs for reconciliation if needed
Subscription Changes
- Stripe webhook updates
Subscriptionstatus - System updates internal
Subscriptionstatus - User immediately sees new access levels