How aeroxy/drift works
• Overall shape: drift is a single Rust binary that bundles a React/TypeScript frontend and a WebSocket-based transfer engine. The binary can act as a local server, an outbound client to another drift instance, or a one-shot CLI tool for send/list/pull operations.
• Primary runtime boundary: there are two peers in every transfer. One side listens on a port and serves the web UI; the other side may connect outbound to --target. Once connected, both peers can expose their own filesystem and browse the remote one, so the app is naturally bidirectional rather than “server vs client” in a fixed sense.
• CLI entry layer: src/main.rs and src/config.rs parse the command set (serve, send, ls, pull, plus legacy flat args) and decide whether the process should launch the web server, open an outbound session, or do a one-off transfer and exit.
• Server subsystem: src/server/ contains the HTTP/WebSocket-facing backend. ws_handler.rs manages the encrypted WebSocket session, file_api.rs serves browse/info requests, browser_transfer.rs coordinates transfers initiated from the UI, and transfer_receiver.rs writes incoming data and handles extraction. This is the main boundary between the UI and filesystem.
• Client subsystem: src/client/ is the outbound side that connects to a remote drift instance when --target is set. browse.rs supports remote directory listing for ls, pull.rs implements downloading from a remote host, send.rs handles push/send mode, and reconnect.rs provides session re-establishment after disconnects.
• Protocol layer: src/protocol/ defines the wire contract. Control traffic uses encrypted JSON ControlMessage values; file payloads use a binary chunk format with a UUID and offset. The protocol is designed for concurrent requests and out-of-order replies, so correlation IDs matter to the architecture.
• Security layer: src/crypto/ implements the session security model. Peers perform an X25519 handshake, derive directional symmetric keys with HKDF-SHA256, optionally authenticate with a password-based HMAC challenge/response, and then encrypt all traffic with ChaCha20-Poly1305. The security boundary is the network link; the code assumes trusted peers after connection.
• Filesystem operations: src/fileops/ isolates local file access. browse.rs canonicalizes and validates browse paths against the root to prevent traversal, reader.rs and writer.rs implement chunked async I/O, and compress.rs / decompress.rs convert directories to and from .tar.gz for recursive folder transfer.
• Transfer behavior: file data moves in 64 KB chunks over encrypted WebSocket binary frames. Files are streamed directly; folders are compressed before upload and extracted on receipt. Large transfers therefore flow through the protocol layer into chunked file I/O rather than through a single buffered payload.
• Frontend subsystem: frontend/ is a React + TypeScript UI built with Vite/Bun. The main UI is a two-pane file browser with connection modal, path bar, file list, toolbar, and transfer progress bar. Hooks such as useWebSocket and useTransfer bind the UI to backend events and transfer state.
• Embedding and packaging: build.rs builds the frontend before Rust compilation, and src/frontend.rs serves the generated assets from the binary via embedded static files. That makes the shipped artifact self-contained: no separate web app deployment is required.
• Operational modes: the same codebase supports three distinct flows: interactive browsing via the web UI, direct CLI file movement (send, pull, ls), and reconnectable long-lived sessions. This is important for diagramming because the UI and CLI are thin entry points into the same underlying transport and filesystem subsystems.
• Testing and validation: frontend integration tests in frontend/test/ spin up real drift processes, transfer actual files over WebSocket, and verify checksums plus cleanup of temporary .drift/ directories. The tests exercise the full stack, not just isolated units.
• Useful diagram boundary: a good architecture diagram should show four main boxes: CLI/runtime orchestration, encrypted WebSocket protocol + crypto, filesystem/transfer services, and embedded frontend UI — with the WebSocket link as the central data path and the local filesystem as the protected backend resource.
Main entry points: server/mod.rs Server · ws_handler.rs WS Handler · main.rs Main · client/mod.rs Client
Components 22
Runtime
CLI entrypoints and process orchestration
- Main · Parses modes and starts server, client, or one-shot transfer flows
src/main.rs - Config · Command and mode parsing for serve, send, ls, and pull
src/config.rs - Server · HTTP/WebSocket-facing backend for local browsing and incoming transfers
src/server/mod.rs - Client · Outbound peer that connects to a remote drift instance
src/client/mod.rs - Reconnect · Re-establishes outbound sessions after disconnects
src/client/reconnect.rs
Network
Encrypted WebSocket protocol and session security
- Handshake · Performs key exchange and derives directional session keys
src/crypto/handshake.rs - Stream Crypto · Encrypts and decrypts WebSocket traffic with authenticated frames
src/crypto/stream.rs - Codec · Encodes control messages and binary transfer frames
src/protocol/codec.rs - Messages · Defines encrypted JSON control messages and request correlation
src/protocol/messages.rs - Transfer Proto · Defines file chunk payloads, UUIDs, and offsets for concurrent transfer
src/protocol/transfer.rs - WS Handler · Manages encrypted WebSocket sessions at the server boundary
src/server/ws_handler.rs
Transfer Services
Filesystem access and transfer execution
- File API · Serves browse and file information requests over the session
src/server/file_api.rs - Browser Transfer · Coordinates UI-initiated send and pull operations
src/server/browser_transfer.rs - Receiver · Writes incoming data and handles extraction on receipt
src/server/transfer_receiver.rs - Browse FS · Canonicalizes browse paths and prevents traversal outside the root
src/fileops/browse.rs - Chunk I/O · Implements chunked async reads and writes for large transfers
src/fileops/reader.rs - Compress · Packages directories into archives for recursive transfer
src/fileops/compress.rs - Decompress · Extracts received archives back into directories
src/fileops/decompress.rs
Frontend
Embedded React UI and its bundle pipeline
- Frontend Embed · Serves the built frontend assets from inside the Rust binary
src/frontend.rs - App UI · Two-pane file browser with connection, path, toolbar, and progress controls
frontend/src/App.tsx - WS Hook · Connects the UI to backend WebSocket events
frontend/src/hooks/useWebSocket.ts - Transfer Hook · Tracks transfer state and progress in the UI
frontend/src/hooks/useTransfer.ts
Connections 22
- Main → Config: parses · Chooses runtime mode and transfer command
- Main → Server: starts · Launches the local server/runtime path
- Main → Client: opens · Creates outbound sessions for remote targets
- Client → Reconnect: reconnects · Restores long-lived sessions after disconnects
- Server → WS Handler: accepts · Owns the encrypted network session boundary
- WS Handler → Handshake: negotiates · Performs key exchange before application traffic
- WS Handler → Stream Crypto: encrypts · Wraps all traffic in authenticated encryption
- Stream Crypto → Codec: frames · Carries control and binary messages over the wire
- Codec → Messages: encodes · Serializes request and response control messages
- Codec → Transfer Proto: encodes · Serializes chunked file payload frames
- Server → File API: routes · Exposes browse and info operations to peers
- Server → Browser Transfer: coordinates · Handles transfer actions initiated from the UI
- Browser Transfer → Receiver: delivers · Hands off incoming content for persistence
- File API → Browse FS: validates · Restricts paths to the configured local root
- Receiver → Chunk I/O: streams · Uses chunked I/O for large file movement
- Browser Transfer → Compress: packages · Archives directories before send
- Receiver → Decompress: extracts · Unpacks directory archives after receive
- Chunk I/O → Transfer Proto: moves · Transfers file bytes in 64 KB chunks
- Frontend Embed → App UI: serves · Embeds the generated UI bundle into the binary
- App UI → WS Hook: binds · Subscribes the UI to backend session events
- App UI → Transfer Hook: binds · Displays live transfer progress and status
- Client → WS Handler: connects · Uses the same protocol on the outbound peer side