$ show getpaykit/paykit
PayKit is an open-source, embedded billing framework for TypeScript applications. It provides a core library (`paykitjs`) that handles subscription management, metered usage tracking, feature entitlements, and webhook processing – all backed by PostgreSQL and currently integrated exclusively with Stripe as the payment provider. The monorepo includes a CLI for project scaffolding and migration, a client SDK, a dashboard plugin (`@paykitjs/dash`), a documentation website (Next.js + Fumadocs), a demo application, and a webhook tunnel worker (Cloudflare Workers + Durable Objects). The architecture is modular: a core `createPayKit()` instance orchestrates services for customers, subscriptions, entitlements, products, and invoices, each following a service pattern with Drizzle ORM models. A plugin system allows custom endpoints, and a provider abstraction (currently only Stripe) handles payment operations. The codebase is well-structured with TypeScript end-to-end, extensive E2E testing against Stripe test clocks, and a clean separation of concerns. However, it is in alpha stage, has duplicated UI component libraries across apps, and is tightly coupled to Stripe – factors that limit immediate reuse without adaptation.
The LLM identified 4 files worth highlighting for reuse:
Defines the `PaymentProvider` interface (upsertCustomer, checkout, attachPaymentMethod, charge, refund, handleWebhook). This is an isolated, self-contained abstraction that enables swapping payment providers. It imports only external types and is highly reusable for implementing alternative providers (e.g., Paddle, Braintree) with minimal modification.
Implements entitlement checking and reporting with a CTE-based query for efficient balance lookups, lazy-reset logic (no cron needed), and stacked deduction fallback. Demonstrates non-obvious SQL optimization and domain logic extraction. The pattern of reset intervals and unlimited features is generic and could be reused in any metering system.
Handles Stripe webhook processing with idempotency via `stripe_event_id` deduplication, buffered delivery for unknown customers, and automated retry of failed events after 5 minutes. The event status tracking and error handling pattern is reusable for any external event stream that requires reliable, at-least-once processing.
Exports template strings for generating product definition files (e.g., `feature()`, `plan()` calls) and framework-agnostic configuration. These templates are hand-crafted, parameterized, and isolated from internal modules. They can be reused or adapted to scaffold billing configurations in new projects.