Lifecycle Supervision & Kernel (pkg/lifecycle)

Import path: github.com/krewire/krewire/pkg/lifecycle

lifecycle.Kernel is the imperative control plane: it binds a validated model.Project to registered modules and executes a declared workload.


Kernel Execution Example

package main

import (
	"context"
	"os"

	"github.com/krewire/krewire/pkg/lifecycle"
	"github.com/krewire/krewire/pkg/model"
)

func main() {
	ctx := context.Background()

	k, err := lifecycle.New(project)
	if err != nil {
		panic(err)
	}

	k.Use(bootModule, webModule) // modules initialize in dependency order
	k.RegisterHandler(run)

	if err := k.Boot(ctx); err != nil {
		panic(err)
	}
	defer k.Shutdown(ctx)

	os.Exit(k.Execute(ctx).Int())
}

Supporting Types

  • Registry โ€” NewRegistry, Register, Ordered, Resolve; ordering is resolved from each module's DependsOn() []string, never from arbitrary map iteration.
  • Supervisor โ€” NewSupervisor, Add, Start, Stop, Health, Reload, WithShutdownTimeout; supervises long-running background processes and services.
  • Capability Interfaces โ€” Module, Startable, and Depender opt-in interfaces that allow modular subsystems to hook into initialization and cleanup phases.\n