# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
**coinlive** is an interactive command-line tool written in Rust that displays live cryptocurrency prices from Binance. It features a TUI (terminal user interface) with multiple views: price list, price table, historical price charts, symbol search, help, and about pages.
## Commands
```bash
# Build and run
cargo run # Debug build
cargo run --release # Optimized release build
cargo b # Alias for build (defined in .cargo/config.toml)
cargo br # Alias for build --release
cargo rr # Alias for run --release
# Testing
cargo test # Run tests
cargo t # Alias for test
# Code quality
cargo check # Type check without building
cargo clippy # Lint
```
## Architecture
### Data Flow
1. **WebSocket Connection** (`main.rs:84-126`): Connects to Binance's `!ticker@arr` stream for real-time price updates
2. **REST API** (`utils.rs`): Fetches exchange info, 24hr tickers, and klines (candlestick data) from Binance REST API
3. **Message Passing**: Uses tokio unbounded channels (`UnboundedSender<Msg>`) to communicate between async tasks
4. **UI Rendering** (`ui.rs`): TUI manages state and renders different views based on keyboard input
### Key Modules
- **`src/main.rs`**: Entry point, WebSocket client, keyboard input listener
- **`src/utils.rs`**: Binance API integration, data types (`Info`, `Market`, `Update`, `Bar`), parsing/formatting utilities
- **`src/ui.rs`**: UI state management, view routing, message handling, drawing loop
- **`src/ui/*.rs`**: Individual pages (price_list, price_table, graph, search, help, about, nice)
### Key Data Types
- `Symbol = InlineString`: Crypto pair symbol (e.g., "BTCUSDT")
- `Info`: Symbol metadata (base, quote, volume)
- `Market`: Price, 24h volume, price change
- `Update`: Real-time price update from WebSocket
- `Bar`: OHLCV candlestick data for charts
### View System
The UI uses an enum-based view system (`UIView`) with these states:
- `PriceList`: Scrollable list sorted by volume
- `PriceTable`: Grid (base × quote currencies)
- `Graph`: Historical price chart with time scale selection (0-9 keys)
- `Search`: Symbol picker
- `Help` / `About`: Informational pages
## Keyboard Controls
| `h` | Help |
| `l` | Price list |
| `t` | Price table |
| `g` | Graph (current symbol) |
| `0-9` | Graph with time scale |
| `s` | Search/symbol selection |
| `%` | Toggle percent/price |
| `x` | Toggle extended/reduced table |
| `a` | About |
| `Esc` | Go back |
| `q/Ctrl-c` | Quit |
## Dependencies
Key crates:
- `tokio` / `tokio-tungstenite`: Async runtime and WebSocket
- `tui` / `termion`: Terminal UI framework
- `serde` / `serde_json`: Serialization
- `dec`: Decimal64 for precise financial calculations
- `clap`: CLI argument parsing
- `chrono`: Date/time formatting