# google/wire architecture

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

- Interactive diagram: https://gitdiagram.com/google/wire
- Repository: https://github.com/google/wire

## Overview

Wire is a Go compile-time dependency-injection code generator, not a runtime container. A developer declares providers and injector templates, then runs the `wire` CLI; the tool analyzes dependency requirements and emits Go initialization code, which the application builds and calls. The README documents provider sets, explicit function-parameter dependencies, and the absence of runtime reflection/state. Some internal stage boundaries are inferred from the partial excerpts, so those relationships are dashed and uncited rather than asserted as inspected calls.

Main entry points: [`internal/wire/wire.go`](https://github.com/google/wire/blob/main/internal/wire/wire.go) (Generation engine), [`cmd/wire/main.go`](https://github.com/google/wire/blob/main/cmd/wire/main.go) (Wire CLI), [`internal/wire/parse.go`](https://github.com/google/wire/blob/main/internal/wire/parse.go) (Package analysis), [`internal/wire/analyze.go`](https://github.com/google/wire/blob/main/internal/wire/analyze.go) (Provider graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["Injector authoring"]
  node_directives["Wire directives<br/>[wire.go]"]
  node_injector["Injector template<br/>[wire.go]"]
end

subgraph group_tool["Generation command"]
  node_cli["Wire CLI<br/>[main.go]"]
end

subgraph group_engine["Analysis and emission"]
  node_engine["Generation engine<br/>[wire.go]"]
  node_parser["Package analysis<br/>[parse.go]"]
  node_graph["Provider graph<br/>[analyze.go]"]
  node_diagnostics["Error reporting<br/>[errors.go]"]
  node_astcopy["AST copying<br/>[copyast.go]"]
end

node_developer(("Go developer"))
node_generated["Generated injector"]
node_application["Go application"]

node_developer -->|"declares providers"| node_directives
node_developer -->|"writes template"| node_injector
node_developer -->|"runs generation"| node_cli
node_cli -->|"calls Generate"| node_engine
node_engine -.->|"analyzes packages"| node_parser
node_parser -.->|"builds provider graph"| node_graph
node_engine -.->|"solves dependencies"| node_graph
node_engine -.->|"collects errors"| node_diagnostics
node_engine -->|"copies AST"| node_astcopy
node_engine -->|"emits Go code"| node_generated
node_generated -->|"compiled into"| node_application

click node_directives "https://github.com/google/wire/blob/main/wire.go"
click node_injector "https://github.com/google/wire/blob/main/wire.go"
click node_cli "https://github.com/google/wire/blob/main/cmd/wire/main.go"
click node_engine "https://github.com/google/wire/blob/main/internal/wire/wire.go"
click node_parser "https://github.com/google/wire/blob/main/internal/wire/parse.go"
click node_graph "https://github.com/google/wire/blob/main/internal/wire/analyze.go"
click node_diagnostics "https://github.com/google/wire/blob/main/internal/wire/errors.go"
click node_astcopy "https://github.com/google/wire/blob/main/internal/wire/copyast.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_directives,node_injector toneBlue
class node_cli toneAmber
class node_engine,node_parser,node_graph,node_diagnostics,node_astcopy toneMint
class node_developer,node_generated,node_application toneIndigo
```

## Components

### Injector authoring

- [Wire directives](https://github.com/google/wire/blob/main/wire.go): `wire.go`
- [Injector template](https://github.com/google/wire/blob/main/wire.go): `wire.go`

### Generation command

- [Wire CLI](https://github.com/google/wire/blob/main/cmd/wire/main.go): `cmd/wire/main.go`

### Analysis and emission

- [Generation engine](https://github.com/google/wire/blob/main/internal/wire/wire.go): `internal/wire/wire.go`
- [Package analysis](https://github.com/google/wire/blob/main/internal/wire/parse.go): `internal/wire/parse.go`
- [Provider graph](https://github.com/google/wire/blob/main/internal/wire/analyze.go): `internal/wire/analyze.go`
- [Error reporting](https://github.com/google/wire/blob/main/internal/wire/errors.go): `internal/wire/errors.go`
- [AST copying](https://github.com/google/wire/blob/main/internal/wire/copyast.go): `internal/wire/copyast.go`

### Other components

- **Go developer**
- **Generated injector**
- **Go application**

## Connections

- Go developer → Wire directives: declares providers (evidence: `wire.go`)
- Go developer → Injector template: writes template (evidence: `wire.go`)
- Go developer → Wire CLI: runs generation (evidence: `README.md`)
- Wire CLI → Generation engine: calls Generate (evidence: `cmd/wire/main.go`)
- Generation engine → Package analysis: analyzes packages
- Package analysis → Provider graph: builds provider graph
- Generation engine → Provider graph: solves dependencies
- Generation engine → Error reporting: collects errors
- Generation engine → AST copying: copies AST (evidence: `internal/wire/wire.go`)
- Generation engine → Generated injector: emits Go code (evidence: `internal/wire/wire.go`)
- Generated injector → Go application: compiled into (evidence: `README.md`)
