Documentation
¶
Overview ¶
Package modules implements haistack-modules, a manifest-driven installer for HAIStack. It turns a local module directory into runtime capabilities by driving the existing registry catalog, ModuleStore, and RegistryInstallStore.
v1 is registry-first: it fully installs and upgrades resource enablement, profiles, and search parameters. It persists declarations for views, AI tools, permissions, sync policies, subscriptions, and migrations in module metadata but does not execute those subsystems yet.
Module layout ¶
A module is a directory containing a module.json manifest and optional definition JSON files. Compiled IG artefacts may be loaded from an ig/ directory declared as igPackage:
modules/<name>/ ├── module.json ├── ig/*.json └── definitions/*.json
module.json declares the module identity, dependencies, resources to enable, definition files and/or an igPackage directory to ingest, and deferred subsystem declarations.
Manifest format ¶
Recommended manifest shape for v1:
{
"name": "scheduling",
"version": "1.0.0",
"dependencies": [{"name": "core", "version": "1.0.0"}],
"resources": ["Appointment", "Schedule", "Slot"],
"definitionFiles": ["definitions/Appointment-search-date.json"],
"views": ["AppointmentCalendar"],
"aiTools": [],
"permissions": ["read-appointment"],
"syncPolicies": [],
"subscriptions": [],
"migrations": []
}
Fields:
- name: module identity. Must be unique across installed modules.
- version: semver string. Upgrades must move to a greater version.
- dependencies: required modules with a minimum compatible semver version.
- resources: FHIR resource types to enable from the seeded base definitions.
- definitionFiles: relative JSON files to ingest as profiles or search parameters.
- igPackage: relative directory of compiled IG JSON (all *.json files are loaded).
- views, aiTools, permissions, syncPolicies, subscriptions, migrations: declaration-only arrays stored in ModuleRecord.Metadata for future subsystems.
Public API ¶
Manager is the primary runtime-facing entry point. Construct it with the existing persistence stores and a registry.Manager:
reg := registry.NewManager(registry.Config{Definitions: defs, Installs: installs})
mgr := modules.NewManager(modules.Config{
ModuleStore: moduleStore,
DefinitionStore: defs,
RegistryInstallStore: installs,
RegistryManager: reg,
Now: time.Now,
})
result, err := mgr.Install(ctx, "modules/scheduling")
Manager methods:
- Install loads a module directory and applies it to the registry.
- InstallAll applies a build-time module set as one compensating transaction.
- Upgrade loads a module directory and upgrades an already-installed module.
- Uninstall removes a module and its registry contributions.
- List returns all installed modules with their runtime contributions.
- Inspect returns one installed module.
- PlanInstall returns the intended install or upgrade plan without mutating state.
Deployments that distribute modules from an untrusted source should set modules.Config.Verifier. Ed25519ModuleVerifier verifies a detached module.json.sig over the exact manifest and definition bytes; custom ModuleVerifier implementations can enforce another trust root or format.
Install/upgrade behavior:
- Dependencies are validated for exact name match and minimum semver version.
- Cycles in the dependency graph, including self-references, are rejected.
- Base FHIR definitions are seeded before any resource is enabled.
- Declared resources are enabled and declared definitions are ingested with ModuleName and SourceModule provenance.
- The registry snapshot is rebuilt once at the end.
- Upgrades must be to a newer version and are additive only in v1; removing a previously declared resource or definition returns ErrUpgradeWouldRemove.
Uninstall behavior:
- Refuses if another installed module depends on the target.
- Refuses to disable a resource type that still has persisted resources when ResourceStore is configured.
- Disables resources contributed by the target that are not still required.
- Removes registry install rows and definition records owned by the target.
- Removes the ModuleStore entry last, after registry state is safely updated.
- Rebuilds the registry snapshot after uninstall.
Internal services ¶
The Manager composes several focused services:
- Loader reads and validates a module directory.
- DependencyResolver validates dependencies and detects cycles.
- RegistryApplier enables resources, installs definitions, and rebuilds snapshots.
- Installer orchestrates install/upgrade/uninstall planning and execution.
- CapabilitySnapshotBuilder returns a module-centric view of installed modules.
Paid modules, remote registry syncing, hospital-specific patch layering, and tenant-specific modules are out of v1 scope but are intended future extensions.
Index ¶
- Variables
- func LoadDefinitionsFromIG(dir string) ([][]byte, error)
- func ManifestToMetadata(manifest Manifest) (map[string]string, error)
- func ModuleSigningDigest(module Module) []byte
- type CapabilitySnapshotBuilder
- type Config
- type Declarations
- type DefinitionRef
- type DependencyRef
- type DependencyResolver
- type Ed25519ModuleVerifier
- type InstallAuthRequest
- type InstallAuthorizer
- type InstallAuthorizerFunc
- type InstallResult
- type InstallWorker
- type InstalledModule
- type Installer
- func (i *Installer) Install(ctx context.Context, mod *Module) (*InstallResult, error)
- func (i *Installer) PlanInstall(ctx context.Context, mod *Module) (*Plan, error)
- func (i *Installer) Uninstall(ctx context.Context, name string) error
- func (i *Installer) Upgrade(ctx context.Context, mod *Module) (*UpgradeResult, error)
- type Loader
- type Manager
- func (m *Manager) Inspect(ctx context.Context, name string) (*InstalledModule, error)
- func (m *Manager) Install(ctx context.Context, path string) (InstallResult, error)
- func (m *Manager) InstallAll(ctx context.Context, paths ...string) error
- func (m *Manager) InstallWithProgress(ctx context.Context, path string, progress ProgressFunc) (InstallResult, error)
- func (m *Manager) List(ctx context.Context) ([]InstalledModule, error)
- func (m *Manager) PlanInstall(ctx context.Context, path string) (*Plan, error)
- func (m *Manager) SetAfterChange(fn func(ctx context.Context) error)
- func (m *Manager) Uninstall(ctx context.Context, name string) error
- func (m *Manager) Upgrade(ctx context.Context, path string) (UpgradeResult, error)
- func (m *Manager) UpgradeWithProgress(ctx context.Context, path string, progress ProgressFunc) (UpgradeResult, error)
- type Manifest
- type Module
- type ModuleVerifier
- type ModuleVerifierFunc
- type Plan
- type ProgressFunc
- type RegistryApplier
- func (a *RegistryApplier) CompletePackageInstall(ctx context.Context, provenance registry.InstallProvenance) error
- func (a *RegistryApplier) DefinitionStore() store.DefinitionStore
- func (a *RegistryApplier) DeleteDefinition(ctx context.Context, canonicalURL, version string) error
- func (a *RegistryApplier) DeleteInstall(ctx context.Context, filter store.RegistryInstallFilter) error
- func (a *RegistryApplier) DisableResource(ctx context.Context, resourceType string) error
- func (a *RegistryApplier) EnableResource(ctx context.Context, resourceType string) error
- func (a *RegistryApplier) InstallDefinition(ctx context.Context, jsonData []byte, provenance registry.InstallProvenance) error
- func (a *RegistryApplier) InstallStore() store.RegistryInstallStore
- func (a *RegistryApplier) RebuildSnapshot(ctx context.Context) (*registry.Snapshot, error)
- func (a *RegistryApplier) SeedBundled(ctx context.Context) error
- type UpgradeResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrManifestNotFound is returned when a module directory does not contain // a module.json manifest. ErrManifestNotFound = errors.New("module manifest not found") // ErrInvalidManifest is returned when a manifest fails validation. ErrInvalidManifest = errors.New("invalid module manifest") // ErrMissingDependency is returned when a required module dependency is not // installed. ErrMissingDependency = errors.New("missing module dependency") // ErrDependencyVersionMismatch is returned when an installed dependency is // below the required minimum version. ErrDependencyVersionMismatch = errors.New("module dependency version mismatch") // ErrCircularDependency is returned when a module's dependency graph contains // a cycle. ErrCircularDependency = errors.New("circular module dependency") // ErrAmbiguousModule is returned when a module name maps to multiple // conflicting versions or sources. ErrAmbiguousModule = errors.New("ambiguous module reference") // ErrDowngradeNotAllowed is returned when an upgrade would move to an older // or equal version. ErrDowngradeNotAllowed = errors.New("module downgrade not allowed") // ErrModuleNotFound is returned when an operation references a module that // is not installed. ErrModuleNotFound = errors.New("module not found") // ErrModuleInUse is returned when uninstall is blocked because another // installed module depends on the target. ErrModuleInUse = errors.New("module is required by another installed module") // ErrResourceTypeInUse is returned when uninstalling a module would disable // a resource type that still has persisted resources. ErrResourceTypeInUse = errors.New("resource type still has persisted resources") // ErrModuleFileTooLarge is returned when a manifest or definition file // exceeds the loader's configured safety limit. ErrModuleFileTooLarge = errors.New("module file is too large") // ErrModuleSignatureMissing is returned when a configured verifier cannot // find the module's detached signature. ErrModuleSignatureMissing = errors.New("module signature missing") // ErrModuleSignatureInvalid is returned when a configured verifier rejects // the module signature or its signed content. ErrModuleSignatureInvalid = errors.New("invalid module signature") // ErrUpgradeWouldRemove is returned when an upgrade would remove // resources or definitions that were previously declared, requiring manual // action in v1. ErrUpgradeWouldRemove = errors.New("upgrade would remove previously declared resources or definitions") )
Functions ¶
func LoadDefinitionsFromIG ¶
LoadDefinitionsFromIG reads FHIR JSON definition files from a compiled IG output directory (SUSHI fsh-generated/resources or an unpacked NPM package).
func ManifestToMetadata ¶
ManifestToMetadata serializes a manifest for storage in a module record.
func ModuleSigningDigest ¶
ModuleSigningDigest returns the digest signed by Ed25519ModuleVerifier. Framing prevents concatenation ambiguity between manifest and definitions.
Types ¶
type CapabilitySnapshotBuilder ¶
type CapabilitySnapshotBuilder struct {
// contains filtered or unexported fields
}
CapabilitySnapshotBuilder returns a module-centric view of what each installed module contributed, built from ModuleStore plus RegistryInstallStore.
func NewCapabilitySnapshotBuilder ¶
func NewCapabilitySnapshotBuilder(modules store.ModuleStore, installs store.RegistryInstallStore) *CapabilitySnapshotBuilder
NewCapabilitySnapshotBuilder creates a builder backed by the module and registry install stores.
func (*CapabilitySnapshotBuilder) Build ¶
func (b *CapabilitySnapshotBuilder) Build(ctx context.Context) ([]InstalledModule, error)
Build returns one InstalledModule per registered module, with resources and definitions derived from registry install rows that name the module as their source.
type Config ¶
type Config struct {
ModuleStore store.ModuleStore
DefinitionStore store.DefinitionStore
RegistryInstallStore store.RegistryInstallStore
RegistryManager *registry.Manager
ResourceStore store.ResourceStore
Authorizer InstallAuthorizer
Verifier ModuleVerifier
Now func() time.Time
}
Config supplies the stable persistence pieces required by the module manager. Tenant-aware wrappers can be added later without changing this shape.
type Declarations ¶
type Declarations struct {
Views []string `json:"views,omitempty"`
AITools []string `json:"aiTools,omitempty"`
Permissions []string `json:"permissions,omitempty"`
SyncPolicies []string `json:"syncPolicies,omitempty"`
Subscriptions []string `json:"subscriptions,omitempty"`
Migrations []string `json:"migrations,omitempty"`
}
Declarations groups deferred subsystem names that are stored but not executed in v1.
type DefinitionRef ¶
type DefinitionRef struct {
CanonicalURL string `json:"canonicalUrl"`
Version string `json:"version"`
}
DefinitionRef identifies one installed definition by canonical URL and version.
type DependencyRef ¶
DependencyRef names a required module and its minimum compatible version.
type DependencyResolver ¶
type DependencyResolver struct {
// contains filtered or unexported fields
}
DependencyResolver validates dependency presence and version compatibility before install. v1 policy: exact module name match and semver-compatible minimum version; fail on ambiguity or cycles.
func NewDependencyResolver ¶
func NewDependencyResolver(modules store.ModuleStore) *DependencyResolver
NewDependencyResolver creates a resolver backed by the installed module store.
type Ed25519ModuleVerifier ¶
Ed25519ModuleVerifier verifies a detached Ed25519 signature stored next to module.json. The signature covers ModuleSigningDigest, which includes the exact manifest bytes and every loaded definition file in manifest order. Signatures may be raw 64-byte values or standard base64 text.
func (Ed25519ModuleVerifier) VerifyModule ¶
func (v Ed25519ModuleVerifier) VerifyModule(ctx context.Context, module Module) error
VerifyModule verifies one module using the configured Ed25519 public key.
type InstallAuthRequest ¶
InstallAuthRequest carries module authorization context for install and upgrade operations.
type InstallAuthorizer ¶
type InstallAuthorizer interface {
AuthorizeModuleInstall(ctx context.Context, req InstallAuthRequest) error
}
InstallAuthorizer is the pluggable authorization seam for module install/upgrade operations.
type InstallAuthorizerFunc ¶
type InstallAuthorizerFunc func(ctx context.Context, req InstallAuthRequest) error
InstallAuthorizerFunc adapts a function to InstallAuthorizer.
func (InstallAuthorizerFunc) AuthorizeModuleInstall ¶
func (f InstallAuthorizerFunc) AuthorizeModuleInstall(ctx context.Context, req InstallAuthRequest) error
AuthorizeModuleInstall implements InstallAuthorizer.
type InstallResult ¶
type InstallResult struct {
Action string `json:"action"`
Name string `json:"name"`
Version string `json:"version"`
EnabledResources []string `json:"enabledResources,omitempty"`
InstalledDefinitions []DefinitionRef `json:"installedDefinitions,omitempty"`
Deferred Declarations `json:"deferred,omitempty"`
Snapshot *registry.Snapshot `json:"-"`
}
InstallResult reports what an install changed in the registry.
type InstallWorker ¶
type InstallWorker struct {
Manager *Manager
Store store.JobStore
TerminologyInstalls store.TerminologyInstallStoreFactory
DefaultTerminologyTenantID string
}
InstallWorker handles modules.install jobs.
type InstalledModule ¶
type InstalledModule struct {
Name string `json:"name"`
Version string `json:"version"`
Dependencies []DependencyRef `json:"dependencies,omitempty"`
Resources []string `json:"resources,omitempty"`
Definitions []DefinitionRef `json:"definitions,omitempty"`
Deferred Declarations `json:"deferred,omitempty"`
RegisteredAt time.Time `json:"registeredAt"`
}
InstalledModule is a module-centric view of one registered module and its runtime contributions.
type Installer ¶
type Installer struct {
OnProgress ProgressFunc
// contains filtered or unexported fields
}
Installer orchestrates install/upgrade/uninstall planning and execution. It owns the registry applier and module store updates.
func NewInstaller ¶
func NewInstaller(modules store.ModuleStore, defs store.DefinitionStore, installs store.RegistryInstallStore, reg *registry.Manager, now func() time.Time) *Installer
NewInstaller creates an installer from the same persistence pieces used by the public manager. Resource usage checks are disabled when no resource store is supplied; use NewInstallerWithResources for production lifecycle protection.
func NewInstallerWithResources ¶
func NewInstallerWithResources(modules store.ModuleStore, defs store.DefinitionStore, installs store.RegistryInstallStore, reg *registry.Manager, resources store.ResourceStore, now func() time.Time) *Installer
NewInstallerWithResources creates an installer that also checks persisted resources before disabling a resource type during uninstall.
func (*Installer) Install ¶
Install applies a module to the registry and registers the module.
The persistence interfaces intentionally remain backend-neutral, so the installer uses a compensating state transaction around the multi-store operation. This keeps a failed install from leaving registry or module records half-applied.
func (*Installer) PlanInstall ¶
PlanInstall computes the desired state for a module without mutating the registry or module store.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader reads a local module directory, parses module.json, resolves relative file references, and returns a normalized Module.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the public runtime-facing API for installing, upgrading, uninstalling, and inspecting modules.
func NewManager ¶
NewManager constructs a module manager from persistence stores.
func (*Manager) Inspect ¶
Inspect returns one installed module, or ErrModuleNotFound if it is not registered.
func (*Manager) InstallAll ¶
InstallAll installs a build-time module set as one logical operation. If a later module fails, all state changes made by this batch are compensated.
func (*Manager) InstallWithProgress ¶
func (m *Manager) InstallWithProgress(ctx context.Context, path string, progress ProgressFunc) (InstallResult, error)
InstallWithProgress loads a module and reports incremental install progress.
func (*Manager) List ¶
func (m *Manager) List(ctx context.Context) ([]InstalledModule, error)
List returns all installed modules with their runtime contributions.
func (*Manager) PlanInstall ¶
PlanInstall returns the intended install or upgrade plan without mutating persistent state.
func (*Manager) SetAfterChange ¶
SetAfterChange registers a callback invoked after successful install, upgrade, or uninstall operations.
func (*Manager) Upgrade ¶
Upgrade loads a local module directory and upgrades the already-installed module of the same name to a newer version.
func (*Manager) UpgradeWithProgress ¶
func (m *Manager) UpgradeWithProgress(ctx context.Context, path string, progress ProgressFunc) (UpgradeResult, error)
UpgradeWithProgress upgrades a module and reports incremental progress.
type Manifest ¶
type Manifest struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Dependencies []DependencyRef `json:"dependencies,omitempty"`
Resources []string `json:"resources,omitempty"`
DefinitionFiles []string `json:"definitionFiles,omitempty"`
// IGPackage is a module-relative directory of compiled IG JSON resources
// (typically modules/<name>/ig produced by make ig). When set, every
// *.json file in that directory is loaded as a definition.
IGPackage string `json:"igPackage,omitempty"`
Views []string `json:"views,omitempty"`
AITools []string `json:"aiTools,omitempty"`
Permissions []string `json:"permissions,omitempty"`
SyncPolicies []string `json:"syncPolicies,omitempty"`
Subscriptions []string `json:"subscriptions,omitempty"`
Migrations []string `json:"migrations,omitempty"`
}
Manifest describes a module's identity and declared capabilities. Declarations for views, aiTools, permissions, syncPolicies, subscriptions, and migrations are persisted but not executed in v1.
type Module ¶
type Module struct {
Path string
Manifest Manifest
ManifestBytes []byte
Definitions [][]byte
DefinitionPaths []string
}
Module is a normalized, loaded module with its manifest and in-memory definition payloads.
type ModuleVerifier ¶
ModuleVerifier verifies a loaded module before dependency resolution or registry mutation. Deployments can use this seam to enforce their own trust roots and signature formats.
type ModuleVerifierFunc ¶
ModuleVerifierFunc adapts a function to ModuleVerifier.
func (ModuleVerifierFunc) VerifyModule ¶
func (f ModuleVerifierFunc) VerifyModule(ctx context.Context, module Module) error
VerifyModule implements ModuleVerifier.
type Plan ¶
type Plan struct {
Name string `json:"name"`
Version string `json:"version"`
Action string `json:"action"`
Dependencies []DependencyRef `json:"dependencies,omitempty"`
ResourcesToEnable []string `json:"resourcesToEnable,omitempty"`
DefinitionsToInstall []DefinitionRef `json:"definitionsToInstall,omitempty"`
DefinitionsToRemove []DefinitionRef `json:"definitionsToRemove,omitempty"`
Deferred Declarations `json:"deferred,omitempty"`
}
Plan describes the intended outcome of an install or upgrade without mutating persistent state.
type ProgressFunc ¶
ProgressFunc reports incremental module install progress.
type RegistryApplier ¶
type RegistryApplier struct {
// contains filtered or unexported fields
}
RegistryApplier installs module-owned definitions, enables or disables base resources, and rebuilds the registry snapshot. It is the boundary between the module installer and the registry.Manager.
func NewRegistryApplier ¶
func NewRegistryApplier(reg *registry.Manager, defs store.DefinitionStore, installs store.RegistryInstallStore) *RegistryApplier
NewRegistryApplier creates an applier backed by the registry manager and its persistence stores.
func (*RegistryApplier) CompletePackageInstall ¶
func (a *RegistryApplier) CompletePackageInstall(ctx context.Context, provenance registry.InstallProvenance) error
CompletePackageInstall enqueues batched ValueSet pre-expand for a package install.
func (*RegistryApplier) DefinitionStore ¶
func (a *RegistryApplier) DefinitionStore() store.DefinitionStore
DefinitionStore returns the underlying definition store for queries.
func (*RegistryApplier) DeleteDefinition ¶
func (a *RegistryApplier) DeleteDefinition(ctx context.Context, canonicalURL, version string) error
DeleteDefinition removes a definition catalog entry and its target mappings.
func (*RegistryApplier) DeleteInstall ¶
func (a *RegistryApplier) DeleteInstall(ctx context.Context, filter store.RegistryInstallFilter) error
DeleteInstall removes registry install rows matching the filter.
func (*RegistryApplier) DisableResource ¶
func (a *RegistryApplier) DisableResource(ctx context.Context, resourceType string) error
DisableResource marks a base resource type as disabled.
func (*RegistryApplier) EnableResource ¶
func (a *RegistryApplier) EnableResource(ctx context.Context, resourceType string) error
EnableResource marks a base resource type as enabled.
func (*RegistryApplier) InstallDefinition ¶
func (a *RegistryApplier) InstallDefinition(ctx context.Context, jsonData []byte, provenance registry.InstallProvenance) error
InstallDefinition ingests a definition JSON with module provenance.
func (*RegistryApplier) InstallStore ¶
func (a *RegistryApplier) InstallStore() store.RegistryInstallStore
InstallStore returns the underlying registry install store for queries.
func (*RegistryApplier) RebuildSnapshot ¶
RebuildSnapshot compiles the registry snapshot.
func (*RegistryApplier) SeedBundled ¶
func (a *RegistryApplier) SeedBundled(ctx context.Context) error
SeedBundled ensures the embedded FHIR base definitions are present.
type UpgradeResult ¶
type UpgradeResult struct {
Name string `json:"name"`
OldVersion string `json:"oldVersion"`
NewVersion string `json:"newVersion"`
EnabledResources []string `json:"enabledResources,omitempty"`
InstalledDefinitions []DefinitionRef `json:"installedDefinitions,omitempty"`
RemovedDefinitions []DefinitionRef `json:"removedDefinitions,omitempty"`
Deferred Declarations `json:"deferred,omitempty"`
Snapshot *registry.Snapshot `json:"-"`
}
UpgradeResult reports what an upgrade changed in the registry.