# andrearcaina/hyperion architecture

> Architecture diagram of the GitHub repository andrearcaina/hyperion, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andrearcaina/hyperion
- Repository: https://github.com/andrearcaina/hyperion
- Video tour (about a minute): https://gitdiagram.com/andrearcaina/hyperion/video

## Overview

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: [`internal/store/store.go`](https://github.com/andrearcaina/hyperion/blob/main/internal/store/store.go) (store), [`internal/transport/http/handler.go`](https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/handler.go) (HTTP handler), [`internal/server/server.go`](https://github.com/andrearcaina/hyperion/blob/main/internal/server/server.go) (server), [`cmd/hyprd/cmd/root.go`](https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprd/cmd/root.go) (root cmd)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_cmd["Commands"]
  node_cmd_hyprd_main["hyprd main<br/>entrypoint<br/>[main.go]"]
  node_cmd_hyprd_root["root cmd<br/>cli wiring<br/>[root.go]"]
  node_cmd_hyprctl_main["hyprctl<br/>operator cli<br/>[main.go]"]
end

subgraph group_group_transport["Transport"]
  node_http_handler["HTTP handler<br/>transport ingress<br/>[handler.go]"]
  node_http_dto["HTTP DTOs<br/>api schema<br/>[dto.go]"]
  node_http_utils["HTTP utils<br/>transport helpers<br/>[utils.go]"]
  node_grpc_placeholder["gRPC<br/>future transport<br/>[.keep]"]
end

subgraph group_group_server["Orchestration"]
  node_server["server<br/>composition<br/>[server.go]"]
end

subgraph group_group_store["Consensus & State"]
  node_store["store<br/>[store.go]"]
  node_node["node<br/>[node.go]"]
  node_fsm["FSM<br/>raft apply<br/>[fsm.go]"]
  node_snapshot["snapshot<br/>recovery<br/>[snapshot.go]"]
end

subgraph group_group_db["Persistence"]
  node_db[("BadgerDB<br/>kv engine<br/>[db.go]")]
end

subgraph group_group_docs["Docs"]
  node_raft_docs["Raft notes<br/>design doc<br/>[raft.md]"]
  node_kv_docs["DB notes<br/>design doc"]
end

node_logger["logger<br/>cross-cutting<br/>[logger.go]"]

node_cmd_hyprd_main -->|"starts"| node_cmd_hyprd_root
node_cmd_hyprd_root -->|"bootstraps"| node_server
node_server -->|"exposes"| node_http_handler
node_server -->|"wires"| node_store
node_server -->|"uses"| node_logger
node_http_handler -->|"marshals"| node_http_dto
node_http_handler -->|"helpers"| node_http_utils
node_http_handler -->|"submits"| node_store
node_cmd_hyprctl_main -.->|"client of"| node_http_handler
node_store -->|"controls"| node_node
node_store -->|"applies via"| node_fsm
node_store -->|"recovers via"| node_snapshot
node_fsm -->|"mutates"| node_db
node_node -.->|"modeled by"| node_raft_docs
node_store -.->|"explained by"| node_kv_docs
node_grpc_placeholder -.->|"future path"| node_store
node_http_handler -.->|"mirrors"| node_grpc_placeholder

click node_cmd_hyprd_main "https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprd/main.go"
click node_cmd_hyprd_root "https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprd/cmd/root.go"
click node_cmd_hyprctl_main "https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprctl/main.go"
click node_server "https://github.com/andrearcaina/hyperion/blob/main/internal/server/server.go"
click node_http_handler "https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/handler.go"
click node_http_dto "https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/dto.go"
click node_http_utils "https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/utils.go"
click node_grpc_placeholder "https://github.com/andrearcaina/hyperion/blob/main/internal/transport/grpc/.keep"
click node_store "https://github.com/andrearcaina/hyperion/blob/main/internal/store/store.go"
click node_node "https://github.com/andrearcaina/hyperion/blob/main/internal/store/node.go"
click node_fsm "https://github.com/andrearcaina/hyperion/blob/main/internal/store/fsm.go"
click node_snapshot "https://github.com/andrearcaina/hyperion/blob/main/internal/store/snapshot.go"
click node_db "https://github.com/andrearcaina/hyperion/blob/main/internal/db/db.go"
click node_logger "https://github.com/andrearcaina/hyperion/blob/main/internal/logger/logger.go"
click node_raft_docs "https://github.com/andrearcaina/hyperion/blob/main/docs/raft.md"
click node_kv_docs "https://github.com/andrearcaina/hyperion/blob/main/docs/distributed-kv-db.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cmd_hyprd_main,node_cmd_hyprd_root,node_cmd_hyprctl_main toneBlue
class node_http_handler,node_http_dto,node_http_utils,node_grpc_placeholder toneAmber
class node_server toneMint
class node_store,node_node,node_fsm,node_snapshot toneRose
class node_db toneIndigo
class node_raft_docs,node_kv_docs toneTeal
class node_logger toneNeutral
```

## Components

### Commands

Process entrypoints and operator CLI

- [hyprd main](https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprd/main.go): entrypoint · Daemon startup and process bootstrap · `cmd/hyprd/main.go`
- [root cmd](https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprd/cmd/root.go): cli wiring · CLI and flag command composition for the daemon · `cmd/hyprd/cmd/root.go`
- [hyprctl](https://github.com/andrearcaina/hyperion/blob/main/cmd/hyprctl/main.go): operator cli · Planned client and operator command-line interface · `cmd/hyprctl/main.go`

### Transport

Network boundaries for client requests

- [HTTP handler](https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/handler.go): transport ingress · Handles HTTP requests and maps them to store operations · `internal/transport/http/handler.go`
- [HTTP DTOs](https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/dto.go): api schema · Request and response payload shapes · `internal/transport/http/dto.go`
- [HTTP utils](https://github.com/andrearcaina/hyperion/blob/main/internal/transport/http/utils.go): transport helpers · Helpers used by the HTTP boundary · `internal/transport/http/utils.go`
- [gRPC](https://github.com/andrearcaina/hyperion/blob/main/internal/transport/grpc/.keep): future transport · Placeholder for a future gRPC API · `internal/transport/grpc/.keep`

### Orchestration

Wires transports, logging, and storage together

- [server](https://github.com/andrearcaina/hyperion/blob/main/internal/server/server.go): composition · Assembles transports, store, and logging · `internal/server/server.go`

### Consensus & State

Raft, state machine, snapshots, and store coordination

- [store](https://github.com/andrearcaina/hyperion/blob/main/internal/store/store.go): raft store · Main Raft-facing coordination and request path · `internal/store/store.go`
- [node](https://github.com/andrearcaina/hyperion/blob/main/internal/store/node.go): raft node · Raft node lifecycle and control · `internal/store/node.go`
- [FSM](https://github.com/andrearcaina/hyperion/blob/main/internal/store/fsm.go): raft apply · Applies committed log entries to state · `internal/store/fsm.go`
- [snapshot](https://github.com/andrearcaina/hyperion/blob/main/internal/store/snapshot.go): recovery · Snapshotting and restore support · `internal/store/snapshot.go`

### Persistence

Durable key-value backend

- [BadgerDB](https://github.com/andrearcaina/hyperion/blob/main/internal/db/db.go): kv engine · Durable key-value storage backend · `internal/db/db.go`

### Docs

Design notes and protocol guidance

- [Raft notes](https://github.com/andrearcaina/hyperion/blob/main/docs/raft.md): design doc · Protocol and replication design notes · `docs/raft.md`
- [DB notes](https://github.com/andrearcaina/hyperion/blob/main/docs/distributed-kv-db.md): design doc · Distributed key-value database design notes · `docs/distributed-kv-db.md`

### Other components

- [logger](https://github.com/andrearcaina/hyperion/blob/main/internal/logger/logger.go): cross-cutting · Centralized logging for daemon subsystems · `internal/logger/logger.go`

## Connections

- 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
