$ show juspay/hyperswitch
Hyperswitch is a composable open-source payments infrastructure built in Rust that provides a modular platform for processing payments through multiple connectors. The system handles the complete payment lifecycle including authorization, capture, refunds, and dispute management, while offering features like intelligent routing, 3DS authentication, revenue recovery, and analytics. Built with a microservices architecture using Actix-web, it features a plugin-based connector system, event-driven design with Redis/Kafka, and comprehensive SDK support for web and mobile platforms. The codebase demonstrates strong engineering practices with typesafe ID generation, robust encryption utilities, and well-abstracted interfaces that promote reusability and maintainability.
The LLM identified 10 files worth highlighting for reuse:
A typesafe ID generation system that creates prefixed, ULID-based identifiers for different entities (PaymentId, RefundId, etc.) with compile-time safety. The system uses procedural macros to generate ID types with embedded prefixes, preventing accidental mixing of different ID types. This solves a common problem in distributed systems where ID confusion can cause serious bugs.
An encryption utility implementing AES-GCM with key rotation support. It provides a clean interface for encrypting/decrypting sensitive data (PII, payment details) with automatic key versioning. The implementation handles nonce generation securely and includes proper error handling. This pattern is extractable and solves a universal need for secure data storage in applications.
Cryptographic utilities including PBKDF2 key generation and secure comparison functions. Provides constant-time comparison to prevent timing attacks and standardized hashing patterns. This is a security-focused component that addresses common vulnerabilities in authentication systems.
Extension traits for Result and Option types that add convenience methods like `change_context`, `attach_printable`, and `report`. These follow the error handling patterns from the `error_stack` crate but provide additional utility methods. This improves error handling ergonomics in a reusable way.
Personal Identifiable Information (PII) handling utilities that automatically mask sensitive data in logs and provide secure handling patterns. Includes types for email, phone, and name that implement Debug traits to prevent accidental logging of sensitive data. This addresses a critical privacy concern in a reusable manner.
An asynchronous caching layer with TTL support and metrics collection. Implements a thread-safe cache with background cleanup and Prometheus metrics for hit/miss ratios. This solves a common performance optimization need in web services.
Defines the core trait for payment connector integration that abstracts over different payment providers. Uses associated types and generic parameters to create a flexible interface that can be implemented for any payment gateway. This enables the plugin architecture that allows adding new payment connectors without changing core logic.
A typesafe SQL query builder that prevents SQL injection while providing flexibility for complex queries. Uses Rust's type system to ensure query validity at compile time. This addresses a common need for safe, dynamic query generation.
A robust HTTP client implementation with retry logic, timeout handling, and circuit breaker patterns. Includes metrics collection and proper error handling for external service calls. This solves a universal need for reliable external API communication.
Custom procedural macros that reduce boilerplate in the codebase, including the `id_type!` macro for generating typesafe IDs and `FromNew` derive macro for entity conversion. These demonstrate advanced Rust metaprogramming skills that improve code maintainability.