A Stripe-inspired payment infrastructure built entirely in Rust.
This project recreates many of the core backend systems behind modern payment processors, including authentication, product management, recurring pricing, subscriptions, payment intents, and automatic billing.
Rather than acting as a wrapper around Stripe's APIs, the goal is to understand and implement the internal architecture that powers subscription-based payment platforms.
The backend models the lifecycle of a payment platform from merchant authentication to recurring billing.
Current functionality includes:
- Secure JWT authentication
- Cookie-based session management
- Product management
- Multiple prices per product
- Subscription management
- Automatic recurring billing
- Background subscription workers
- Payment Intent creation
- PostgreSQL persistence
Instead of requiring merchants to manually bill customers every month, subscriptions are monitored by a background worker which automatically creates payment intents whenever a subscription reaches its next billing date.
Most tutorials demonstrate how to integrate Stripe into an application.
Very few explain how Stripe itself could be implemented.
This project focuses on recreating the backend architecture behind payment processors to better understand:
- Authentication systems
- Subscription billing
- Asynchronous background workers
- REST API design
- Database modeling
- Production backend architecture
- Building scalable services with Rust
Authentication is fully JWT-based.
Upon successful signup, the backend generates both an access token and a refresh token. These are returned as HttpOnly cookies, preventing JavaScript access and improving security.
Current authentication features include:
- User registration
- JWT generation
- Access tokens
- Refresh tokens
- Cookie-based authentication
- Protected routes
- Argon2 password hashing
Passwords are never stored in plaintext. Every password is hashed using Argon2 before being persisted to PostgreSQL.
Each JWT contains:
- User ID
- Token Type
- Issued At
- Expiration Time
Protected endpoints automatically validate the access token before allowing access.
Products represent items or services offered by a merchant.
Each authenticated user owns their own collection of products, ensuring complete data isolation between accounts.
Current product functionality includes:
- Create products
- Retrieve products
- Ownership validation
- Product metadata
- Product activation status
Products intentionally do not contain pricing information.
Instead, pricing is handled separately, following Stripe's architecture.

A Product defines what is being sold.
A Price defines how much it costs.
Separating the two allows a single product to support multiple billing options.
For example, one product may offer:
- Monthly subscription
- Quarterly subscription
- Annual subscription
Current price fields include:
- Unit amount
- Currency
- Billing interval
- Billing interval count
- Active status
This design avoids duplicating product information for every pricing option.
Subscriptions connect customers to prices.
Rather than storing payment information directly, subscriptions reference a specific price.
Each subscription stores information such as:
- Current billing period
- Next billing date
- Status
- Trial dates
- Metadata
Subscriptions form the foundation of recurring billing.
One of the primary goals of this project is implementing recurring billing without relying on incoming HTTP requests.
A Tokio background task continuously scans the database for subscriptions whose billing period has expired.
For every due subscription the worker currently:
- Retrieves the associated price
- Creates a Payment Intent
- Simulates payment processing
- Updates subscription dates
- Marks failed subscriptions as
past_due
This closely mirrors how subscription billing operates in production payment systems.
Payments are modeled using Payment Intents rather than immediately charging customers.
Each Payment Intent stores information such as:
- Amount
- Currency
- Client Secret
- Status
- Associated Price
- Associated User
- Metadata
Separating Payment Intents from the actual payment process makes it possible to support retries, confirmations, refunds, multiple payment methods, and asynchronous processing later in development.
- User Signup
- JWT Authentication
- Access Tokens
- Refresh Tokens
- Cookie Authentication
- Argon2 Password Hashing
- Protected Routes
- Product Creation
- Product Retrieval
- Product Ownership
- Database Schema
- Product Relationship
- Recurring Billing Fields
- Subscription Schema
- Background Billing Worker
- Due Subscription Detection
- Automatic Payment Intent Creation
- Subscription Renewal Logic
- PostgreSQL Integration
- SQLx
- Database Migrations
- Modular Project Structure
- Centralized Error Handling
- Login Endpoint
- Payment Intent API
- Subscription API
- Price CRUD
- Customer Management
- Refresh Token Rotation
POST /signup
GET /products
POST /products/createPOST /signin
GET /prices
POST /prices/create
GET /subscriptions
POST /subscriptions/create
GET /payment_intents
POST /payment_intents
POST /payment_intents/:id/confirm
POST /payment_intents/:id/cancel
POST /checkout/sessions
POST /refunds
POST /webhookssrc/
├── auth/
│ ├── jwt.rs
│ ├── signup.rs
│ └── middleware.rs
│
├── products/
├── prices/
├── subscriptions/
├── config/
├── helpers/
├── errors/
└── main.rs
The project is organized into independent modules, allowing authentication, products, subscriptions, and billing logic to evolve independently while keeping the codebase maintainable.
- Rust
- Tokio
- Axum
- PostgreSQL
- SQLx
- JWT
- Argon2
- Cookies
- Serde
- Serde JSON
- UUID
- Chrono
- Login endpoint
- Checkout Sessions
- Customer API
- Charges API
- Refunds
- Invoice generation
- Webhook system
- Retry scheduling
- Email notifications
- Idempotency keys
- API keys
- Usage-based billing
- Metered pricing
- Multi-currency support
- Background job queue
- Metrics dashboard
- Fraud detection
- Admin dashboard
git clone <repository-url>
cd stripe-clone
cargo build
cargo runThe server starts on:
http://localhost:3000
The objective of this project is to understand how subscription-based payment platforms are engineered internally.
Instead of simply integrating with Stripe, the backend recreates many of the architectural concepts that make payment processors reliable and scalable, including authentication, recurring billing, payment orchestration, and asynchronous background processing.
MIT License
If this project helped you learn about payment infrastructure, subscription billing, Rust backend development, or distributed system design, consider giving it a ⭐.
Built with Rust, PostgreSQL, Tokio, and enough borrow checker negotiations to qualify as international diplomacy.