How vektra/mockery works
Mockery is a Go interface-mock generator. The main workflow loads configuration, discovers configured packages and interfaces, builds typed template data, renders mocks, and writes generated files. The graph also retains the documented config initialization/migration commands and the template/import/type-scope layers. Some links use only README or indexed-file references; unsampled internals are not treated as inspected.
Main entry points: template_generator.go Template generator · mockery.go Generation command · parse.go Go package parser · config.go Configuration schema
Components 23
CLI and configuration
- Mockery entry
main.go - Generation command
internal/cmd/mockery.go - Configuration schema
config/config.go - Init command
internal/cmd/init.go - Config migration
internal/cmd/migrate.go - Show config
internal/cmd/showconfig.go
Package discovery
- Go package parser
internal/parse.go - AST interface visitor
internal/node_visitor.go - Interface model
internal/interface.go
Mock generation
- Template generator
internal/template_generator.go - Generated file output
internal/cmd/mockery.go - Remote templates
internal/remote_template.go
Template model
- Type registry
template/registry.go - Method name scope
template/method_scope.go - Method representation
template/method.go - Template data model
template/data.go - Template execution
template/template.go - Template functions
template_funcs/functions.go
Other components
- CLI user
- Filesystem
- Go interfaces
- Generated mocks
- testify/mock
Connections 26
- CLI user → Mockery entry: runs
main.go - Mockery entry → Generation command: executes
main.go - Generation command → Configuration schema: loads config
internal/cmd/mockery.go - Generation command → Go package parser: parses packages
internal/cmd/mockery.go - Go package parser → AST interface visitor: walks syntax
internal/parse.go - Go package parser → Interface model: collects interfaces
internal/parse.go - Generation command → Interface model: configures interfaces
internal/cmd/mockery.go - Generation command → Template generator: generates mocks
internal/cmd/mockery.go - Template generator → Type registry: looks up types
internal/template_generator.go - Template generator → Method name scope: builds method scope
- Method name scope → Type registry: resolves imports
template/method_scope.go - Template generator → Method representation: builds methods
- Template generator → Template data model: builds template data
- Template generator → Template execution: executes template
internal/template_generator.go - Template execution → Template functions: uses functions
template/template.go - Template generator → Remote templates: fetches template
- Generation command → Generated file output: writes output
internal/cmd/mockery.go - Generated file output → Filesystem: creates files
internal/cmd/mockery.go - Generated file output → Generated mocks: writes mocks
internal/cmd/mockery.go - Go interfaces → Go package parser: provides source
- Init command → Configuration schema: uses defaults
internal/cmd/init.go - Init command → Filesystem: writes config
internal/cmd/init.go - Config migration → Configuration schema: converts settings
internal/cmd/migrate.go - Config migration → Filesystem: writes config
internal/cmd/migrate.go - Show config → Configuration schema: shows settings
internal/cmd/showconfig.go - Generated mocks → testify/mock: targets library