Skip to content

SDK Installation

The TinySystems SDK provides everything you need to build custom modules and components.

Installation

Create a New Module

bash
# Create project directory
mkdir my-module && cd my-module

# Initialize Go module
go mod init github.com/myorg/my-module

# Install the SDK
go get github.com/tiny-systems/module@latest

Verify Installation

bash
go list -m github.com/tiny-systems/module
# github.com/tiny-systems/module v0.1.x

SDK Package Overview

The SDK is organized into several packages:

PackageImport PathPurpose
modulegithub.com/tiny-systems/module/moduleCore interfaces (Component, Port, Handler)
registrygithub.com/tiny-systems/module/registryComponent registration
cligithub.com/tiny-systems/module/cliCLI commands (run, build, tools)
v1alpha1github.com/tiny-systems/module/api/v1alpha1CRD types (TinyNode, TinyModule)
resourcegithub.com/tiny-systems/module/pkg/resourceKubernetes resource manager
evaluatorgithub.com/tiny-systems/module/pkg/evaluatorExpression evaluation
schemagithub.com/tiny-systems/module/pkg/schemaJSON Schema generation
errorsgithub.com/tiny-systems/module/pkg/errorsError handling utilities

Core Interfaces

Component Interface

The main interface you'll implement:

go
import "github.com/tiny-systems/module/module"

type Component interface {
    // Returns component metadata (name, description, tags)
    GetInfo() ComponentInfo

    // Processes incoming messages on ports
    Handle(ctx context.Context, output Handler, port string, message any) any

    // Defines input and output ports
    Ports() []Port

    // Factory method to create new instances
    Instance() Component
}

Handler Function

The callback for sending output:

go
type Handler func(ctx context.Context, port string, data any) any

Port Definition

Define component ports:

go
type Port struct {
    Name          string      // Unique identifier
    Label         string      // Display name in UI
    Position      Position    // Left, Right, Top, Bottom
    Source        bool        // true = output port
    Configuration interface{} // Schema definition struct
}

Minimal Example

Here's a complete minimal module:

go
// cmd/main.go
package main

import (
    "context"

    "github.com/tiny-systems/module/cli"
    "github.com/tiny-systems/module/module"
    "github.com/tiny-systems/module/registry"
)

// Component implementation
type Echo struct{}

func (e *Echo) GetInfo() module.ComponentInfo {
    return module.ComponentInfo{
        Name:        "echo",
        Description: "Echoes input to output",
    }
}

func (e *Echo) Handle(ctx context.Context, output module.Handler, port string, msg any) any {
    return output(ctx, "output", msg)
}

func (e *Echo) Ports() []module.Port {
    return []module.Port{
        {Name: "input", Label: "Input", Position: module.Left},
        {Name: "output", Label: "Output", Position: module.Right, Source: true},
    }
}

func (e *Echo) Instance() module.Component {
    return &Echo{}
}

func init() {
    registry.Register(&Echo{})
}

func main() {
    cli.Run()
}

Running Your Module

Local Development

bash
# Build the module
go build -o my-module ./cmd

# Run locally (connects to current kubectl context)
./my-module run \
    --name=my-module \
    --version=1.0.0 \
    --namespace=default

With Environment Variables

bash
# Enable OpenTelemetry tracing
OTLP_DSN=http://localhost:4317 ./my-module run \
    --name=my-module \
    --version=1.0.0 \
    --namespace=default

Available CLI Commands

The SDK includes a CLI with these commands:

bash
# Run the module operator
./my-module run --help

# Build and publish
./my-module tools build --help

# Show component info
./my-module tools info

See CLI Reference for details.

Dependencies

The SDK brings in these key dependencies:

go
require (
    // Kubernetes
    sigs.k8s.io/controller-runtime
    k8s.io/client-go
    k8s.io/apimachinery

    // gRPC (cross-module communication)
    google.golang.org/grpc

    // OpenTelemetry (observability)
    go.opentelemetry.io/otel

    // Expression evaluation
    github.com/spyzhov/ajson
)

Next Steps

Build flow-based applications on Kubernetes