# sng2c/rpipe architecture

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

- Interactive diagram: https://gitdiagram.com/sng2c/rpipe
- Repository: https://github.com/sng2c/rpipe

## Overview

rpipe is a Go CLI that bridges local streams or a child process to Redis pub/sub, with pipe-transfer and chat modes and optional end-to-end encryption. The main workflow is local input → message preparation and encryption → Redis publication; incoming Redis messages are handled by the runtime, decrypted when secured, and delivered to local output or a child’s stdin. The README documents the overall bridge and key negotiation; the excerpts show the runtime and helpers, but omit parts of the main loop, so some internal receive-path links are not asserted.

Main entry points: [`rpipe.go`](https://github.com/sng2c/rpipe/blob/main/rpipe.go) (Rpipe runtime), [`secure/cryptor.go`](https://github.com/sng2c/rpipe/blob/main/secure/cryptor.go) (Key management), [`pipe/spawn.go`](https://github.com/sng2c/rpipe/blob/main/pipe/spawn.go) (Child process adapter), [`msgspec/msg.go`](https://github.com/sng2c/rpipe/blob/main/msgspec/msg.go) (Wire envelope)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bridge runtime"]
  node_runtime["Rpipe runtime<br/>[rpipe.go]"]
end

subgraph group_protocol["Message protocol"]
  node_appmsg["Chat framing<br/>[msg.go]"]
  node_wiremsg["Wire envelope<br/>[msg.go]"]
end

subgraph group_security["Encryption"]
  node_cryptor["Key management<br/>[cryptor.go]"]
  node_cipher["Payload cipher<br/>[cryptor.go]"]
end

subgraph group_io["Local I/O"]
  node_streambuf["Stream framing<br/>[bufutil.go]"]
  node_spawn["Child process adapter<br/>[spawn.go]"]
end

node_user(("CLI user"))
node_localio["Local streams"]
node_child["Child command"]
node_redis[("Redis pub/sub")]

node_user -->|"configures and starts"| node_runtime
node_runtime -->|"reads and writes"| node_streambuf
node_runtime -->|"spawns command"| node_spawn
node_spawn -->|"runs command"| node_child
node_runtime -->|"reads and writes"| node_localio
node_runtime -->|"parses and encodes"| node_appmsg
node_runtime -->|"publishes messages"| node_wiremsg
node_runtime -->|"manages keys"| node_cryptor
node_runtime -->|"encrypts and decrypts"| node_cipher
node_cryptor -->|"builds reset messages"| node_wiremsg
node_cryptor -->|"stores and fetches keys"| node_redis
node_runtime -->|"publishes and subscribes"| node_redis

click node_runtime "https://github.com/sng2c/rpipe/blob/main/rpipe.go"
click node_appmsg "https://github.com/sng2c/rpipe/blob/main/msgspec/msg.go"
click node_wiremsg "https://github.com/sng2c/rpipe/blob/main/msgspec/msg.go"
click node_cryptor "https://github.com/sng2c/rpipe/blob/main/secure/cryptor.go"
click node_cipher "https://github.com/sng2c/rpipe/blob/main/secure/cryptor.go"
click node_streambuf "https://github.com/sng2c/rpipe/blob/main/pipe/bufutil.go"
click node_spawn "https://github.com/sng2c/rpipe/blob/main/pipe/spawn.go"

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_runtime,node_user toneBlue
class node_appmsg,node_wiremsg,node_redis toneAmber
class node_cryptor,node_cipher toneMint
class node_streambuf,node_spawn toneRose
class node_localio,node_child toneIndigo
```

## Components

### Bridge runtime

- [Rpipe runtime](https://github.com/sng2c/rpipe/blob/main/rpipe.go): `rpipe.go`

### Message protocol

- [Chat framing](https://github.com/sng2c/rpipe/blob/main/msgspec/msg.go): `msgspec/msg.go`
- [Wire envelope](https://github.com/sng2c/rpipe/blob/main/msgspec/msg.go): `msgspec/msg.go`

### Encryption

- [Key management](https://github.com/sng2c/rpipe/blob/main/secure/cryptor.go): `secure/cryptor.go`
- [Payload cipher](https://github.com/sng2c/rpipe/blob/main/secure/cryptor.go): `secure/cryptor.go`

### Local I/O

- [Stream framing](https://github.com/sng2c/rpipe/blob/main/pipe/bufutil.go): `pipe/bufutil.go`
- [Child process adapter](https://github.com/sng2c/rpipe/blob/main/pipe/spawn.go): `pipe/spawn.go`

### Other components

- **CLI user**
- **Local streams**
- **Child command**
- **Redis pub/sub**

## Connections

- CLI user → Rpipe runtime: configures and starts (evidence: `README.md`)
- Rpipe runtime → Stream framing: reads and writes (evidence: `rpipe.go`)
- Rpipe runtime → Child process adapter: spawns command (evidence: `rpipe.go`)
- Child process adapter → Child command: runs command (evidence: `pipe/spawn.go`)
- Rpipe runtime → Local streams: reads and writes (evidence: `rpipe.go`)
- Rpipe runtime → Chat framing: parses and encodes (evidence: `rpipe.go`)
- Rpipe runtime → Wire envelope: publishes messages (evidence: `rpipe.go`)
- Rpipe runtime → Key management: manages keys (evidence: `rpipe.go`)
- Rpipe runtime → Payload cipher: encrypts and decrypts (evidence: `rpipe.go`)
- Key management → Wire envelope: builds reset messages (evidence: `secure/cryptor.go`)
- Key management → Redis pub/sub: stores and fetches keys (evidence: `secure/cryptor.go`)
- Rpipe runtime → Redis pub/sub: publishes and subscribes (evidence: `README.md`)
