|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +cfproxy is a Rust CLI that exposes localhost services to the internet via Cloudflare Tunnels with a rich ratatui-powered TUI dashboard. It automatically manages the `cloudflared` binary (download, cache, update) and provides real-time connection status, request metrics, and tunnel details. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +cargo build # Dev build |
| 13 | +cargo build --release # Release build |
| 14 | +cargo run -- 3000 # Run against local port 3000 |
| 15 | +cargo test # Run all tests (unit + integration) |
| 16 | +cargo test <test_name> # Run a single test |
| 17 | +cargo clippy -- -D warnings # Lint (treat warnings as errors) |
| 18 | +cargo fmt # Format code |
| 19 | +cargo check # Type-check without building |
| 20 | +RUST_LOG=debug cargo run -- 3000 # Run with debug logging |
| 21 | +``` |
| 22 | + |
| 23 | +A `Makefile` wraps these: `make build`, `make test`, `make lint`, `make fmt`, `make run PORT=3000`. |
| 24 | + |
| 25 | +## Dependencies |
| 26 | + |
| 27 | +- **Rust toolchain** (1.70+) via rustup |
| 28 | +- **cloudflared** is auto-downloaded at runtime; no manual install needed |
| 29 | + |
| 30 | +## Architecture |
| 31 | + |
| 32 | +Async pipeline: CLI args → config → resolve/download `cloudflared` binary → spawn tunnel subprocess → parse stderr into typed `TunnelEvent`s via mpsc channel → drive TUI. |
| 33 | + |
| 34 | +Key modules in `src/`: |
| 35 | + |
| 36 | +- **main.rs** — Entry point, wires components together |
| 37 | +- **cli.rs** — CLI argument definitions (clap derive) |
| 38 | +- **config.rs** — Builds runtime `Config` from parsed args |
| 39 | +- **cloudflared.rs** — `BinaryManager`: locate, cache, or download the cloudflared binary |
| 40 | +- **tunnel.rs** — Spawns cloudflared subprocess, parses stderr into `TunnelEvent`s |
| 41 | +- **event.rs** — `TunnelEvent` enum (central data type shared across modules) |
| 42 | +- **metrics.rs** — Fetches/parses Prometheus metrics from cloudflared's local metrics server |
| 43 | +- **ui/** — TUI rendering and event loop (ratatui + crossterm), split into state, render, overlays, requests, detail, helpers |
| 44 | +- **proxy.rs** — Local reverse proxy (hyper) that captures HTTP requests for the TUI |
| 45 | +- **qr.rs** — QR code generation for tunnel URL |
| 46 | +- **har.rs** — HAR file export |
| 47 | +- **diff.rs** — Request diff utilities |
| 48 | +- **mock.rs** — Mock response rules (matched against incoming requests) |
| 49 | +- **settings.rs** — Persistent settings (`~/.config/cfproxy/settings.json`) |
| 50 | +- **cloudflare.rs** — Cloudflare API client (tunnels, DNS, ingress management) |
| 51 | +- **setup.rs** — Interactive setup wizard for custom domain configuration |
| 52 | +- **purge.rs** — Find and clean stale/orphaned tunnels and DNS records |
| 53 | +- **doctor.rs** — Diagnostic checks (settings, binary, network, API, tunnel, DNS) |
| 54 | +- **error.rs** — Unified error type and `Result` alias |
| 55 | + |
| 56 | +Integration tests live in `tests/integration.rs`. |
0 commit comments