|
| 1 | +# OSVM-Web Crate - CLAUDE.md |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +**OSVM-Web** is a WebAssembly-based browser implementation of the OSVM Research TUI, enabling blockchain investigation directly in the browser via WebGL2 rendering. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +src/ |
| 11 | +├── lib.rs # WASM entry point, app state, event handling (~48K lines) |
| 12 | +└── graph.rs # Transaction graph visualization (~107K lines) |
| 13 | +``` |
| 14 | + |
| 15 | +## Key Components |
| 16 | + |
| 17 | +### Main App (`lib.rs`) |
| 18 | +- WASM bindings via `wasm-bindgen` |
| 19 | +- Ratzilla-based TUI rendering (ratatui for web) |
| 20 | +- Keyboard/touch event handling |
| 21 | +- API calls to backend via `gloo-net` |
| 22 | +- URL hash state for sharing investigations |
| 23 | + |
| 24 | +### Graph Visualization (`graph.rs`) |
| 25 | +- Transaction flow graph rendering |
| 26 | +- Node layout algorithms (force-directed, columnar) |
| 27 | +- Edge rendering with amount labels |
| 28 | +- Zoom/pan controls |
| 29 | +- AI insights panel integration |
| 30 | + |
| 31 | +## Building |
| 32 | + |
| 33 | +```bash |
| 34 | +# Install wasm-pack if not present |
| 35 | +cargo install wasm-pack |
| 36 | + |
| 37 | +# Build for web |
| 38 | +cd crates/osvm-web |
| 39 | +wasm-pack build --target web --release |
| 40 | + |
| 41 | +# Output in pkg/ |
| 42 | +# - osvm_web.js |
| 43 | +# - osvm_web_bg.wasm |
| 44 | +# - osvm_web.d.ts |
| 45 | +``` |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +```html |
| 50 | +<!DOCTYPE html> |
| 51 | +<html> |
| 52 | +<head> |
| 53 | + <style> |
| 54 | + body { margin: 0; background: #1a1a2e; } |
| 55 | + #terminal { width: 100vw; height: 100vh; } |
| 56 | + </style> |
| 57 | +</head> |
| 58 | +<body> |
| 59 | + <div id="terminal"></div> |
| 60 | + <script type="module"> |
| 61 | + import init, { OsvmApp } from './pkg/osvm_web.js'; |
| 62 | +
|
| 63 | + async function run() { |
| 64 | + await init(); |
| 65 | + const app = new OsvmApp('terminal'); |
| 66 | + app.start(); |
| 67 | + } |
| 68 | + run(); |
| 69 | + </script> |
| 70 | +</body> |
| 71 | +</html> |
| 72 | +``` |
| 73 | + |
| 74 | +## Features |
| 75 | + |
| 76 | +### Implemented |
| 77 | +- Full TUI in browser (WebGL2 rendering) |
| 78 | +- Wallet investigation mode |
| 79 | +- Transaction graph visualization |
| 80 | +- Token holdings display |
| 81 | +- AI insights panel |
| 82 | +- Touch support for mobile |
| 83 | +- URL hash state persistence |
| 84 | + |
| 85 | +### Touch Gestures |
| 86 | +- Single tap: Select |
| 87 | +- Double tap: Zoom in |
| 88 | +- Two-finger pinch: Zoom in/out |
| 89 | +- Two-finger pan: Move view |
| 90 | +- Swipe: Navigate tabs |
| 91 | + |
| 92 | +## Key Differences from CLI |
| 93 | + |
| 94 | +| Feature | CLI | Web | |
| 95 | +|---------|-----|-----| |
| 96 | +| Rendering | Terminal escape codes | WebGL2 via Ratzilla | |
| 97 | +| HTTP | reqwest (native) | gloo-net (fetch API) | |
| 98 | +| Storage | Filesystem | LocalStorage | |
| 99 | +| Input | stdin | DOM events | |
| 100 | + |
| 101 | +## Dependencies |
| 102 | + |
| 103 | +- `ratzilla` - ratatui for WASM/WebGL2 |
| 104 | +- `wasm-bindgen` - Rust/JS interop |
| 105 | +- `gloo-net` - HTTP fetch wrapper |
| 106 | +- `gloo-timers` - setTimeout/setInterval |
| 107 | +- `web-sys` - DOM API bindings |
| 108 | +- `js-sys` - JavaScript runtime bindings |
| 109 | + |
| 110 | +## API Endpoints |
| 111 | + |
| 112 | +The web app expects a backend at `/api/`: |
| 113 | + |
| 114 | +``` |
| 115 | +GET /api/wallet/{address} - Wallet info |
| 116 | +GET /api/wallet/{address}/transfers - Transfer history |
| 117 | +GET /api/wallet/{address}/tokens - Token holdings |
| 118 | +POST /api/research - AI research query |
| 119 | +``` |
| 120 | + |
| 121 | +## Size Optimization |
| 122 | + |
| 123 | +The release build uses aggressive optimization: |
| 124 | +- `opt-level = "z"` - Optimize for size |
| 125 | +- `lto = true` - Link-time optimization |
| 126 | +- `codegen-units = 1` - Better optimization |
| 127 | +- `panic = "abort"` - Remove unwinding |
| 128 | +- `strip = true` - Remove symbols |
| 129 | + |
| 130 | +Typical output: ~800KB WASM (gzipped: ~250KB) |
| 131 | + |
| 132 | +## Development |
| 133 | + |
| 134 | +```bash |
| 135 | +# Dev build with debug info |
| 136 | +wasm-pack build --target web --dev |
| 137 | + |
| 138 | +# Watch mode (requires cargo-watch) |
| 139 | +cargo watch -w src -s "wasm-pack build --target web --dev" |
| 140 | + |
| 141 | +# Test in browser |
| 142 | +python3 -m http.server 8080 |
| 143 | +# Open http://localhost:8080 |
| 144 | +``` |
| 145 | + |
| 146 | +## Known Limitations |
| 147 | + |
| 148 | +1. **No native Solana RPC** - Requires backend proxy for RPC calls |
| 149 | +2. **No filesystem** - Can't save files, use LocalStorage or download |
| 150 | +3. **WebSocket limitations** - Some browsers limit concurrent connections |
| 151 | +4. **Mobile keyboards** - Virtual keyboard may cover UI |
| 152 | + |
| 153 | +## Debugging |
| 154 | + |
| 155 | +```javascript |
| 156 | +// In browser console |
| 157 | +localStorage.setItem('OVSM_DEBUG', 'true'); |
| 158 | +location.reload(); |
| 159 | + |
| 160 | +// Check WASM memory |
| 161 | +console.log(wasmModule.memory.buffer.byteLength); |
| 162 | +``` |
0 commit comments