# vektra/mockery architecture

> Architecture diagram of the GitHub repository vektra/mockery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vektra/mockery
- Repository: https://github.com/vektra/mockery

## Overview

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: [`internal/template_generator.go`](https://github.com/vektra/mockery/blob/v3/internal/template_generator.go) (Template generator), [`internal/cmd/mockery.go`](https://github.com/vektra/mockery/blob/v3/internal/cmd/mockery.go) (Generation command), [`internal/parse.go`](https://github.com/vektra/mockery/blob/v3/internal/parse.go) (Go package parser), [`config/config.go`](https://github.com/vektra/mockery/blob/v3/config/config.go) (Configuration schema)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and configuration"]
  node_entry["Mockery entry<br/>[main.go]"]
  node_commands["Generation command<br/>[mockery.go]"]
  node_config["Configuration schema<br/>[config.go]"]
  node_init["Init command<br/>[init.go]"]
  node_migrate["Config migration<br/>[migrate.go]"]
  node_showconfig["Show config<br/>[showconfig.go]"]
end

subgraph group_discovery["Package discovery"]
  node_parser["Go package parser<br/>[parse.go]"]
  node_visitor["AST interface visitor<br/>[node_visitor.go]"]
  node_iface["Interface model<br/>[interface.go]"]
end

subgraph group_generation["Mock generation"]
  node_generator["Template generator"]
  node_writer["Generated file output<br/>[mockery.go]"]
  node_remote["Remote templates<br/>[remote_template.go]"]
end

subgraph group_template["Template model"]
  node_registry["Type registry<br/>[registry.go]"]
  node_scope["Method name scope<br/>[method_scope.go]"]
  node_method["Method representation<br/>[method.go]"]
  node_data["Template data model<br/>[data.go]"]
  node_templaterender["Template execution<br/>[template.go]"]
  node_templatefuncs["Template functions<br/>[functions.go]"]
end

node_user(("CLI user"))
node_filesystem[("Filesystem")]
node_gointerfaces["Go interfaces"]
node_mockoutput["Generated mocks"]
node_testify["testify/mock"]

node_user -->|"runs"| node_entry
node_entry -->|"executes"| node_commands
node_commands -->|"loads config"| node_config
node_commands -->|"parses packages"| node_parser
node_parser -->|"walks syntax"| node_visitor
node_parser -->|"collects interfaces"| node_iface
node_commands -->|"configures interfaces"| node_iface
node_commands -->|"generates mocks"| node_generator
node_generator -->|"looks up types"| node_registry
node_generator -.->|"builds method scope"| node_scope
node_scope -->|"resolves imports"| node_registry
node_generator -.->|"builds methods"| node_method
node_generator -.->|"builds template data"| node_data
node_generator -->|"executes template"| node_templaterender
node_templaterender -->|"uses functions"| node_templatefuncs
node_generator -.->|"fetches template"| node_remote
node_commands -->|"writes output"| node_writer
node_writer -->|"creates files"| node_filesystem
node_writer -->|"writes mocks"| node_mockoutput
node_gointerfaces -.->|"provides source"| node_parser
node_init -->|"uses defaults"| node_config
node_init -->|"writes config"| node_filesystem
node_migrate -->|"converts settings"| node_config
node_migrate -->|"writes config"| node_filesystem
node_showconfig -->|"shows settings"| node_config
node_mockoutput -->|"targets library"| node_testify

click node_entry "https://github.com/vektra/mockery/blob/v3/main.go"
click node_commands "https://github.com/vektra/mockery/blob/v3/internal/cmd/mockery.go"
click node_config "https://github.com/vektra/mockery/blob/v3/config/config.go"
click node_init "https://github.com/vektra/mockery/blob/v3/internal/cmd/init.go"
click node_migrate "https://github.com/vektra/mockery/blob/v3/internal/cmd/migrate.go"
click node_showconfig "https://github.com/vektra/mockery/blob/v3/internal/cmd/showconfig.go"
click node_parser "https://github.com/vektra/mockery/blob/v3/internal/parse.go"
click node_visitor "https://github.com/vektra/mockery/blob/v3/internal/node_visitor.go"
click node_iface "https://github.com/vektra/mockery/blob/v3/internal/interface.go"
click node_generator "https://github.com/vektra/mockery/blob/v3/internal/template_generator.go"
click node_writer "https://github.com/vektra/mockery/blob/v3/internal/cmd/mockery.go"
click node_remote "https://github.com/vektra/mockery/blob/v3/internal/remote_template.go"
click node_registry "https://github.com/vektra/mockery/blob/v3/template/registry.go"
click node_scope "https://github.com/vektra/mockery/blob/v3/template/method_scope.go"
click node_method "https://github.com/vektra/mockery/blob/v3/template/method.go"
click node_data "https://github.com/vektra/mockery/blob/v3/template/data.go"
click node_templaterender "https://github.com/vektra/mockery/blob/v3/template/template.go"
click node_templatefuncs "https://github.com/vektra/mockery/blob/v3/template_funcs/functions.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_commands,node_config,node_init,node_migrate,node_showconfig,node_user toneBlue
class node_parser,node_visitor,node_iface,node_filesystem toneAmber
class node_generator,node_writer,node_remote toneMint
class node_registry,node_scope,node_method,node_data,node_templaterender,node_templatefuncs toneRose
class node_gointerfaces,node_mockoutput,node_testify toneIndigo
```

## Components

### CLI and configuration

- [Mockery entry](https://github.com/vektra/mockery/blob/v3/main.go): `main.go`
- [Generation command](https://github.com/vektra/mockery/blob/v3/internal/cmd/mockery.go): `internal/cmd/mockery.go`
- [Configuration schema](https://github.com/vektra/mockery/blob/v3/config/config.go): `config/config.go`
- [Init command](https://github.com/vektra/mockery/blob/v3/internal/cmd/init.go): `internal/cmd/init.go`
- [Config migration](https://github.com/vektra/mockery/blob/v3/internal/cmd/migrate.go): `internal/cmd/migrate.go`
- [Show config](https://github.com/vektra/mockery/blob/v3/internal/cmd/showconfig.go): `internal/cmd/showconfig.go`

### Package discovery

- [Go package parser](https://github.com/vektra/mockery/blob/v3/internal/parse.go): `internal/parse.go`
- [AST interface visitor](https://github.com/vektra/mockery/blob/v3/internal/node_visitor.go): `internal/node_visitor.go`
- [Interface model](https://github.com/vektra/mockery/blob/v3/internal/interface.go): `internal/interface.go`

### Mock generation

- [Template generator](https://github.com/vektra/mockery/blob/v3/internal/template_generator.go): `internal/template_generator.go`
- [Generated file output](https://github.com/vektra/mockery/blob/v3/internal/cmd/mockery.go): `internal/cmd/mockery.go`
- [Remote templates](https://github.com/vektra/mockery/blob/v3/internal/remote_template.go): `internal/remote_template.go`

### Template model

- [Type registry](https://github.com/vektra/mockery/blob/v3/template/registry.go): `template/registry.go`
- [Method name scope](https://github.com/vektra/mockery/blob/v3/template/method_scope.go): `template/method_scope.go`
- [Method representation](https://github.com/vektra/mockery/blob/v3/template/method.go): `template/method.go`
- [Template data model](https://github.com/vektra/mockery/blob/v3/template/data.go): `template/data.go`
- [Template execution](https://github.com/vektra/mockery/blob/v3/template/template.go): `template/template.go`
- [Template functions](https://github.com/vektra/mockery/blob/v3/template_funcs/functions.go): `template_funcs/functions.go`

### Other components

- **CLI user**
- **Filesystem**
- **Go interfaces**
- **Generated mocks**
- **testify/mock**

## Connections

- CLI user → Mockery entry: runs (evidence: `main.go`)
- Mockery entry → Generation command: executes (evidence: `main.go`)
- Generation command → Configuration schema: loads config (evidence: `internal/cmd/mockery.go`)
- Generation command → Go package parser: parses packages (evidence: `internal/cmd/mockery.go`)
- Go package parser → AST interface visitor: walks syntax (evidence: `internal/parse.go`)
- Go package parser → Interface model: collects interfaces (evidence: `internal/parse.go`)
- Generation command → Interface model: configures interfaces (evidence: `internal/cmd/mockery.go`)
- Generation command → Template generator: generates mocks (evidence: `internal/cmd/mockery.go`)
- Template generator → Type registry: looks up types (evidence: `internal/template_generator.go`)
- Template generator → Method name scope: builds method scope
- Method name scope → Type registry: resolves imports (evidence: `template/method_scope.go`)
- Template generator → Method representation: builds methods
- Template generator → Template data model: builds template data
- Template generator → Template execution: executes template (evidence: `internal/template_generator.go`)
- Template execution → Template functions: uses functions (evidence: `template/template.go`)
- Template generator → Remote templates: fetches template
- Generation command → Generated file output: writes output (evidence: `internal/cmd/mockery.go`)
- Generated file output → Filesystem: creates files (evidence: `internal/cmd/mockery.go`)
- Generated file output → Generated mocks: writes mocks (evidence: `internal/cmd/mockery.go`)
- Go interfaces → Go package parser: provides source
- Init command → Configuration schema: uses defaults (evidence: `internal/cmd/init.go`)
- Init command → Filesystem: writes config (evidence: `internal/cmd/init.go`)
- Config migration → Configuration schema: converts settings (evidence: `internal/cmd/migrate.go`)
- Config migration → Filesystem: writes config (evidence: `internal/cmd/migrate.go`)
- Show config → Configuration schema: shows settings (evidence: `internal/cmd/showconfig.go`)
- Generated mocks → testify/mock: targets library
