Sessionstream Reference

Reference for Sessionstream packages, core types, schema rules, transport semantics, and development commands.

Sections

Terminology & Glossary
📖 Documentation
Navigation
58 sectionsv0.1
📄 Sessionstream Reference — glaze help sessionstream-reference
sessionstream-reference

Sessionstream Reference

Reference for Sessionstream packages, core types, schema rules, transport semantics, and development commands.

Topicsessionstreamreferenceapipackagesprotobuftransportsessionstream-lintsessionstream-systemlab

This reference summarizes the public pieces of the sessionstream repository. Use it when you know the concept and need names, packages, commands, or contracts.

Module

github.com/go-go-golems/sessionstream

Core import path:

import sessionstream "github.com/go-go-golems/sessionstream/pkg/sessionstream"

Embedded documentation import path:

import sessionstreamdoc "github.com/go-go-golems/sessionstream/pkg/doc"

Repository layout

PathPurpose
pkg/sessionstreamCore framework APIs: hub, commands, events, projections, hydration interfaces.
pkg/sessionstream/hydration/sqliteSQLite hydration store implementation.
pkg/sessionstream/transport/wsWebSocket transport adapter.
pkg/sessionstream/pb/proto/sessionstream/v1Generated Go bindings for transport frames.
proto/sessionstream/v1/transport.protoWebSocket transport protobuf schema.
pkg/analysis/sessionstreamschemaGo analyzer that rejects top-level Struct schema registrations.
cmd/sessionstream-lintVettool command for the schema analyzer.
pkg/docEmbedded Glazed help entries for downstream CLIs.
cmd/sessionstream-systemlabBrowser-based lab/reference application.
examples/chatdemoSmall runnable chat-style example.
ttmpDesign docs, tickets, and implementation diaries.

Core types

Hub

The Hub is the command/event/projection coordinator.

Important functions and options:

func NewHub(opts ...HubOption) (*Hub, error)
func WithSchemaRegistry(r *SchemaRegistry) HubOption
func WithHydrationStore(s HydrationStore) HubOption
func WithUIFanout(f UIFanout) HubOption
func WithProjectionPolicies(p ProjectionPolicies) HubOption

func (h *Hub) RegisterCommand(name string, handler CommandHandler) error
func (h *Hub) RegisterUIProjection(p UIProjection) error
func (h *Hub) RegisterTimelineProjection(p TimelineProjection) error
func (h *Hub) Submit(ctx context.Context, sid SessionId, name string, payload proto.Message) error
func (h *Hub) Snapshot(ctx context.Context, sid SessionId) (Snapshot, error)

CommandHandler

type CommandHandler func(
    ctx context.Context,
    cmd Command,
    sess *Session,
    pub EventPublisher,
) error

Handlers publish backend events through EventPublisher. They should not return UI state directly.

EventPublisher

type EventPublisher interface {
    Publish(ctx context.Context, ev Event) error
}

The publisher validates event payload types, assigns ordinals, applies projections, stores timeline state, and fans out UI events according to hub configuration.

Event

type Event struct {
    Name      string
    Payload   proto.Message
    SessionId SessionId
    Ordinal   uint64
}

Backend events are canonical records. Projections derive other views from them.

UIEvent

type UIEvent struct {
    Name    string
    Payload proto.Message
}

UI events are live client-facing projected events.

TimelineEntity

type TimelineEntity struct {
    Kind             string
    Id               string
    CreatedOrdinal   uint64
    LastEventOrdinal uint64
    Payload          proto.Message
    Tombstone        bool
}

Timeline entities are durable projected state. Hydration stores use them to build snapshots.

TimelineView

type TimelineView interface {
    Get(kind, id string) (TimelineEntity, bool)
    List(kind string) []TimelineEntity
    Ordinal() uint64
}

Projections receive a read-only timeline view so they can update existing entities instead of blindly replacing state.

Schema registry

func NewSchemaRegistry() *SchemaRegistry
func (r *SchemaRegistry) RegisterCommand(name string, msg proto.Message) error
func (r *SchemaRegistry) RegisterEvent(name string, msg proto.Message) error
func (r *SchemaRegistry) RegisterUIEvent(name string, msg proto.Message) error
func (r *SchemaRegistry) RegisterTimelineEntity(kind string, msg proto.Message) error

