|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +lib-net is a hybrid TypeScript/Rust networking library (`@shardeum-foundation/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. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Building |
| 12 | +```bash |
| 13 | +# Full build (Rust + TypeScript) |
| 14 | +npm run build |
| 15 | + |
| 16 | +# Build only TypeScript |
| 17 | +npm run build-node |
| 18 | + |
| 19 | +# Build only Rust (debug mode) |
| 20 | +npm run build-rust-debug |
| 21 | + |
| 22 | +# Build only Rust (release mode) |
| 23 | +npm run build-rust-release |
| 24 | +``` |
| 25 | + |
| 26 | +### Testing |
| 27 | +```bash |
| 28 | +# Run all tests |
| 29 | +npm test |
| 30 | + |
| 31 | +# Run Rust tests |
| 32 | +npm run test:cargo |
| 33 | +# or |
| 34 | +cargo test |
| 35 | + |
| 36 | +# Run specific integration tests |
| 37 | +npm run it-test |
| 38 | +npm run it-test2 |
| 39 | +``` |
| 40 | + |
| 41 | +### Code Quality |
| 42 | +```bash |
| 43 | +# Run ESLint |
| 44 | +npm run lint |
| 45 | + |
| 46 | +# Check formatting |
| 47 | +npm run format-check |
| 48 | + |
| 49 | +# Fix formatting |
| 50 | +npm run format-fix |
| 51 | +``` |
| 52 | + |
| 53 | +### Release Process |
| 54 | +```bash |
| 55 | +# Patch release (1.6.0 -> 1.6.1) |
| 56 | +npm run release:patch |
| 57 | + |
| 58 | +# Minor release (1.6.0 -> 1.7.0) |
| 59 | +npm run release:minor |
| 60 | + |
| 61 | +# Major release (1.6.0 -> 2.0.0) |
| 62 | +npm run release:major |
| 63 | + |
| 64 | +# Pre-release versions |
| 65 | +npm run release:prepatch |
| 66 | +npm run release:preminor |
| 67 | +npm run release:premajor |
| 68 | +npm run release:prerelease |
| 69 | +``` |
| 70 | + |
| 71 | +## Architecture |
| 72 | + |
| 73 | +### Directory Structure |
| 74 | +- `src/`: TypeScript source code - API layer and Node.js bindings |
| 75 | +- `shardus_net/`: Main Rust crate implementing core networking functionality |
| 76 | +- `crypto/`: Rust crate for cryptographic operations (signing, verification) |
| 77 | +- `shardeum_utils/`: Shared Rust utilities |
| 78 | +- `test/`: Test files (unit tests in `test/unit/`, integration tests in root) |
| 79 | +- `build/`: TypeScript compilation output |
| 80 | +- `coverage/`: Test coverage reports |
| 81 | + |
| 82 | +### Key Components |
| 83 | + |
| 84 | +1. **TypeScript Layer** (`src/`) |
| 85 | + - `index.ts`: Main entry point, exports the network creation function |
| 86 | + - Handles Node.js integration and provides JavaScript-friendly API |
| 87 | + - Manages correlation of requests/responses using UUIDs |
| 88 | + |
| 89 | +2. **Rust Layer** (`shardus_net/`) |
| 90 | + - `lib.rs`: Main Rust library entry point |
| 91 | + - Compiles to `shardus-net.node` native module |
| 92 | + - Implements high-performance TCP socket handling |
| 93 | + - Features compression (flate2, brotli) and LRU caching |
| 94 | + - Uses Tokio for async runtime |
| 95 | + |
| 96 | +3. **Message Flow** |
| 97 | + - Messages are JSON-serialized with UUID correlation IDs |
| 98 | + - Supports request/response pattern with timeouts |
| 99 | + - Can send to multiple nodes simultaneously |
| 100 | + - Headers support compression options |
| 101 | + |
| 102 | +### Build Process |
| 103 | +1. Rust code compiles to a C dynamic library (`cdylib`) |
| 104 | +2. `cargo-cp-artifact` copies the compiled artifact to `shardus-net.node` |
| 105 | +3. TypeScript compiles to JavaScript in `build/` directory |
| 106 | +4. The `postinstall` script automatically builds Rust code when installing |
| 107 | + |
| 108 | +## Important Notes |
| 109 | + |
| 110 | +- **Node.js Version**: Requires exactly Node.js 18.19.1 |
| 111 | +- **Main Branch**: Development happens on `dev` branch (not `main` or `master`) |
| 112 | +- **Native Module**: The Rust code compiles to a native Node.js module - platform-specific builds required |
| 113 | +- **Security**: Follow responsible disclosure per SECURITY.md for vulnerabilities |
| 114 | +- **Testing**: Always run both TypeScript and Rust tests before submitting changes |
0 commit comments