This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
lib-net is a hybrid TypeScript/Rust networking library (@shardus/lib-net) that provides TCP-based JSON message passing between nodes with request/response patterns. The library uses native Rust code for performance-critical networking operations while exposing a TypeScript API for Node.js applications.
# Full build (Rust + TypeScript)
npm run build
# Build only TypeScript
npm run build-node
# Build only Rust (debug mode)
npm run build-rust-debug
# Build only Rust (release mode)
npm run build-rust-release# Run all tests
npm test
# Run Rust tests
npm run test:cargo
# or
cargo test
# Run specific integration tests
npm run it-test
npm run it-test2# Run ESLint
npm run lint
# Check formatting
npm run format-check
# Fix formatting
npm run format-fix# Patch release (1.6.0 -> 1.6.1)
npm run release:patch
# Minor release (1.6.0 -> 1.7.0)
npm run release:minor
# Major release (1.6.0 -> 2.0.0)
npm run release:major
# Pre-release versions
npm run release:prepatch
npm run release:preminor
npm run release:premajor
npm run release:prereleasesrc/: TypeScript source code - API layer and Node.js bindingsshardus_net/: Main Rust crate implementing core networking functionalitycrypto/: Rust crate for cryptographic operations (signing, verification)shardus_utils/: Shared Rust utilitiestest/: Test files (unit tests intest/unit/, integration tests in root)build/: TypeScript compilation outputcoverage/: Test coverage reports
-
TypeScript Layer (
src/)index.ts: Main entry point, exports the network creation function- Handles Node.js integration and provides JavaScript-friendly API
- Manages correlation of requests/responses using UUIDs
-
Rust Layer (
shardus_net/)lib.rs: Main Rust library entry point- Compiles to
shardus-net.nodenative module - Implements high-performance TCP socket handling
- Features compression (flate2, brotli) and LRU caching
- Uses Tokio for async runtime
-
Message Flow
- Messages are JSON-serialized with UUID correlation IDs
- Supports request/response pattern with timeouts
- Can send to multiple nodes simultaneously
- Headers support compression options
- Rust code compiles to a C dynamic library (
cdylib) cargo-cp-artifactcopies the compiled artifact toshardus-net.node- TypeScript compiles to JavaScript in
build/directory - The
postinstallscript automatically builds Rust code when installing
- Node.js Version: Requires exactly Node.js 18.19.1
- Main Branch: Development happens on
devbranch (notmainormaster) - Native Module: The Rust code compiles to a native Node.js module - platform-specific builds required
- Security: Follow responsible disclosure per SECURITY.md for vulnerabilities
- Testing: Always run both TypeScript and Rust tests before submitting changes