# fgm/envrun architecture

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

- Interactive diagram: https://gitdiagram.com/fgm/envrun
- Repository: https://github.com/fgm/envrun

## Overview

envrun is a small environment-file loader and command launcher. Its principal workflow parses CLI arguments, loads and validates one required environment file, merges its variables beneath inherited values, then starts the requested command. Unix replaces envrun with that command; other supported platforms supervise it. A separate Go library path lets applications apply the same file rules to their own process. The graph follows documented behavior and shown calls; some internal loader links are omitted where the excerpts do not show the call site.

Main entry points: [`main.go`](https://github.com/fgm/envrun/blob/main/main.go) (Run coordinator), [`env/env.go`](https://github.com/fgm/envrun/blob/main/env/env.go) (File loading), [`exec_unix.go`](https://github.com/fgm/envrun/blob/main/exec_unix.go) (Unix exec), [`exec_other.go`](https://github.com/fgm/envrun/blob/main/exec_other.go) (Supervised exec)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_launcher["Command launcher"]
  node_cli["Argument parsing<br/>[main.go]"]
  node_coordinator["Run coordinator<br/>[main.go]"]
end

subgraph group_envlib["Environment library"]
  node_fileload["File loading<br/>[env.go]"]
  node_parser["File parser<br/>[env.go]"]
  node_parseerrors["Parse errors<br/>[errors.go]"]
  node_vars["Variable sets<br/>[env.go]"]
  node_apply["Library Apply<br/>[env.go]"]
  node_export["Process export<br/>[env.go]"]
end

subgraph group_execution["Process execution"]
  node_unixexec["Unix exec<br/>[exec_unix.go]"]
  node_otherexec["Supervised exec<br/>[exec_other.go]"]
end

node_user(("CLI user"))
node_inherited["Inherited environment"]
node_target(("Requested command"))

node_user -->|"provides arguments"| node_cli
node_cli -->|"returns options"| node_coordinator
node_coordinator -->|"loads file"| node_fileload
node_fileload -->|"parses contents"| node_parser
node_parser -->|"reports problems"| node_parseerrors
node_fileload -->|"returns variables"| node_vars
node_coordinator -->|"reads environment"| node_inherited
node_coordinator -->|"merges variables"| node_vars
node_coordinator -->|"dispatches to"| node_unixexec
node_coordinator -->|"dispatches to"| node_otherexec
node_unixexec -->|"replaces process"| node_target
node_otherexec -->|"starts child"| node_target
node_vars -->|"supplies environment"| node_unixexec
node_vars -->|"supplies environment"| node_otherexec
node_user -->|"imports library"| node_apply
node_apply -->|"loads file"| node_fileload
node_apply -->|"applies variables"| node_export
node_export -->|"sets process environment"| node_inherited

click node_cli "https://github.com/fgm/envrun/blob/main/main.go"
click node_coordinator "https://github.com/fgm/envrun/blob/main/main.go"
click node_fileload "https://github.com/fgm/envrun/blob/main/env/env.go"
click node_parser "https://github.com/fgm/envrun/blob/main/env/env.go"
click node_parseerrors "https://github.com/fgm/envrun/blob/main/env/errors.go"
click node_vars "https://github.com/fgm/envrun/blob/main/env/env.go"
click node_apply "https://github.com/fgm/envrun/blob/main/env/env.go"
click node_export "https://github.com/fgm/envrun/blob/main/env/env.go"
click node_unixexec "https://github.com/fgm/envrun/blob/main/exec_unix.go"
click node_otherexec "https://github.com/fgm/envrun/blob/main/exec_other.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_cli,node_coordinator,node_user toneBlue
class node_fileload,node_parser,node_parseerrors,node_vars,node_apply,node_export toneAmber
class node_unixexec,node_otherexec,node_target toneMint
class node_inherited toneIndigo
```

## Components

### Command launcher

- [Argument parsing](https://github.com/fgm/envrun/blob/main/main.go): `main.go`
- [Run coordinator](https://github.com/fgm/envrun/blob/main/main.go): `main.go`

### Environment library

- [File loading](https://github.com/fgm/envrun/blob/main/env/env.go): `env/env.go`
- [File parser](https://github.com/fgm/envrun/blob/main/env/env.go): `env/env.go`
- [Parse errors](https://github.com/fgm/envrun/blob/main/env/errors.go): `env/errors.go`
- [Variable sets](https://github.com/fgm/envrun/blob/main/env/env.go): `env/env.go`
- [Library Apply](https://github.com/fgm/envrun/blob/main/env/env.go): `env/env.go`
- [Process export](https://github.com/fgm/envrun/blob/main/env/env.go): `env/env.go`

### Process execution

- [Unix exec](https://github.com/fgm/envrun/blob/main/exec_unix.go): `exec_unix.go`
- [Supervised exec](https://github.com/fgm/envrun/blob/main/exec_other.go): `exec_other.go`

### Other components

- **CLI user**
- **Inherited environment**
- **Requested command**

## Connections

- CLI user → Argument parsing: provides arguments (evidence: `README.md`)
- Argument parsing → Run coordinator: returns options (evidence: `main.go`)
- Run coordinator → File loading: loads file (evidence: `main.go`)
- File loading → File parser: parses contents (evidence: `env/env.go`)
- File parser → Parse errors: reports problems (evidence: `env/errors.go`)
- File loading → Variable sets: returns variables (evidence: `env/env.go`)
- Run coordinator → Inherited environment: reads environment (evidence: `main.go`)
- Run coordinator → Variable sets: merges variables (evidence: `main.go`)
- Run coordinator → Unix exec: dispatches to (evidence: `exec_unix.go`)
- Run coordinator → Supervised exec: dispatches to (evidence: `exec_other.go`)
- Unix exec → Requested command: replaces process (evidence: `exec_unix.go`)
- Supervised exec → Requested command: starts child (evidence: `exec_other.go`)
- Variable sets → Unix exec: supplies environment (evidence: `exec_unix.go`)
- Variable sets → Supervised exec: supplies environment (evidence: `exec_other.go`)
- CLI user → Library Apply: imports library
- Library Apply → File loading: loads file (evidence: `env/env.go`)
- Library Apply → Process export: applies variables (evidence: `env/env.go`)
- Process export → Inherited environment: sets process environment (evidence: `env/env.go`)
