๐ช Mudra - Currency Converter
A robust, high-performance currency converter built in Rust with real-time and historical exchange rates, intelligent caching, and a beautiful CLI interface.
Mudra (เคฎเฅเคฆเฅเคฐเคพ) - Sanskrit/Hindi word meaning "currency" or "money"
โจ Features
- ๐ Real-time exchange rates from multiple currency providers
- ๐ Historical data support with date-specific conversions
- โก High-performance caching with configurable TTL
- ๐ฏ Type-safe currency handling with compile-time validation
- ๐ฅ๏ธ Beautiful CLI interface with colored output and progress indicators
- ๐ฑ Interactive mode for continuous currency conversions
- ๐ Batch processing for multiple conversions
- ๐งช Comprehensive error handling with detailed messages
- ๐ Performance monitoring with cache statistics
- ๐ก๏ธ Production-ready with extensive testing
๐ Quick Start
Installation
# Install from crates.io
# Or build from source
# Or download pre-built binaries from GitHub releases
# https://github.com/AshishBagdane/mudra/releases
Note: The package name is
mudra-clibut the binary is calledmudra
Get an API Key
- Sign up for a free account at exchangerate-api.com
- Get your API key from the dashboard (free tier: 1,500 requests/month)
- Set your environment variable:
Basic Usage
# Convert 100 USD to EUR
# Output: 100.00 USD = 85.23 EUR
# Get current exchange rates for USD
# Historical conversion
# Interactive mode
# Compare across multiple currencies
๐ Documentation
CLI Commands
Convert Currency
# Basic conversion
# With custom precision
# Historical conversion
# Verbose output
List Currencies
# Compact list
# Extended format
# Filter currencies
Exchange Rates
# All rates for USD
# Specific currencies only
# Historical rates
# Limited results
Compare Currencies
# Compare across multiple currencies
# Historical comparison
Cache Management
# View cache statistics
# Clear all cached data
# Clean up expired entries
Interactive Mode
# Then use commands like:
# > 100 USD EUR
# > convert 50 GBP JPY
# > rates USD
# > list
# > help
# > quit
๐๏ธ Library Usage
Basic Example
use ;
async
Advanced Example with Caching
use ;
async
Historical Data Example
use ;
async
๐๏ธ Architecture
Core Components
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ CLI โ โ Library โ โ API Client โ
โ (clap-based) โโโโโถโ (type-safe) โโโโโถโ (HTTP client) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Cache โ โ External API โ
โ (in-memory) โ โ (exchangerate- โ
โโโโโโโโโโโโโโโโโโโ โ api.com) โ
โโโโโโโโโโโโโโโโโโโ
Key Design Principles
- Type Safety: All currency codes and amounts are validated at compile time
- Error Handling: Comprehensive error types with context
- Performance: Intelligent caching with configurable TTL
- Modularity: Clean separation between CLI, library, and API layers
- Testability: Extensive unit and integration tests with mocking
Conversion Algorithm
- Same Currency: Return input amount (no API call)
- Direct Conversion: Use base currency rates directly
- Cross Conversion: Convert via USD as intermediate currency
// Example: GBP โ JPY via USD
// Step 1: Get USD rates (contains both GBP and JPY)
// Step 2: Calculate cross rate: JPY_rate / GBP_rate
// Step 3: Apply rate to amount
๐งช Testing
Run All Tests
# Unit tests
# Integration tests (requires wiremock)
# With coverage (requires cargo-tarpaulin)
Property-Based Testing
The project includes property-based tests using proptest:
# Run property tests
Performance Benchmarks
# Run benchmarks (requires API key for realistic results)
EXCHANGE_API_KEY=your_key
# Memory usage analysis
|
๐ Performance
Benchmarks
Typical performance on modern hardware:
- Type creation: ~10ns per Currency/Money instance
- Cache hit: ~1-5ms for cached conversions
- Cache miss: ~100-500ms (network dependent)
- Batch conversion: ~50-200ms for 10 currencies
- Memory usage: ~50KB baseline, ~1KB per cached entry
Cache Effectiveness
- Hit rate: 85-95% in typical usage
- TTL: 5 minutes for latest rates, 1 hour for historical
- Capacity: 1000 entries (configurable)
- Eviction: LRU (Least Recently Used)
๐ ๏ธ Development
Prerequisites
- Rust 1.70+
- API key from exchangerate-api.com
Build from Source
Development Commands
# Check code
# Format code
# Lint code
# Run tests
# Build release
# Run mudra
# Build documentation
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Ensure all tests pass:
cargo test - Format code:
cargo fmt - Submit a pull request
๐ Supported Currencies
The converter supports 168+ currencies including:
- Major: USD, EUR, GBP, JPY, CHF, CAD, AUD
- Asian: CNY, KRW, INR, SGD, HKD, THB, MYR
- European: SEK, NOK, DKK, PLN, CZK, HUF
- Americas: BRL, MXN, ARS, CLP, COP, PEN
- Others: ZAR, RUB, TRY, ILS, SAR, AED
Use currency_converter list to see all supported currencies.
โ๏ธ Configuration
Environment Variables
EXCHANGE_API_KEY: Your API key (required)EXCHANGE_BASE_URL: Custom API base URL (optional)NO_COLOR: Disable colored output (optional)
Cache Configuration
CacheConfig
๐ Troubleshooting
Common Issues
"API key not found"
"Invalid currency code"
- Use 3-letter ISO codes (USD, EUR, GBP)
- Check
currency_converter listfor supported currencies
"Network timeout"
- Check internet connection
- Increase timeout with custom configuration
"Rate limit exceeded"
- Free tier: 1,500 requests/month
- Upgrade plan or wait for reset
Debug Mode
# Enable verbose logging
RUST_LOG=debug
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- ExchangeRate-API for providing free exchange rate data
- Rust community for excellent libraries and tools
- All contributors who help improve this project
๐ Links
Made with โค๏ธ and ๐ฆ Rust