You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main.py: FastAPI endpoints for heartbeat, discovery, PoH, authorization
database.py: Users, Nodes, Transactions tables with credit ledger
auth.py: JWT ticket generation and verification
benchmark.py: PyTorch matrix multiplication for hardware verification
Worker (Rust)
main.rs: Detects engines, initializes model registry, launches heartbeat and proxy
heartbeat.rs: Broadcasts node status with periodic model refresh (default 3min)
proxy.rs: Axum server that verifies JWT, parses model name, routes to correct engine
gpu.rs: Detects GPU idle state via nvidia-smi
engines/: Multi-engine drivers (Ollama, vLLM, LM Studio) with priority-based routing
Client (Rust)
main.rs: CLI with up, balance, nodes commands
proxy.rs: Local server on :9000 that mimics OpenAI API, discovers nodes, obtains JWT, connects P2P
Shared (Rust)
models.rs: Serde types for NodeHeartbeat, ChallengeRequest, JWTClaims, etc.
Architecture Flow
Worker detects all available engines (Ollama, vLLM, LM Studio) → builds model registry
Worker detects idle GPU → broadcasts heartbeat with models from all engines → stored in Redis
Client receives OpenAI request → asks Coordinator for authorization
Coordinator finds idle node with requested model → issues signed JWT ticket → returns node IP
Client connects directly to Worker's Tailscale IP with JWT
Worker verifies JWT → parses model from request → routes to correct engine → streams response back
No data passes through Coordinator during inference (pure P2P)
Model registry refreshes every 3 minutes, heartbeat only sent on changes
Development Commands
# Build everything
cargo build --workspace
# Run coordinator locallycd coordinator && uvicorn main:app --reload
# Run worker
cargo run --bin monkey-troop-worker
# Run client
cargo run --bin monkey-troop-client up
# Run tests
cargo test --workspace
cd coordinator && pytest
# Format code
cargo fmt --all
cd coordinator && black .# Lint
cargo clippy --all-targets
cd coordinator && ruff check .