vihren

module
v0.0.0-...-afad831 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: Apache-2.0

README

Vihren

Go Reference License

Vihren is a Go toolkit for building typed Temporal workflows with less boilerplate. You write ordinary Go activities and workflows, mark them with //vihren:activity and //vihren:workflow, and run vihren-gen to generate Temporal registration, workflow-side activity proxies, and typed workflow clients.

The v0.1 release focuses on one concrete path:

  • typed workflow and activity code generation;
  • a small runnable codegenhello example;
  • an embedded Temporal runtime for local demos and single-process development.

Install

Requires Go 1.26 or newer.

go get github.com/vihren-dev/vihren
go install github.com/vihren-dev/vihren/cmd/vihren-gen@latest

The Smallest Example

Write an activity and a workflow:

package codegenhello

import (
	"context"
	"fmt"
	"time"

	"go.temporal.io/sdk/workflow"
)

//go:generate vihren-gen ./...

const DefaultTaskQueue = "vihren-codegenhello"

type GreetingActivities struct {
	Prefix string
}

type GreetingInput struct {
	Name string
}

type GreetingOutput struct {
	Message string
}

// ComposeGreeting builds a greeting.
//
//vihren:activity
func (activities *GreetingActivities) ComposeGreeting(ctx context.Context, in GreetingInput) (GreetingOutput, error) {
	_ = ctx
	return GreetingOutput{Message: fmt.Sprintf("%s, %s", activities.Prefix, in.Name)}, nil
}

// HelloWorkflow calls the activity through the generated type-safe proxy.
//
//vihren:workflow
func HelloWorkflow(ctx workflow.Context, in GreetingInput) (GreetingOutput, error) {
	ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{StartToCloseTimeout: time.Second})
	return Activity.ComposeGreeting(ctx, in)
}

Run generation:

go generate ./...

The generated file contains:

  • Register, which registers the workflow and activity on a Temporal worker;
  • Activity, a workflow-safe activity proxy with compile-time checked arguments and result types;
  • NewClient, a typed workflow client for starting and awaiting workflows.

In this example the 53-line workflow.go you write generates 84 lines of registration, proxy, and client code you never hand-write or hand-maintain.

Run The Example

From this repository, run the self-contained example directly:

go run ./examples/codegenhello/cmd/codegenhello-embedded

It starts Temporal inside the process, starts a worker, runs the generated typed workflow client, and prints:

Hello, Ada

No Docker, daemon, or separate Temporal development server is required.

If you use just, the same command is available as:

just run-codegenhello-embedded

To verify generated code and tests from a checkout:

go generate ./examples/codegenhello
go test ./examples/codegenhello ./examples/codegenhello/cmd/codegenhello-embedded -timeout 60s

Embedded Temporal

platform/embeddedtemporal runs a Temporal server inside the current process. It is useful for examples, demos, and single-binary local development. It is not a production Temporal deployment.

server, err := embeddedtemporal.Start()
if err != nil {
	return err
}
defer server.Close()

See docs/embedded-temporal.md and examples/codegenhello.

License

Vihren is licensed under the Apache License, Version 2.0. See the NOTICE file for attribution.

Directories

Path Synopsis
cmd
vihren-gen command
examples
codegenhello
Package codegenhello is the minimal vihren-gen example: a developer writes one activity and one workflow, and the generator supplies all Temporal registration and typed-call plumbing (see vihren.gen.go).
Package codegenhello is the minimal vihren-gen example: a developer writes one activity and one workflow, and the generator supplies all Temporal registration and typed-call plumbing (see vihren.gen.go).
codegenhello/cmd/codegenhello-embedded command
Command codegenhello-embedded runs the whole codegenhello example in a single process: it starts an embedded Temporal server, hosts a worker for the generated activity and workflow, and starts the workflow through the generated typed client — no Docker, no daemon, no `just temporal-start`.
Command codegenhello-embedded runs the whole codegenhello example in a single process: it starts an embedded Temporal server, hosts a worker for the generated activity and workflow, and starts the workflow through the generated typed client — no Docker, no daemon, no `just temporal-start`.
codegenhello/cmd/codegenhello-start command
Command codegenhello-start starts HelloWorkflow through the generated typed client and prints the result.
Command codegenhello-start starts HelloWorkflow through the generated typed client and prints the result.
codegenhello/cmd/codegenhello-worker command
Command codegenhello-worker runs a Temporal worker for the codegenhello example.
Command codegenhello-worker runs a Temporal worker for the codegenhello example.
internal
codegen
Package codegen discovers vihren activity/workflow markers and generates typed Temporal registration and call surfaces from the ADR 20260619 contract.
Package codegen discovers vihren activity/workflow markers and generates typed Temporal registration and call surfaces from the ADR 20260619 contract.
toolschema
Package toolschema generates checked-in JSON Schema Go artifacts for tool input and output structs.
Package toolschema generates checked-in JSON Schema Go artifacts for tool input and output structs.
platform
blobref
Package blobref models activity input and output values that may cross Temporal workflow history, where large payloads would otherwise bloat the event history and threaten replay cost and durability.
Package blobref models activity input and output values that may cross Temporal workflow history, where large payloads would otherwise bloat the event history and threaten replay cost and durability.
embeddedtemporal
Package embeddedtemporal runs a Temporal server inside the current process so a single Go binary can host durable workflows with no external infrastructure.
Package embeddedtemporal runs a Temporal server inside the current process so a single Go binary can host durable workflows with no external infrastructure.
toolcontract
Package toolcontract owns logical tool contracts and shared tool-call result types used by tool catalogs and provider adapters.
Package toolcontract owns logical tool contracts and shared tool-call result types used by tool catalogs and provider adapters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL