Skip to content

Commit 2a0faee

Browse files
docs: add mermaid diagrams to documentation
Add accurate Mermaid diagrams that GitHub renders natively: - ARCHITECTURE.md: component/dependency diagram (cmd -> controller -> aid/dao/view -> go-tfe -> TFC API, with credentials.yaml and TFC_* env vars feeding token/org resolution) and a sequence diagram for `tecli workspace create`. - README.md: high-level request-flow overview diagram. All mermaid diagrams validated locally with mermaid-cli (3 blocks, 0 failures).
1 parent 031faa3 commit 2a0faee

2 files changed

Lines changed: 79 additions & 4 deletions

File tree

ARCHITECTURE.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,39 @@ The command framework is [Cobra](https://github.com/spf13/cobra). Configuration
1212

1313
The dependency direction flows in one direction, from the command adapters down to the API client:
1414

15-
```text
16-
cobra/cmd --> cobra/controller --> cobra/aid --> helper/, box/
17-
--> hashicorp/go-tfe
15+
```mermaid
16+
%% Component and dependency diagram
17+
flowchart TB
18+
user([You / CI pipeline])
19+
20+
subgraph cli["tecli binary"]
21+
main["main.go<br/>cmd.Execute()"]
22+
cmd["cobra/cmd<br/>thin command adapters"]
23+
controller["cobra/controller<br/>business logic, PreRunE / RunE"]
24+
aid["cobra/aid<br/>flag builders, TFE client, Viper"]
25+
dao["cobra/dao<br/>resolve org and tokens"]
26+
view["cobra/view<br/>interactive prompts"]
27+
helperbox["helper/, box/<br/>utilities and embedded manuals"]
28+
end
29+
30+
gotfe["hashicorp/go-tfe<br/>Go client"]
31+
tfc[("Terraform Cloud / Enterprise API")]
32+
33+
creds["credentials.yaml<br/>under os.UserConfigDir()"]
34+
env["TFC_* environment variables"]
35+
36+
user --> cmd
37+
main --> cmd
38+
cmd --> controller
39+
controller --> aid
40+
controller --> dao
41+
controller --> view
42+
controller --> gotfe
43+
aid --> helperbox
44+
aid --> gotfe
45+
dao --> creds
46+
env --> dao
47+
gotfe --> tfc
1848
```
1949

2050
Layers below `controller` do not import `cmd`. Layers below `aid` do not import `controller`.
@@ -46,6 +76,37 @@ A single command, such as `tecli workspace list`, flows through the layers:
4676
4. `RunE` reads the resolved token through `cobra/dao` (environment variable first, then the active profile), builds a `*tfe.Client` with `aid.GetTFEClient`, and calls the matching `go-tfe` method.
4777
5. The controller prints the API response as JSON.
4878

79+
The following sequence shows `tecli workspace create --name my-workspace`:
80+
81+
```mermaid
82+
%% Sequence for tecli workspace create
83+
sequenceDiagram
84+
actor User
85+
participant Cmd as cobra/cmd
86+
participant Ctrl as cobra/controller
87+
participant Aid as cobra/aid
88+
participant Dao as cobra/dao
89+
participant Tfe as hashicorp/go-tfe
90+
participant TFC as Terraform Cloud API
91+
92+
User->>Cmd: tecli workspace create --name my-workspace
93+
Cmd->>Ctrl: run matched command (initConfig loads Viper)
94+
Ctrl->>Ctrl: PreRunE validates argument and --name flag
95+
Ctrl->>Dao: GetOrganizationToken(profile)
96+
Dao-->>Ctrl: token (TFC_* env var, else profile)
97+
Ctrl->>Aid: GetTFEClient(token)
98+
Aid-->>Ctrl: *tfe.Client
99+
Ctrl->>Dao: GetOrganization(profile)
100+
Dao-->>Ctrl: organization
101+
Ctrl->>Aid: GetWorkspaceCreateOptions(cmd)
102+
Aid-->>Ctrl: tfe.WorkspaceCreateOptions
103+
Ctrl->>Tfe: Workspaces.Create(ctx, organization, options)
104+
Tfe->>TFC: POST /organizations/{org}/workspaces
105+
TFC-->>Tfe: workspace JSON
106+
Tfe-->>Ctrl: *tfe.Workspace
107+
Ctrl-->>User: print workspace as JSON
108+
```
109+
49110
## Design decisions
50111

51112
- **Thin wrapper over `go-tfe`.** TECLI does not reimplement Terraform Cloud logic. Each command maps to one `go-tfe` call, so the output mirrors the API response. Upgrading `go-tfe` is the main way new API behavior reaches the CLI.

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,21 @@ The `configure` command reads and writes the credentials file only. It does not
174174

175175
## Architecture
176176

177-
TECLI is a thin command-line wrapper around `hashicorp/go-tfe`. The `main` package calls `cmd.Execute()`, which builds a Cobra command tree. Each command validates flags, marshals them into `go-tfe` option structs, calls the Terraform Cloud API, and prints the JSON response. For components, data flow, and design decisions, see [ARCHITECTURE.md](ARCHITECTURE.md).
177+
TECLI is a thin command-line wrapper around `hashicorp/go-tfe`. The `main` package calls `cmd.Execute()`, which builds a Cobra command tree. Each command validates flags, marshals them into `go-tfe` option structs, calls the Terraform Cloud API, and prints the JSON response.
178+
179+
```mermaid
180+
%% High-level request flow
181+
flowchart LR
182+
user([You / CI pipeline]) --> cli["tecli<br/>Cobra command"]
183+
cli --> resolve["Resolve org and token<br/>TFC_* env vars, then profile"]
184+
config[("credentials.yaml<br/>+ TFC_* env vars")] --> resolve
185+
resolve --> gotfe["hashicorp/go-tfe<br/>client"]
186+
gotfe --> tfc[("Terraform Cloud /<br/>Enterprise API")]
187+
tfc --> gotfe
188+
gotfe --> out["JSON response<br/>printed to stdout"]
189+
```
190+
191+
For components, data flow, and design decisions, see [ARCHITECTURE.md](ARCHITECTURE.md).
178192

179193
## Troubleshooting
180194

0 commit comments

Comments
 (0)