aquasecurity/trivy
Apps
Trivy ships as a single Go binary (cmd/trivy/main.go) but exposes several modes that look like distinct applications to a user:
- The CLI — interactive scans, configuration management, and one-shot operations.
- The Server — long-running RPC server for
trivy clientand the Trivy Operator. - The Plugin host — the same binary running in plugin-replacement mode (
TRIVY_RUN_AS_PLUGIN=...). - The Module host — the same binary loading WebAssembly modules.
The "apps" lens here documents the user-facing surfaces. The reusable subsystems behind them (fanal, scan service, cache, RPC, plugin manager, WebAssembly host) are covered under systems.
Pages in this section
- CLI — the
trivybinary, its command tree, and how a command is wired up. - Server — the
trivy servermode and its RPC surface.
How a single binary serves four roles
graph LR
Bin[trivy binary<br/>cmd/trivy/main.go] -->|TRIVY_RUN_AS_PLUGIN| Plugin[Plugin replacement<br/>pkg/plugin/Run]
Bin -->|otherwise| Run[commands.Run]
Run -->|trivy server| Server[server command<br/>pkg/commands/server]
Run -->|trivy client / trivy image --server| Client[client command<br/>pkg/commands/server + RPC]
Run -->|trivy image / fs / repo / ...| StdScan[standalone scan<br/>pkg/commands/artifact]
Run -->|trivy module install| ModHost[module host<br/>pkg/module]
Run -->|trivy <plugin>| PluginCmd[plugin command<br/>pkg/plugin]The dispatch happens in two places:
cmd/trivy/main.go— checks theTRIVY_RUN_AS_PLUGINenvironment variable; if set, runs Trivy as the named plugin.pkg/commands/app.go— Cobra root command with subcommands for every top-level mode.
Common scaffolding
Every command shares the same scaffolding:
- A
New<Name>Command(globalFlags)constructor inpkg/commands/app.go. - A
flag.Flags{...}composition that selects the relevant flag groups. - A
RunEthat produces aflag.Optionsand dispatches to a runner. - For scan-shaped commands, the runner is
pkg/commands/artifact/run.go.
See patterns and conventions for the boilerplate.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.