A TypeScript implementation of the Raft consensus algorithm, structured as a monorepo.
Raft is a protocol for building fault-tolerant distributed systems. A cluster of nodes elects a leader, replicates a log of commands across all nodes, and applies those commands to a state machine — even when some nodes crash or become unreachable. This implementation covers leader election, log replication, snapshots, pre-vote, and joint-consensus cluster membership changes.
| Package | Description |
|---|---|
@maboke123/raft-core |
The core library — transport and storage agnostic |
@maboke123/raft-grpc |
gRPC transport adapter for real network deployments |
| App | Description |
|---|---|
example-cluster |
A runnable 3-node cluster with a WebSocket server for the devtools UI |
devtools |
A React visualizer that shows live cluster state, elections, and message flow |
packages/
raft-core/ the npm library — zero production dependencies
raft-grpc/ gRPC transport adapter
apps/
example-cluster/ runnable demo server (depends on raft-core + raft-grpc)
devtools/ React devtools UI (connects to example-cluster via WebSocket)
scripts/
GenerateCerts.sh generates self-signed TLS certificates for local testing
npm install
This installs dependencies for all packages and apps in one step.
npm run build
Or build a single package:
cd packages/raft-core
npm run build
npm run test
Or test a single package:
cd packages/raft-core
npm test
The example cluster starts three Raft nodes and a WebSocket server that streams events to the devtools UI.
cd apps/example-cluster
npm run dev
Then in a separate terminal, start the devtools UI:
cd apps/devtools
npm run dev
Open http://localhost:5173 to see the cluster visualizer.
For running the gRPC transport with mutual TLS locally:
bash scripts/GenerateCerts.sh
This generates a CA and node certificates under certs/. Do not commit the generated .key files.
Install from npm — you do not need to clone this repository to use the library:
npm install @maboke123/raft-core
# Optional: gRPC transport for real network deployments
npm install @maboke123/raft-grpc
See the raft-core README for the full usage guide.
InstallSnapshot RPCMetaStorage, LogStorage, SnapshotStorage, ConfigStorage) so you can implement exactly the backend you needTransport interface is minimal so you can bring any communication layerMIT