Rules:

  • Names must be stable logical names.
  • Payload prototypes must be concrete protobuf messages.
  • Do not use top-level *structpb.Struct registrations.
  • Nested google.protobuf.Struct fields are allowed when intentionally scoped inside a concrete message.

Projection interfaces

type UIProjection interface {
    Project(ctx context.Context, ev Event, sess *Session, view TimelineView) ([]UIEvent, error)
}

type TimelineProjection interface {
    Project(ctx context.Context, ev Event, sess *Session, view TimelineView) ([]TimelineEntity, error)
}

Function adapters are available:

sessionstream.UIProjectionFunc(func(ctx context.Context, ev sessionstream.Event, sess *sessionstream.Session, view sessionstream.TimelineView) ([]sessionstream.UIEvent, error) {
    return nil, nil
})

sessionstream.TimelineProjectionFunc(func(ctx context.Context, ev sessionstream.Event, sess *sessionstream.Session, view sessionstream.TimelineView) ([]sessionstream.TimelineEntity, error) {
    return nil, nil
})

WebSocket transport

Transport schemas live in:

proto/sessionstream/v1/transport.proto

Important frame types:

FrameDirectionPurpose
ClientFrame.subscribeclient -> serverSubscribe to a session.
ClientFrame.unsubscribeclient -> serverStop receiving a session.
ClientFrame.pingclient -> serverKeepalive.
ServerFrame.helloserver -> clientConnection greeting.
ServerFrame.snapshotserver -> clientCurrent hydrated timeline state.
ServerFrame.uiEventserver -> clientLive UI event derived from a backend event.
ServerFrame.errorserver -> clientTransport or subscription error.

Payloads are encoded as protobuf JSON. Snapshot and UI payloads use google.protobuf.Any; clients need matching application schema knowledge to unpack or interpret them.

Ordinal semantics

FieldMeaning
Backend event OrdinalOrder assigned to a canonical backend event.
Snapshot.snapshotOrdinalHighest timeline ordinal represented by the snapshot.
SnapshotEntity.createdOrdinalOrdinal that created the entity.
SnapshotEntity.lastEventOrdinalLatest event ordinal that updated the entity.
UiEventFrame.eventOrdinalBackend event ordinal that produced the live UI event.

Protojson renders uint64 values as strings. Browser code should not force them through JavaScript number if precision matters.

Commands

sessionstream-lint

Build the schema vettool:

go build -o /tmp/sessionstream-lint ./cmd/sessionstream-lint

Run it through go vet:

go vet -vettool=/tmp/sessionstream-lint ./pkg/analysis/sessionstreamschema ./cmd/sessionstream-lint

Downstream workspace usage:

go build -o /tmp/sessionstream-lint ../sessionstream/cmd/sessionstream-lint
go vet -vettool=/tmp/sessionstream-lint ./cmd/... ./pkg/...

sessionstream-systemlab

Run the browser-based lab app:

make systemlab-run
# or directly:
go run ./cmd/sessionstream-systemlab serve --addr :8091

Browse embedded CLI help entries:

go run ./cmd/sessionstream-systemlab help sessionstream-user-guide
go run ./cmd/sessionstream-systemlab help sessionstream-reference

Default URL:

http://localhost:8091/

Embedded help docs are served by Systemlab under:

http://localhost:8091/docs/

Development commands

make test
make build
make lint
make schema-vet
make systemlab-build
make systemlab-run
make boundary-check

Most repository Makefile targets use GOWORK=off so the module is tested as an external consumer would see it.

Embedded docs package

Downstream CLIs can load Sessionstream help entries into a Glazed help system:

helpSystem := help.NewHelpSystem()
if err := sessionstreamdoc.AddDocToHelpSystem(helpSystem); err != nil {
    return err
}

The package also exposes the embedded filesystem:

docsFS := sessionstreamdoc.FS()

See Also

  • sessionstream-user-guide for the architecture narrative.
  • sessionstream-getting-started for a first app walkthrough.
  • sessionstream-schema-vet-playbook for vettool operation.
  • examples/chatdemo/chat.go for runnable application code.
  • proto/sessionstream/v1/transport.proto for websocket schema details.