Architecture β
Bridge Payments is built on a modern, scalable architecture designed for high performance and reliability.
System Overview β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client Applications β
β (React, Next.js, React Native, Mobile Apps) β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
β HTTPS/REST API
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β Bridge Payments API β
β (Hono + Bun Runtime) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Auth Bridge β β Payment β β Webhook β β
β β Validator β β Engine β β System β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββ¬ββββββββ β
β β β β β
β β β β β
β ββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌββββββββ β
β β LRU Cache Layer β β
β ββββββββ¬βββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββ β
β β β β β
β ββββββββΌβββββββ ββββββββΌβββββββ βββββββΌβββββββ β
β β Provider β β Database β β External β β
β β Adapters β β Layer β β Webhooks β β
β ββββββββ¬βββββββ ββββββββ¬βββββββ βββββββ¬βββββββ β
βββββββββββΌβββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββ
β β β
β β β
βββββββΌββββββ βββββββΌββββββ βββββββΌββββββ
β Stripe β βPostgreSQL β β Discord β
β PayPal β β MySQL β β Slack β
βAuthorize β β SQLite β βCustom APIsβ
βββββββββββββ βββββββββββββ βββββββββββββCore Components β
1. Authentication Bridge β
Purpose: Validates user sessions with Flowless backend
Features:
- Session validation with Flowless API
- Token-based authentication
- Guest token validation and caching
- Automatic session refresh
- Rate limiting
Flow:
Client Request β Extract Session ID β Validate with Flowless β Cache Result β Continue2. Payment Processing Engine β
Purpose: Handles payment intent creation, confirmation, and status management
Features:
- Payment intent lifecycle management
- Multi-provider support (Stripe, PayPal, Authorize.net)
- Client secret generation and cleanup
- Payment status synchronization
- Automatic retry logic
Payment Flow:
Create Intent β Generate Client Secret β Frontend Confirmation β Sync Status β Update Database3. Provider Adapters β
Purpose: Abstract payment provider implementations
Supported Providers:
- Stripe: Credit cards, Apple Pay, Google Pay, 3D Secure
- PayPal: PayPal accounts, Venmo, credit cards
- Authorize.net: Credit cards, bank accounts
Adapter Pattern:
interface PaymentProvider {
createPaymentIntent(data: PaymentIntentData): Promise<ProviderIntent>;
confirmPayment(intentId: string): Promise<ProviderPayment>;
syncPaymentStatus(paymentId: string): Promise<PaymentStatus>;
createCustomer(data: CustomerData): Promise<ProviderCustomer>;
createPaymentMethod(data: PaymentMethodData): Promise<ProviderPaymentMethod>;
}4. Database Layer β
Purpose: Multi-database support with type-safe queries
Technology: Kysely ORM
Supported Databases:
- PostgreSQL
- MySQL
- SQLite
- LibSQL (Turso)
- Neon
- PlanetScale
Schema:
provider_payments- Payment transactionsprovider_payment_methods- Saved payment methodsprovider_customers- Customer informationprovider_addresses- Billing addressesprovider_subscriptions- Recurring subscriptionsprovider_webhooks- Webhook event log
5. Webhook System β
Purpose: Process provider webhooks and send external notifications
Provider Webhooks:
- Stripe webhook signature validation
- PayPal webhook signature validation
- Automatic event processing
- Database updates
External Webhooks:
- Event filtering and routing
- Signature generation
- Retry logic with exponential backoff
- Multiple endpoint support
6. Cache Layer β
Purpose: High-performance in-memory caching
Technology: LRU Cache
Cached Data:
- Guest token validations (1 hour TTL)
- User session validations (5 minutes TTL)
- Payment method lists (5 minutes TTL)
- Customer data (5 minutes TTL)
Benefits:
- Reduced database queries
- Faster response times
- Lower Flowless API calls
- Improved scalability
Technology Stack β
Runtime & Framework β
- Bun: High-performance JavaScript runtime (3x faster than Node.js)
- Hono: Lightweight web framework (optimized for edge computing)
Database β
- Kysely: Type-safe SQL query builder
- Multi-database support: PostgreSQL, MySQL, SQLite, LibSQL, Neon, PlanetScale
Validation β
- Zod: TypeScript-first schema validation
- Runtime type checking: Ensures data integrity
Payment SDKs β
- stripe: Official Stripe Node.js SDK
- @paypal/sdk-client: Official PayPal SDK
- authorizenet: Official Authorize.net SDK
Utilities β
- LRU Cache: In-memory caching
- Croner: Cron job scheduling (client secret cleanup)
Security Architecture β
Authentication Flow β
1. Client sends request with X-Session-ID header
2. Bridge Payments validates session with Flowless
3. Flowless returns user data or error
4. Bridge Payments caches validation result
5. Request proceeds with user contextClient Secret Management β
1. Payment intent created β Client secret generated
2. Client secret sent to frontend
3. Frontend confirms payment with provider
4. Client secret automatically deleted after 24 hours
5. Cron job cleans up expired secretsWebhook Security β
1. Provider sends webhook with signature
2. Bridge Payments validates signature
3. Event processed and database updated
4. External webhooks triggered with new signature
5. Retry logic for failed deliveriesScalability β
Horizontal Scaling β
Bridge Payments is designed to scale horizontally:
- Stateless architecture: No server-side sessions
- Database connection pooling: Efficient database usage
- LRU cache: In-memory caching per instance
- Load balancer ready: Can run multiple instances
Performance Optimizations β
- Bun runtime: 3x faster than Node.js
- Kysely ORM: Optimized SQL queries
- LRU cache: Reduces database load
- Async operations: Non-blocking I/O
- Connection pooling: Reuses database connections
Database Optimization β
- Indexed columns: Fast lookups on user_id, customer_id, provider_payment_id
- Composite indexes: Optimized for common queries
- Partitioning ready: Can partition by date for large datasets
Deployment Architecture β
Pubflow Platform Deployment β
Pubflow Dashboard β Create Instance β Configure Providers β Deploy
β
βββββββββββββββββββ
β Bridge Payments β
β Instance β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Database β
β (Managed) β
βββββββββββββββββββEnvironment Configuration β
All configuration managed through Pubflow dashboard:
- Payment provider credentials
- Database connection
- Flowless integration
- External webhooks
- Feature flags
Monitoring & Observability β
Logging β
- Structured logging: JSON format for easy parsing
- Log levels: DEBUG, INFO, WARN, ERROR
- Request logging: All API requests logged
- Error tracking: Detailed error information
Metrics β
- Payment success rate: Track successful vs failed payments
- Response times: Monitor API performance
- Cache hit rate: Measure cache effectiveness
- Webhook delivery rate: Track webhook success
Next Steps β
- Configuration - Configure your instance
- API Reference - Explore the API
- Testing - Test your integration