How andrearcaina/hyperion works
1. What this repo is
- hyperion is a distributed key-value database built around Raft consensus.
- The current running shape is a single hyprd node exposing an HTTP API that forwards writes into Raft and then into a local KV store.
2. Top-level process split
- There are two command binaries:
- cmd/hyprd is the daemon/node process.
- cmd/hyprctl is intended as the operator/client CLI, but the README says it is still a roadmap item.
- This separation is important: the node owns storage/consensus, while the CLI is meant to talk to running nodes externally.
3. Bootstrapping and composition
- internal/server is the orchestration layer that wires together the HTTP server, the Raft store/node, logging, and any future transports.
- cmd/hyprd/main.go and cmd/hyprd/cmd/root.go are the entrypoints that likely parse config/flags and invoke the server composition.
4. Request path for client traffic
- Client requests enter through internal/transport/http.
- handler.go handles incoming HTTP requests, dto.go defines request/response shapes, and utils.go contains transport-level helpers.
- The HTTP layer does not appear to own persistence; it acts as a boundary that translates network input into store operations.
5. Consensus and replication boundary
- internal/store is the core Raft-facing subsystem.
- The README states that requests are first recorded as Raft log entries, then applied to the underlying database.
- This is the main architectural boundary: everything above it is transport/orchestration, everything below it is state mutation and persistence.
6. State machine / database application
- internal/store/fsm.go is the Raft finite-state-machine adapter: it is where committed log entries are applied to the KV engine.
- internal/db holds the actual database abstraction; the README identifies BadgerDB as the backing store.
- So the durable write path is: HTTP request → Raft log entry → FSM apply → BadgerDB mutation.
7. Snapshots and recovery
- internal/store/snapshot.go indicates support for Raft snapshots.
- Architecturally, this is the recovery/compaction path used to bound log growth and restore node state efficiently.
- Snapshots sit alongside the FSM and database as part of the durable state management story.
8. Node lifecycle
- internal/store/node.go and internal/store/store.go suggest a split between Raft node lifecycle/control and higher-level store operations.
- This is likely where membership, proposal handling, and node state are coordinated.
- The README notes clustering/replication support is present, though the current runtime is still effectively single-node.
9. Transport expansion point
- internal/transport/grpc exists as a placeholder for future gRPC support.
- Today the active transport is HTTP; gRPC is an architectural extension point, not the primary path yet.
- This suggests the project is intentionally layered so multiple APIs can front the same store/consensus core.
10. Cross-cutting concerns
- internal/logger provides centralized logging for the daemon and its subsystems.
- docs/raft.md and docs/distributed-kv-db.md are design notes that likely explain the Raft model and distributed database behavior.
- The Makefile and Go module files indicate a standard Go service layout with CLI binaries and internal packages.
11. Net effect for an architecture diagram
- The clearest diagram is: CLI/operator or client → HTTP transport → server orchestration → Raft store/node → FSM → BadgerDB, with snapshots/log replication attached to the Raft/store layer.
- Draw internal/server as the composition boundary, internal/transport/http as the ingress boundary, and internal/store as the consensus/state boundary.
Main entry points: store.go store · handler.go HTTP handler · server.go server · root.go root cmd
Components 16
Commands
Process entrypoints and operator CLI
- hyprd main · Daemon startup and process bootstrap
cmd/hyprd/main.go - root cmd · CLI and flag command composition for the daemon
cmd/hyprd/cmd/root.go - hyprctl · Planned client and operator command-line interface
cmd/hyprctl/main.go
Transport
Network boundaries for client requests
- HTTP handler · Handles HTTP requests and maps them to store operations
internal/transport/http/handler.go - HTTP DTOs · Request and response payload shapes
internal/transport/http/dto.go - HTTP utils · Helpers used by the HTTP boundary
internal/transport/http/utils.go - gRPC · Placeholder for a future gRPC API
internal/transport/grpc/.keep
Orchestration
Wires transports, logging, and storage together
- server · Assembles transports, store, and logging
internal/server/server.go
Consensus & State
Raft, state machine, snapshots, and store coordination
Docs
Design notes and protocol guidance
- Raft notes · Protocol and replication design notes
docs/raft.md - DB notes · Distributed key-value database design notes
docs/distributed-kv-db.md
Other components
- logger · Centralized logging for daemon subsystems
internal/logger/logger.go
Connections 17
- hyprd main → root cmd: starts · Daemon entrypoint delegates to command setup
- root cmd → server: bootstraps · Command wiring constructs and runs the server
- server → HTTP handler: exposes · Server attaches the active HTTP ingress
- server → store: wires · Server composes the Raft-backed store
- server → logger: uses · Server and subsystems share logging
- HTTP handler → HTTP DTOs: marshals · HTTP boundary uses DTOs for request and response shapes
- HTTP handler → HTTP utils: helpers · Request handling relies on transport helpers
- HTTP handler → store: submits · HTTP requests are translated into store operations
- hyprctl → HTTP handler: client of · Operator CLI is expected to talk to running nodes externally
- store → node: controls · Store manages Raft node lifecycle and coordination
- store → FSM: applies via · Committed entries are applied through the FSM
- store → snapshot: recovers via · Snapshots bound log growth and restore node state
- FSM → BadgerDB: mutates · FSM writes committed state into the KV engine
- node → Raft notes: modeled by · Raft behavior is described by the design notes
- store → DB notes: explained by · Distributed DB behavior is documented here
- gRPC → store: future path · Planned gRPC transport would front the same store core
- HTTP handler → gRPC: mirrors · HTTP is the active transport; gRPC is the parallel extension point