This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is Shardus Core (@shardeum-foundation/core), the foundational technology for building distributed/sharded blockchain applications. It implements a sophisticated consensus system with P2P networking, state management, and transaction processing capabilities.
npm run build:dev- Build TypeScript to JavaScript (for development)npm run build:release- Build to bytecode for production releasenpm run clean- Clean build artifacts
npm run lint- Run ESLint on TypeScript filesnpm run format-check- Check code formatting with Prettiernpm run format-fix- Fix code formatting with Prettiernpm run depcheck- Check for unused dependencies
npm test- Run unit tests with Jestnpm run test-watch- Run tests in watch mode
- Node.js version: 18.19.1 (exact version required)
- Rust toolchain must be installed (cargo must be in PATH)
-
P2P Layer (
src/p2p/)- Join Protocol v2: Handles node joining process with multi-phase validation
- Cycle Management: Implements cycle-based consensus rounds (CycleChain, CycleCreator, CycleParser)
- Network Operations: Sync, Apoptosis (node removal), Rotation, Lost node detection
- Archiver System: Manages data persistence across archivers
-
State Manager (
src/state-manager/)- Account Management: Caching, synchronization, and partitioning of account states
- Transaction Processing: Queue management, consensus, and receipt generation
- Repair Mechanisms: Handles data repair and synchronization across shards
-
Cryptography (
src/crypto/)- Proof of Work (POW) generation for network operations
- Integration with
@shardeum-foundation/lib-crypto-utils
-
Storage (
src/storage/)- SQLite3 and Better-SQLite3 support for persistent storage
- Database initialization and management
- Cycle-Based Consensus: The network operates in cycles where nodes collectively agree on network state changes
- Sharding: Data is partitioned across nodes based on address space
- Account-Based Model: State is organized around accounts with synchronization protocols
- Multi-Phase Protocols: Critical operations (like joining) use multiple validation phases
- Type definitions are in
src/types/with runtime validation using AJV - Path aliases configured:
@src/*→src/*@utils/*→src/utils/*@test/*→test/*
- Unit tests mirror source structure in
test/unit/ - Integration tests in
test/integration/ - Jest configuration in
jest.config.js - Tests use TypeScript and ts-jest
- ESLint configured with security plugins
- Never commit secrets or API keys
- Extensive input validation using AJV schemas
- Network operations use cryptographic signatures
When modifying network protocols:
- Check the relevant documentation in
/docs(e.g., join protocol, safety mode) - Update both the implementation and corresponding unit tests
- Consider impacts on cycle consensus and state synchronization
When working with state management:
- Understand partition assignments and account coverage
- Follow existing patterns for transaction queuing and consensus
- Ensure proper cleanup in failure scenarios
The project uses bytecode compilation for production releases:
- Development builds use plain JavaScript
- Release builds compile to bytecode using Bytenode
- The
dist/directory contains the final build artifacts