Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Registry (reg)

A lightweight, IoT-focused service for managing named registers with dynamic values and automatic lifecycle management.

Overview

A register is a named container that holds a current value, optional metadata, and a time-to-live (TTL). Think of it like a variable in memory that automatically expires if not refreshed. Each register has:

  • Name - Unique identifier (e.g., "living-room-temperature")
  • Value - Current data (any JSON type: number, string, object, array)
  • Metadata - Optional key-value pairs with additional information
  • TTL - How long the register stays valid without refresh

Registry provides a simplified Provider/Consumer model where:

  • Providers publish registers and keep them alive by refreshing before TTL expires
  • Consumers read register values and can request changes
  • Automatic cleanup removes expired registers when TTL elapses

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Provider   β”‚                    β”‚  Consumer   β”‚
β”‚  (Sensor)   β”‚                    β”‚ (Controller)β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                  β”‚
       β”‚ PUT /provider                    β”‚ GET /consumer
       β”‚ (set value)                      β”‚ (read value)
       β”‚                                  β”‚
       └──────────┐          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚          β”‚
                  v          v
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚   Registry Server   β”‚
            β”‚                     β”‚
            β”‚  - In-memory store  β”‚
            β”‚  - TTL management   β”‚
            β”‚  - Change requests  β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  ^          β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          └────────────┐
       β”‚                                  β”‚
       β”‚ GET /provider                    β”‚ PUT /consumer
       β”‚ (poll for changes)               β”‚ (request change)
       β”‚                                  β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
β”‚  Provider   β”‚                    β”‚  Consumer   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Installation

go install github.com/burgrp/reg@latest

Or build from source:

git clone https://github.com/burgrp/reg.git
cd reg
go build -o reg

Running the Server

# Start server on default port (8080)
./reg serve

# Start server on custom port
./reg serve --rest :9000

Using the CLI

Provide a Register

# Set environment variable
export REGISTRY=http://localhost:8080

# Provide a temperature register with initial value
./reg provide temperature 22.5

# Provide with metadata
./reg provide temperature 22.5 '{"unit":"celsius","location":"room1"}'

# Provide with custom TTL (default is 5 seconds)
./reg provide temperature 22.5 '{"unit":"celsius"}' --ttl 10s

Consume a Register

# Read current value
./reg get temperature

# List all registers
./reg list

# Interactive browsing (TUI)
./reg browse

MCP Server (Model Context Protocol)

# Start MCP stdio server for AI assistant integration
export REGISTRY=http://localhost:8080
./reg mcp

# The MCP server exposes tools for AI assistants:
# - get_register: Get register value and metadata
# - list_registers: List all registers
# - request_change: Request value change (consumer operation)

Use with MCP clients like Claude Desktop, Cline, or other MCP-compatible tools.

Using the API

Provide a Register (Provider)

curl -X PUT http://localhost:8080/provider \
  -H "Content-Type: application/json" \
  -d '{
    "registers": {
      "temperature": {
        "value": 22.5,
        "metadata": {"unit": "celsius"},
        "ttl": "10s"
      }
    }
  }'

Read a Register (Consumer)

curl http://localhost:8080/consumer?name=temperature

Request a Change (Consumer)

curl -X PUT http://localhost:8080/consumer \
  -H "Content-Type: application/json" \
  -d '{
    "registers": {
      "temperature": {
        "value": 25.0
      }
    }
  }'

Documentation

Core Concepts

API Reference

Client Libraries

Development

Features

  • Protocol-agnostic core - Clean separation between business logic and transport
  • REST API - Simple HTTP interface with JSON
  • MCP Server - Model Context Protocol stdio server for AI assistant integration
  • Long polling - Efficient real-time updates without WebSockets
  • Automatic TTL management - Registers expire automatically if not refreshed
  • Change requests - Consumers can request value changes from providers
  • Batched operations - Client library batches multiple subscriptions efficiently
  • Graceful shutdown - Clean shutdown with signal handling
  • No dependencies - Minimal external dependencies, easy to deploy

Use Cases

  • IoT device management - Sensors publish values, controllers consume and request changes
  • Configuration management - Dynamic configuration with TTL-based expiration
  • Distributed state - Lightweight state sharing between services
  • Command and control - Send commands to devices via change requests

License

MIT License - see LICENSE file for details

Version

Run ./reg version to see the current version.

About

A lightweight, IoT-focused service for managing named registers

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages