appcontract

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package appcontract projects a stable, machine-readable description of a Gombit application — the HOST-1 application contract (ADR-015). A deployment host (e.g. Gombit Cloud) reads it to learn how to build, health-check, and migrate an ordinary handwritten Gombit app without inferring anything from repository trivia.

Every field is projected from the app's *declared* configuration (typed config.Config / gombit.yaml, the resolved framework version, documented defaults) — never guessed by walking the source tree (build plan §10, 6.2). The contract is versioned by ContractVersion, independent of the framework version, so a host can fail loudly on an unknown shape (DESIGN.md §53, §55).

Index

Constants

View Source
const (
	LivenessPath  = "/livez"
	ReadinessPath = "/readyz"
)

Health probe paths are the stable operational contract from HOST-2 (ADR-015, docs/health.md). They are fixed so a host can rely on them.

View Source
const (
	DefaultBuildCommand  = "gombit build --embed"
	DefaultBuildArtifact = "bin/server"
	// DefaultMigrationsPath mirrors migrations.defaultMigrationDir.
	DefaultMigrationsPath = "database/migrations"
)

Documented build defaults (build plan M5-5; build.DefaultOut = "bin/server").

View Source
const ContractVersion = 1

ContractVersion is the schema version of the emitted contract. It is independent of the framework version; bump it only on a breaking shape change, and document the change.

View Source
const FrameworkModulePath = frameworkmod.ModulePath

FrameworkModulePath is the module a Gombit application requires.

View Source
const FrameworkName = "gombit"

FrameworkName is the framework a Gombit application contract describes.

Variables

View Source
var ErrFrameworkVersionUnresolved = errors.New("appcontract: framework version is unresolved (replaced by a local path or another module)")

ErrFrameworkVersionUnresolved is returned when go.mod names the framework but no framework release: it is replaced by a local filesystem path (a framework dev checkout, the common case) or by another module (a fork, whose version is not a framework release). A host cannot pin such a build as a framework version, so this is surfaced rather than guessed. A replace by the framework module itself at another version IS resolvable, and that version is reported instead.

Functions

func FrameworkVersion

func FrameworkVersion(workDir string) (string, error)

FrameworkVersion reads the version of the Gombit framework the app in workDir builds against, from its go.mod. It deliberately parses the *declared* dependency rather than running the go toolchain, so it is offline and deterministic. It is internal/frameworkmod's Release, the same answer gombit upgrade baseline gives for go.mod.

The replace directive that applies to the required version (as the go command picks it) wins over the require: a replace by the framework module at another version reports that version, while a local filesystem replace or a fork is not a framework release and returns ErrFrameworkVersionUnresolved. A go.mod that does not require the framework at all, or that the go command refuses (the framework required twice, conflicting replaces), is an error.

Types

type Build

type Build struct {
	Command  string `json:"command"`
	Artifact string `json:"artifact"`
}

Build is the command that produces the deployable artifact and where it lands.

type Contract

type Contract struct {
	ContractVersion int        `json:"contract_version"`
	Framework       Framework  `json:"framework"`
	Build           Build      `json:"build"`
	Runtime         Runtime    `json:"runtime"`
	Database        Database   `json:"database"`
	Migrations      Migrations `json:"migrations"`
}

Contract is the machine-readable application description (DESIGN.md §9).

func Project

func Project(in Inputs) (Contract, error)

Project builds the application contract from declared inputs, applying the fixed/default fields. It fails loudly on inputs a host could not act on.

type Database

type Database struct {
	Required bool   `json:"required"`
	Driver   string `json:"driver"`
}

Database is the app's datastore dependency. Required is true when the framework refuses to start without a database for the declared configuration.

type Framework

type Framework struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Framework identifies the framework and the version the app builds against.

type Health

type Health struct {
	Live  string `json:"live"`
	Ready string `json:"ready"`
}

Health is the pair of operational probe paths (HOST-2).

type Inputs

type Inputs struct {
	// FrameworkVersion the app builds against (e.g. "v0.5.0"). Required — an
	// empty value is a hard error, never a silent default (DESIGN.md §55).
	FrameworkVersion string
	// HTTPAddr is the declared listen address (config.HTTP.Addr, e.g. ":8080").
	HTTPAddr string
	// DatabaseDriver is the configured driver (config.Database.Driver).
	DatabaseDriver string
	// DatabaseRequired is whether the framework requires a database to start
	// for this configuration (currently: auth enabled — framework/app.go).
	DatabaseRequired bool
	// MigrationsPath locates versioned migrations; DefaultMigrationsPath when "".
	MigrationsPath string
	// BuildCommand / BuildArtifact override the documented defaults when set.
	BuildCommand  string
	BuildArtifact string
}

Inputs are the declared values a Contract is projected from. The CLI maps a typed config.Config onto these; keeping Project free of config keeps it trivially testable and lets a host reuse the type.

type Migrations

type Migrations struct {
	Path string `json:"path"`
}

Migrations locates the app's versioned migrations.

type Runtime

type Runtime struct {
	HTTPPort int    `json:"http_port"`
	Health   Health `json:"health"`
}

Runtime describes how the built app is run and probed.

Jump to

Keyboard shortcuts

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