⚡ Magnéto-Serge
Multi-language HTTP/WebSocket proxy library with record/replay capabilities
VCR for the modern web - Record HTTP/HTTPS and WebSocket traffic, replay it deterministically
Features • Installation • Quick Start • Documentation • Examples
🎯 Features
🔒 HTTP/HTTPS Proxy
- MITM interception
- Auto TLS certificates
- Request/Response capture
🔌 WebSocket Support
- Bidirectional messages
- Timing preservation
- Protocol agnostic
🌍 Multi-Language
- JavaScript, Rust
- Python, Kotlin, Swift (planned)
- Universal cassette format
📝 Dynamic Templates 🆕
- Environment variables
- Dynamic timestamps
- Request context access
- Custom helpers
🎯 Test Integrations 🆕
- RSpec (Ruby)
- Jest (JavaScript)
- pytest (Python)
- PHPUnit (PHP)
⚡ High Performance
- Rust-powered core
- 10-100x faster than VCR
- Minimal overhead
Why Magnéto-Serge?
| Feature | Magnéto-Serge | VCR (Ruby) | Polly (JS) |
|---|---|---|---|
| Multi-language | ✅ Rust + JS ready | ❌ Ruby only | ❌ JS only |
| WebSocket | ✅ Full support | ❌ No | ⚠️ Limited |
| Performance | ⚡ Rust-powered | 🐌 Ruby | 🐌 JS |
| HTTPS MITM | ✅ Auto certs | ⚠️ Manual | ⚠️ Manual |
| Zero config | ✅ Auto mode | ❌ | ❌ |
📦 Installation
🍺 Homebrew (macOS/Linux) - Recommended
# Add the tap
# Install
# Verify
🚀 One-Line Installer (curl)
|
📥 Pre-built Binaries
Download from GitHub Releases:
- macOS:
magneto-macos-amd64.tar.gz(Intel) ormagneto-macos-arm64.tar.gz(Apple Silicon) - Linux:
magneto-linux-amd64.tar.gzormagneto-linux-arm64.tar.gz - Windows:
magneto-windows-amd64.exe.zip
# Example for macOS ARM64
🦀 Rust (Cargo)
[]
= "0.6.0"
Or install the CLI:
# From crates.io (pending)
# Or from GitHub (current)
🟨 JavaScript/TypeScript (npm)
# Via npm (GitHub Packages)
const = require;
🐍 Python, ☕ Java, 🟣 Kotlin, 🍎 Swift (Coming Soon)
Multi-language bindings are in development. See ROADMAP.md for status.
🚀 Quick Start
⚡ Automated Setup (Makefile)
The fastest way to get started with the complete ecosystem:
# Check dependencies
# Quick setup (install + build)
# Install everything (Rust + Node.js backends + Angular clients)
# Start complete stack (API + Backend + Frontend)
# Individual services
# CLI examples
# Utilities
Complete Makefile reference: Run make help for all 50+ commands.
Basic Usage (Rust)
use ;
JavaScript Example
const = require;
// Create proxy instance
const proxy = ;
proxy.;
proxy.;
// Start recording
proxy.;
// Configure your HTTP client to proxy through localhost:8888
// Make your API requests...
// Stop recording
proxy.;
proxy.;
How It Works
graph LR
A[Your App] -->|HTTP Request| B[Magnéto-Serge<br/>Proxy :8888]
B -->|Record Mode| C[Real API]
B -->|Replay Mode| D[Cassette]
C -->|Response| B
D -->|Cached| B
B -->|Response| A
B -->|Save| D
3 Modes:
- 🔴 Record: Proxy → Real API → Save to cassette
- ▶️ Replay: Proxy → Load from cassette → Return cached
- 🟢 Auto: Record if cassette missing, replay if exists
💡 Examples
const = require;
const axios = require;
;
use ;
async
Enable dynamic content generation during replay with Handlebars templates:
use Player;
use Path;
// Compile with templates feature
// cargo build --features templates
// Set environment variable
set_var;
// Load cassette with templates
let player = load?;
// Templates are automatically rendered during replay
let interaction = player.get_interaction?;
Example Cassette with Templates:
Built-in Helpers:
| Helper | Description | Example Output |
|---|---|---|
{{ env "VAR" }} |
Environment variable | sk-test-1234567890 |
{{ now }} |
ISO 8601 timestamp | 2025-10-26T08:30:45Z |
{{ now_timestamp }} |
Unix epoch | 1729930245 |
{{ uuid }} |
UUID v4 | a1b2c3d4-e5f6-... |
{{ request.method }} |
HTTP method | POST |
{{ request.url }} |
Request URL | https://api.example.com/... |
{{ request.headers.xxx }} |
Request header | Header value |
Custom Helpers:
let mut player = load?;
player.template_engine_mut.register_helper;
// Use in cassette: {"id":"{{ random_id }}"}
Learn More:
🌐 REST API
Magneto-Serge provides a complete REST API with Hydra/JSON-LD and OpenAPI 3.0 support for remote proxy control.
Starting the API Server
# Start the API server (with Hydra hypermedia support)
# Opens: http://127.0.0.1:8889
# REST API: http://127.0.0.1:8889/cassettes
# Hydra API: http://127.0.0.1:8889/api/cassettes
# Or legacy API command
# With authentication
# Custom host/port
Key Features
- ✅ Hypermedia (HATEOAS): Self-documenting with Hydra/JSON-LD links
- ✅ OpenAPI 3.0: Complete specification at
/openapi.json - ✅ Authentication: Bearer token support
- ✅ CORS: Cross-origin requests enabled
- ✅ Language-agnostic: Use from any HTTP client
Quick Example
# Start proxy via API
# Check status
# Stop proxy
Available Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
API root with Hydra links |
GET |
/openapi.json |
OpenAPI 3.0 specification |
GET |
/health |
Health check |
POST |
/proxy/start |
Start proxy (auto/record/replay/passthrough) |
POST |
/proxy/stop |
Stop proxy |
GET |
/proxy/status |
Get proxy status |
GET |
/proxy/stats |
Get statistics |
GET |
/cassettes |
List all cassettes |
GET |
/cassettes/{name} |
Get cassette content |
DELETE |
/cassettes/{name} |
Delete cassette |
Client Examples
=
# Start proxy
=
# Get status
=
# Follow Hydra links
=
const fetch = require;
const api = 'http://localhost:8889';
// Start proxy
await ;
// Get status with authentication
const status = await .;
console.log;
#!/bin/bash
API="http://localhost:8889"
# List cassettes
|
# Start proxy with authentication
# Get OpenAPI spec
|
Hypermedia Navigation
Every API response includes Hydra links for discoverability:
Clients can discover and navigate the API dynamically without hardcoding URLs!
Full API Documentation
See docs/API.md for complete reference including:
- Authentication setup
- Request/response schemas
- Error handling
- Integration examples (CI/CD, Docker, Kubernetes)
- Swagger UI setup
🌐 Web Ecosystem
Magneto-Serge includes a complete web stack with multiple frontend/backend architectures.
Architecture Options
1. CLI Only ⚡
→ Perfect for scripts, CI/CD
2. Production Stack 🏭
Angular Client
↓
Node.js Backend
↓
Magneto API
→ Recommended for production
3. Hydra Demo 🔬
Angular + Alcaeus
↓
Magneto API
→ Hypermedia demonstration
Quick Start: Complete Stack
# Automatic (with tmux)
# Or manual (3 terminals)
Opens:
- API: http://localhost:8889/api (Rust/Axum - Hydra API)
- Backend: http://localhost:3000 (Node.js/Express)
- Frontend: http://localhost:4201 (Angular 17 - Production client)
- Hydra Demo: http://localhost:4200 (Angular 17 - Direct Alcaeus demo)
Components
1. Backend Node.js (Recommended)
Location: examples/nodejs-backend/
Alcaeus wrapper exposing simplified REST API:
# → http://localhost:3000
Features:
- ✅ Alcaeus native (Node.js, zero polyfill)
- ✅ Server-side cache (shared across clients)
- ✅ JSON-LD → JSON simplification
- ✅ Production-ready architecture
Docs: nodejs-backend/README.md | ARCHITECTURE.md
2. Angular Frontend (Production)
Location: frontend/
Production Angular 17 client with Hydra hypermedia navigation:
# Development server (with workaround for Angular 17 + Vite)
# → http://localhost:4201
# Or using npm scripts
Features:
- ✅ Angular 17 with standalone components
- ✅ Material Design UI components
- ✅ NgRx state management (Redux pattern)
- ✅ Alcaeus Hydra client integration
- ✅ Hypermedia navigation (HATEOAS)
- ✅ Cassette list with pagination
- ✅ Cassette detail view with interactions
- ✅ Interaction details view (Phase 3.4) 🆕
- HTTP request/response visualization
- WebSocket message timeline
- Copy-to-clipboard functionality
- cURL command generation
- ✅ Comprehensive testing (Phase 3.5) 🆕
- 186 unit tests (98.9% pass rate)
- 74.73% code coverage
- NgRx Store fully tested
- ✅ Real-time updates
Stack:
- Angular 17.3 (Standalone Components)
- Angular Material 17.3
- NgRx 17.2 (Store + Effects)
- Alcaeus 1.1.0
- RxJS 7.8
Docs: frontend/DEVELOPMENT.md | PHASE-3-COMPLETE 🆕 | PHASE-2-COMPLETE.md
Note: Due to Angular 17 + Vite dev server issue, use dev-server.sh script which builds and serves with http-server + auto-rebuild. See PHASE-2.4-TESTING.md for details.
3. Angular Simple Client (Alternative)
Location: examples/angular-simple-client/
Alternative lightweight Angular client using the Node.js backend:
# → http://localhost:4202
Features:
- ✅ Native HttpClient (no Alcaeus/RDF)
- ✅ Simple TypeScript types
- ✅ Lightweight build (~50kb)
- ✅ Full proxy control dashboard
Docs: angular-simple-client/README.md
4. Angular Hydra Demo
Location: examples/angular-client/
Educational demonstration of Hydra/JSON-LD navigation with Alcaeus in browser:
# → http://localhost:4200
Features:
- ✅ Alcaeus integration in browser
- ✅ Automatic Hydra navigation (zero hardcoded URLs)
- ✅ JSON-LD parsing
- ⚠️ Requires Node.js polyfills (+100kb)
Docs: angular-client/README.md
Architecture Comparison
| Aspect | CLI | Frontend (Hydra) | Simple Client + Backend | Hydra Demo |
|---|---|---|---|---|
| Use Case | Scripts, CI/CD | Production web app | Lightweight web app | Education |
| Complexity | ✅ Simple | ✅ Medium | ✅ Medium | ⚠️ Complex |
| Build Size | N/A | ⚠️ ~4.2MB (dev) | ✅ ~50kb | ⚠️ ~150kb |
| Features | Full CLI | Hypermedia + NgRx | REST API | Alcaeus demo |
| Dependencies | Rust only | Angular + Alcaeus | Node + Angular | Alcaeus + RDF |
| Performance | ✅ Maximum | ✅ Client-side state | ✅ Server cache | ⚠️ Client parsing |
| Production | ✅ Yes | ✅ Recommended | ✅ Yes | ⚠️ Demo only |
Complete Guides
- QUICK_START.md: Comprehensive startup guide with 5 use cases
- PHASE-2-COMPLETE.md: Phase 2 summary (Hydra API + Angular frontend)
- frontend/DEVELOPMENT.md: Frontend development guide
- PHASE-2.4-TESTING.md: Angular 17 + Vite issue documentation
- examples/README.md: All examples catalog
- examples/nodejs-backend/ARCHITECTURE.md: 3-tier production architecture
📋 Cassette Format
Cassettes are language-agnostic JSON files - record in Rust, replay in JavaScript!
Format features:
- ✅ JSON or MessagePack (with
msgpackfeature) - ✅ Share across languages
- ✅ Version controlled (git-friendly)
- ✅ Human readable
🏗️ Architecture
graph TB
A[MagnetoProxy API] --> B[HTTP Handler]
A --> C[WebSocket Interceptor]
B --> D[Recorder/Player]
C --> D
D --> E[Cassette Storage JSON]
B --> F[Hudsucker MITM]
C --> G[tokio-tungstenite]
F --> H[TLS Certificate Manager]
Core components:
- 🎯 MagnetoProxy: Public API (Rust + NAPI-RS for JS)
- 🔄 HTTP Handler: MITM proxy with Hudsucker
- 🔌 WebSocket Interceptor: Bidirectional message capture
- 💾 Recorder/Player: Cassette serialization & matching
- 🔐 TLS Manager: Auto-generated certificates
🎯 Use Cases
🧪 Testing
// Record real API once, replay thousands of times
// ✅ No network flakiness
// ✅ Instant test execution (no API calls)
// ✅ Offline development
// ✅ Deterministic tests in CI/CD
🐛 Debugging
// Capture production traffic
// Replay locally for investigation
// Inspect every request/response
📊 Development
// Mock external APIs during development
// Work offline with cached responses
// Consistent test fixtures across team
🛠️ Development
Using Makefile (Recommended)
# Clone repository
# Check dependencies
# Quick setup
# Or step by step
# Development workflow
# CI/CD checks
# See all commands
Manual Commands
# Build Rust library
# Run all tests (68 tests)
# Run integration tests
# Lint
# Format
# Build JavaScript bindings
# Build Angular clients
&& &&
&& &&
# Build Node.js backend
&&
Running Tests
# Rust unit tests (47 tests)
# Integration tests (9 tests)
# WebSocket tests (5 tests)
# JavaScript tests
Current Test Status: 68/68 passing ✅
- 33 Rust unit tests
- 9 Rust integration tests
- 5 WebSocket integration tests
- 10+ JavaScript API tests
- 7+ JavaScript HTTP tests
Project Structure
magneto-serge/
├── src/
│ ├── lib.rs # Core library
│ ├── proxy.rs # MagnetoProxy implementation
│ ├── cassette.rs # Cassette format
│ ├── player.rs # Replay engine
│ ├── recorder.rs # Record engine
│ ├── websocket/ # WebSocket support
│ ├── tls/ # TLS certificate management
│ └── error.rs # Error types
├── bindings/
│ └── javascript/ # NAPI-RS bindings for Node.js
│ ├── src/lib.rs
│ ├── package.json
│ └── index.js
├── tests/ # Integration tests
│ ├── integration_test.rs
│ └── websocket_integration.rs
├── examples/ # Usage examples
└── docs/ # Documentation
├── ROADMAP.md
└── ARCHITECTURE.md
📚 Documentation
| Documentation | Description |
|---|---|
| QUICK_START.md | 🚀 Quick start guide with use cases |
| Makefile | ⚡ 50+ automation commands |
| ROADMAP.md | 🗺️ Development roadmap & progress |
| ARCHITECTURE.md | 🏗️ Technical architecture details |
| API.md | 🌐 Complete REST API reference |
| TECH-STACK.md | 📚 Complete dependency list |
| SECRETS_SETUP.md | 🔐 GitHub secrets setup for CD |
| CLAUDE.md | 🤖 AI assistant instructions |
Phase 2 (Hydra API + Frontend):
| Documentation | Description |
|---|---|
| PHASE-2-COMPLETE.md | ✅ Phase 2 completion summary |
| frontend/DEVELOPMENT.md | 🅰️ Frontend development guide |
| PHASE-2.4-TESTING.md | 🔧 Angular 17 + Vite troubleshooting |
Web Ecosystem:
| Documentation | Description |
|---|---|
| nodejs-backend/README.md | 🟢 Node.js backend guide |
| nodejs-backend/ARCHITECTURE.md | 🏗️ Production architecture (3-tier) |
| angular-simple-client/README.md | 🅰️ Alternative Angular client |
| angular-client/README.md | 🅰️ Hydra demo client |
| examples/README.md | 📚 All examples catalog |
Bindings:
| Documentation | Description |
|---|---|
| JavaScript README | 🟨 JS/TS bindings guide |
🎯 Roadmap
| Phase | Status | Progress | Details |
|---|---|---|---|
| Phase 1 - HTTP/HTTPS Proxy | ✅ Complete | 100% | MITM proxy, record/replay |
| Phase 2 - Hydra API + Frontend | ✅ Complete | 100% | REST API, Angular UI, Hypermedia |
| Phase 3 - Testing & Polish | ✅ Complete | 100% | 186 tests (98.9% pass), 74.73% coverage, NgRx tested |
| Phase 4 - CLI & Production | ✅ Complete | 100% | CLI tool, templates, benchmarks |
Current Status (v0.7.0) 🆕
✅ Completed:
- Core Rust library with full HTTP/HTTPS support
- WebSocket record/replay with timing preservation
- JavaScript bindings (NAPI-RS)
- CLI tool with 8 commands (
magneto record,replay,auto, etc.) - REST API with Hydra/JSON-LD (hypermedia-driven)
- Angular 17 frontend with Material Design and NgRx
- Cassette list with pagination and filtering
- Cassette detail view with interactions list
- Interaction details view with HTTP/WebSocket visualization 🆕
- Copy-to-clipboard and cURL generation 🆕
- Comprehensive test suite: 186 tests (98.9% pass rate) 🆕
- Code coverage: 74.73% (+23% improvement) 🆕
- NgRx Store fully tested (reducer + selectors) 🆕
- Dynamic templates with Handlebars (env vars, timestamps, custom helpers)
- 186 tests passing (Angular) + 92 tests (Rust) = 278 total tests 🆕
- CI/CD pipeline with GitHub Actions (all checks passing) ✅
- Auto-generated TLS certificates
- Docker support (Alpine + Debian images)
🚧 In Progress:
- Publishing to crates.io (code ready, pending registry)
- Publishing to npm (GitHub Packages)
- Homebrew formula (needs update for v0.6.0)
📅 Planned (Phase 5):
- Python bindings (UniFFI)
- Java/Kotlin bindings
- Performance benchmarks documentation
- Release 1.0
See SESSION-2025-10-27-PHASE3-COMPLETE.md for Phase 3 details, PHASE-2-COMPLETE.md for Phase 2, and ROADMAP.md for detailed milestones.
🤝 Contributing
We welcome contributions! Issues are now enabled on this repository.
Here's how to contribute:
- 🍴 Fork the repository
- 🔧 Create a feature branch (
git checkout -b feature/amazing) - ✅ Add tests for your changes
- 🎨 Run
cargo fmtandcargo clippy - 📝 Commit with descriptive message
- 🚀 Push to your fork
- 🎉 Open a Pull Request
Development requirements:
- Rust 1.75+ (MSRV)
- Cargo
- (Optional) Node.js 18+ for JavaScript bindings
- (Optional) Python 3.9+ for Python bindings (planned)
Areas where we need help:
- 🐍 Python bindings (UniFFI)
- ☕ Java/Kotlin bindings
- 📚 Documentation improvements
- 🧪 More integration tests
- 🎨 Logo design
- 🌐 Translations
📊 Performance
Current benchmarks (Rust):
- HTTP proxy throughput: ~5000 req/s (target met)
- WebSocket message rate: ~10k msg/s (target met)
- Proxy latency: <1ms p50
- Memory footprint: <50 MB
Test environment:
- MacBook Pro M1 (ARM64)
- Rust 1.75
- Release build with LTO
Note: Formal benchmarks coming in Phase 4. Use
cargo benchfor testing.
🐛 Known Issues
- ⚠️ HTTPS interception requires installing CA certificate in system trust store
- ⚠️ WebSocket replay timing may vary slightly from recording
- ⚠️ Large cassettes (>100MB) may impact performance
See Issues for complete list and workarounds.
📄 License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
🌟 Acknowledgments
Inspired by:
- VCR - Ruby HTTP recording library (original)
- Polly.JS - JavaScript HTTP mocking
- Betamax - Python VCR port
- VHS - Rust VCR attempt (unmaintained, used as starting point)
Built with:
- Hudsucker - HTTP/HTTPS MITM proxy framework
- NAPI-RS - Node.js addon framework for Rust
- Tokio - Async runtime for Rust
- tokio-tungstenite - WebSocket implementation
- rcgen - TLS certificate generation
- serde - Serialization framework
🔗 Links
- 🏠 Homepage: GitHub Repository
- 📦 Crates.io: Coming soon
- 📦 npm: @taciclei/magneto-serge
- 📖 Documentation: docs/
- 💬 Issues: GitHub Issues
- 🎬 Discussions: GitHub Discussions
⚡ Made with Rust for maximum performance and safety
Current Version: 0.6.0