How goatx/goat works
Project Type and Purpose
• This is an open-source Go library/tool (“goat” = Go-Oriented Architecture Testing) for modeling and testing state machines and system architectures via Kripke structures and invariant checks.
• The core functionality lets users define states, events, handlers, and invariants, then automatically explore possible transitions and verify properties.
File-Structure Analysis
• Top-level Go packages (each .go file):
• environment.go – orchestrates execution contexts
• statemachine.go – core engine that steps through states
• event.go / eventhandler.go – definitions and callbacks for events
• invariant.go – user-supplied checks on states
• kripke.go – builds the Kripke graph of all reachable states
• error.go / version.go – support utilities
• No frontend/backend split—this is purely a Go library plus illustrative example CLIs.
Key Components & Interactions
a. User Code (examples/main.go)
• Defines a StateMachine type (states, transitions)
• Registers event handlers via environment.OnTransition
• Supplies invariants via environment.WithInvariant
• Calls environment.Run or a similar entry point
b. environment.go
• Serves as the central coordinator, invoking the statemachine engine
• Hooks user event handlers and invariants into each transition
c. statemachine.go
• Examines current state, available events
• Applies transitions, returns next state(s)
d. kripke.go
• Traverses all possible states/transitions to build a graph
• Annotates nodes/edges for downstream invariant checking
e. invariant.go
• Defines the interface for checks to be run at each state
f. event.go / eventhandler.go
• Event types and the registration/invocation logic for user callbacks
g. error.go / version.go
• Standard support modules
Architectural Patterns & Principles
• Modular package separation (each concern in its own file)
• Inversion of control: the library calls user-provided handlers (OnTransition, WithInvariant).
• Graph-based model checking: Kripke structure generation and exploration.
• Extensibility: users can plug in arbitrary handlers and invariants.