compose

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package compose defines SystemForge's composition runtime: the Feature and Registrar contracts that let capabilities — a single feature slice or a whole application — be composed into one binary or split across services without changing the capabilities themselves.

A Feature registers its HTTP routes through a Registrar and participates in a Start/Stop lifecycle. An App (see app.go) aggregates Features and is itself a Feature, which makes composition recursive: a host registers a whole application the same way an application registers one of its own features.

See docs/architecture/systemforge-application-architecture.md for the conventions this package implements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App composes Features into one unit. App is itself a Feature, so an application can be embedded into a larger host composition — this is what makes SystemForge composition recursive.

An App is built during startup (before serving) and is not safe for concurrent modification.

func NewApp

func NewApp(name string, features ...Feature) *App

NewApp creates an App with the given canonical name and initial features.

func (*App) Features

func (a *App) Features() []Feature

Features returns the registered features in registration order.

func (*App) Name

func (a *App) Name() string

Name returns the application's canonical name.

func (*App) Register

func (a *App) Register(features ...Feature)

Register appends features to the App, in order.

func (*App) RegisterRoutes

func (a *App) RegisterRoutes(r Registrar) error

RegisterRoutes registers every feature's routes in registration order, stopping at the first error.

func (*App) Start

func (a *App) Start(ctx context.Context) error

Start starts features in registration order. If a feature fails to start, already-started features are stopped in reverse order and the error is returned, so a failed Start leaves nothing running.

func (*App) Stop

func (a *App) Stop(ctx context.Context) error

Stop stops features in reverse registration order, accumulating any errors so one feature's failure does not prevent the others from stopping.

type Base

type Base struct{}

Base can be embedded in a Feature to satisfy the lifecycle methods with no-ops, so small features only implement Name and RegisterRoutes.

func (Base) Start

func (Base) Start(context.Context) error

Start is a no-op.

func (Base) Stop

func (Base) Stop(context.Context) error

Stop is a no-op.

type Feature

type Feature interface {
	// Name returns the capability's canonical slug (see the application
	// architecture guide). It must be stable and unique within a composition.
	Name() string

	// RegisterRoutes registers the capability's HTTP routes via the Registrar.
	RegisterRoutes(r Registrar) error

	// Start performs startup work (warming caches, opening consumers, etc.).
	// It may be a no-op.
	Start(ctx context.Context) error

	// Stop releases resources acquired in Start. It may be a no-op.
	Stop(ctx context.Context) error
}

Feature is one registrable capability: a feature slice or a whole app.

Implementations that have no startup/shutdown work can embed Base to get no-op Start/Stop and only implement Name and RegisterRoutes.

type Registrar

type Registrar interface {
	// HumaAPI returns the Huma API for typed operation registration.
	HumaAPI() huma.API
	// Mux returns the underlying chi router for not-yet-migrated handlers.
	Mux() chi.Router
}

Registrar is the registration surface a Feature receives. It abstracts the HTTP layer so a feature registers routes without constructing the server.

SystemForge is mid-migration from chi handlers to Huma operations, so the Registrar exposes both: HumaAPI for typed operation registration (the forward direction) and Mux for chi handlers not yet migrated. A feature should prefer HumaAPI for new endpoints.

func NewRegistrar

func NewRegistrar(api huma.API, mux chi.Router) Registrar

NewRegistrar returns a Registrar backed by a Huma API and a chi router. Either may be nil if a composition only uses one HTTP style, but a feature that calls the corresponding accessor will then receive nil.

Jump to

Keyboard shortcuts

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