# bahdotsh/wrkflw architecture

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

- Interactive diagram: https://gitdiagram.com/bahdotsh/wrkflw
- Repository: https://github.com/bahdotsh/wrkflw

## Overview

1. **Repository shape**
   - This is a Rust workspace centered on a single CLI binary, `wrkflw`, plus a set of internal libraries.
   - The workspace is organized by concern: parsing/validation, execution/runtime, UI, secrets, remote integrations, and shared models/utilities.

2. **Top-level entry point**
   - `crates/wrkflw` is the user-facing binary.
   - It exposes the main modes described in the README: interactive TUI, workflow validation, local workflow execution, and remote triggering.
   - The binary is the orchestration layer that wires together the lower-level crates.

3. **Workflow ingestion and schema handling**
   - `crates/parser` reads GitHub Actions and GitLab CI definitions and normalizes them into structured Rust types.
   - It includes bundled schemas and parser-specific logic for GitHub workflow YAML and GitLab CI YAML.
   - This is the first major boundary: raw YAML/config files become typed workflow/job definitions.

4. **Validation layer**
   - `crates/validators` performs semantic checks after parsing.
   - It has separate validation areas for jobs, steps, triggers, matrix configuration, actions, and GitLab-specific rules.
   - Validation is used both for CLI `validate` and for surfacing issues in the TUI before execution.

5. **Shared domain model**
   - `crates/models` holds the canonical types used across the workspace.
   - This crate is the contract between parser, validator, executor, and UI, preventing each subsystem from inventing its own workflow representation.

6. **Execution planning and scheduling**
   - `crates/executor` is the core workflow engine.
   - It resolves job dependencies, action substitution, environment setup, and execution ordering.
   - It is responsible for turning a workflow graph into runnable job/step work, including parallelism and dependency-aware sequencing.

7. **Action and environment resolution**
   - Within executor, the code is split into pieces for dependency handling, action resolution, substitutions, and environment management.
   - This is where special action handling lives, including local actions, composite actions, JavaScript actions, Docker-based actions, and reusable workflow caller jobs.
   - The executor is the main bridge between abstract workflow definitions and concrete runtime commands.

8. **Runtime abstraction**
   - `crates/runtime` provides the actual execution backends:
     - container-based execution,
     - secure emulation,
     - legacy emulation.
   - It also includes sandboxing and secure emulation support, which is an explicit security boundary for running untrusted workflows locally.
   - The runtime crate is where host vs container execution diverges.

9. **Container backends**
   - Container execution is split between Docker and Podman support inside `crates/executor` and `crates/runtime`.
   - The architecture treats Docker and Podman as interchangeable backends with the same workflow semantics but different process/container primitives.
   - Podman is the rootless/security-oriented option; emulation avoids container infrastructure entirely.

10. **Secrets subsystem**
   - `crates/secrets` is a separate subsystem for loading, validating, masking, storing, and substituting secrets.
   - It supports multiple providers, including environment and file-based sources.
   - The secrets manager is relevant to both execution and UI because it affects what gets injected into runs and what gets masked in logs.

11. **Remote integrations**
   - `crates/github` and `crates/gitlab` handle remote workflow/pipeline triggering.
   - These are separate from local execution: they communicate with external services and are only used for manual trigger commands.
   - The README indicates GitHub workflow dispatch and GitLab pipeline triggers are supported through these integration crates.

12. **Terminal UI**
   - `crates/ui` is a dedicated TUI application with tabs for workflows, execution, logs, and help.
   - It consumes workflow state, execution updates, and log streams, and presents them interactively.
   - The UI layer is not the executor; it observes execution state and issues commands back into the orchestration layer.

13. **Logging and log processing**
   - `crates/logging` provides shared logging support across the workspace.
   - `crates/ui/src/log_processor.rs` suggests the UI has a log ingestion/formatting path separate from core execution.
   - This creates a data flow from runtime/executor output into a normalized log stream for display and masking.

14. **Shared utilities and matrix support**
   - `crates/matrix` encapsulates matrix expansion and related job fan-out behavior.
   - `crates/utils` is general shared code used across crates.
   - Matrix expansion sits conceptually between parsing/validation and execution because it changes the job graph before scheduling.

15. **Build, release, and test architecture**
   - The repo is CI-heavy: GitHub Actions workflows, GitLab CI config, release automation, and version management scripts are all present.
   - Tests cover executor/runtime behavior, workflow fixtures, matrix behavior, reusable workflows, and security-related scenarios.
   - The presence of demo casts and fixtures shows the repository is validated as both a CLI tool and an interactive TUI product.

16. **End-to-end data flow**
   - Typical flow: file input → parser → validators → shared models → matrix/dependency resolution → executor → runtime backend → logs/outputs → UI or CLI.
   - For remote triggering, the flow bypasses local execution and goes from CLI/TUI → GitHub/GitLab API client → external service.
   - The main architectural boundary is between workflow semantics and execution backend: everything before runtime is declarative workflow processing; everything after is operational execution and presentation.

Main entry points: [`crates/executor/src/lib.rs`](https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/lib.rs) (Executor), [`crates/wrkflw/src/main.rs`](https://github.com/bahdotsh/wrkflw/blob/main/crates/wrkflw/src/main.rs) (wrkflw), [`crates/runtime/src/lib.rs`](https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/lib.rs) (Runtime), [`crates/ui/src/lib.rs`](https://github.com/bahdotsh/wrkflw/blob/main/crates/ui/src/lib.rs) (UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI orchestration"]
  node_wrkflw["wrkflw<br/>CLI binary<br/>[main.rs]"]
end

subgraph group_ingest["Workflow ingestion"]
  node_parser["Parser<br/>[lib.rs]"]
  node_validators["Validators<br/>semantic checks<br/>[lib.rs]"]
  node_models["Models<br/>domain types<br/>[lib.rs]"]
  node_matrix["Matrix<br/>fan-out<br/>[lib.rs]"]
end

subgraph group_exec["Execution engine"]
  node_executor["Executor<br/>engine<br/>[lib.rs]"]
  node_dependency["Dependencies<br/>graph planning<br/>[dependency.rs]"]
  node_action_resolver["Actions<br/>action resolution<br/>[action_resolver.rs]"]
  node_environment["Environment<br/>run context<br/>[environment.rs]"]
  node_substitution["Substitution<br/>template expansion<br/>[substitution.rs]"]
end

subgraph group_runtime["Runtime backends"]
  node_runtime["Runtime<br/>backend facade<br/>[lib.rs]"]
  node_container["Container<br/>[container.rs]"]
  node_emulation["Emulation<br/>host backend<br/>[emulation.rs]"]
  node_secure_emulation["Secure emu<br/>security boundary"]
end

subgraph group_integration["Remote integrations"]
  node_github["GitHub<br/>remote client<br/>[lib.rs]"]
  node_gitlab["GitLab<br/>remote client<br/>[lib.rs]"]
end

subgraph group_presentation["Presentation"]
  node_ui["UI<br/>[lib.rs]"]
  node_log_processor["Log processor<br/>log ingestion<br/>[log_processor.rs]"]
end

subgraph group_support["Shared support"]
  node_secrets["Secrets<br/>secret manager<br/>[lib.rs]"]
  node_logging["Logging<br/>log support<br/>[lib.rs]"]
end

node_wrkflw -->|"parse"| node_parser
node_wrkflw -->|"validate"| node_validators
node_wrkflw -->|"run"| node_executor
node_wrkflw -->|"tui"| node_ui
node_wrkflw -->|"trigger"| node_github
node_wrkflw -->|"trigger"| node_gitlab
node_parser -->|"emit"| node_models
node_parser -->|"input"| node_validators
node_validators -->|"inspect"| node_models
node_validators -->|"gate"| node_matrix
node_matrix -->|"expand"| node_models
node_models -->|"plan"| node_executor
node_executor -->|"schedule"| node_dependency
node_executor -->|"resolve"| node_action_resolver
node_executor -->|"prepare"| node_environment
node_executor -->|"expand"| node_substitution
node_executor -->|"dispatch"| node_runtime
node_runtime -->|"container"| node_container
node_runtime -->|"emulate"| node_emulation
node_emulation -->|"harden"| node_secure_emulation
node_runtime -->|"inject"| node_secrets
node_runtime -->|"emit"| node_logging
node_ui -->|"ingest"| node_log_processor
node_ui -->|"mask"| node_logging
node_ui -->|"control"| node_executor
node_github -->|"report"| node_logging
node_gitlab -->|"report"| node_logging

click node_wrkflw "https://github.com/bahdotsh/wrkflw/blob/main/crates/wrkflw/src/main.rs"
click node_parser "https://github.com/bahdotsh/wrkflw/blob/main/crates/parser/src/lib.rs"
click node_validators "https://github.com/bahdotsh/wrkflw/blob/main/crates/validators/src/lib.rs"
click node_models "https://github.com/bahdotsh/wrkflw/blob/main/crates/models/src/lib.rs"
click node_matrix "https://github.com/bahdotsh/wrkflw/blob/main/crates/matrix/src/lib.rs"
click node_executor "https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/lib.rs"
click node_dependency "https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/dependency.rs"
click node_action_resolver "https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/action_resolver.rs"
click node_environment "https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/environment.rs"
click node_substitution "https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/substitution.rs"
click node_runtime "https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/lib.rs"
click node_container "https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/container.rs"
click node_emulation "https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/emulation.rs"
click node_secure_emulation "https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/secure_emulation.rs"
click node_secrets "https://github.com/bahdotsh/wrkflw/blob/main/crates/secrets/src/lib.rs"
click node_logging "https://github.com/bahdotsh/wrkflw/blob/main/crates/logging/src/lib.rs"
click node_ui "https://github.com/bahdotsh/wrkflw/blob/main/crates/ui/src/lib.rs"
click node_log_processor "https://github.com/bahdotsh/wrkflw/blob/main/crates/ui/src/log_processor.rs"
click node_github "https://github.com/bahdotsh/wrkflw/blob/main/crates/github/src/lib.rs"
click node_gitlab "https://github.com/bahdotsh/wrkflw/blob/main/crates/gitlab/src/lib.rs"

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_wrkflw,node_secrets,node_logging toneBlue
class node_parser,node_validators,node_models,node_matrix toneAmber
class node_executor,node_dependency,node_action_resolver,node_environment,node_substitution toneMint
class node_runtime,node_container,node_emulation,node_secure_emulation toneRose
class node_github,node_gitlab toneIndigo
class node_ui,node_log_processor toneTeal
```

## Components

### CLI orchestration

User-facing entrypoint and command wiring

- [wrkflw](https://github.com/bahdotsh/wrkflw/blob/main/crates/wrkflw/src/main.rs): CLI binary · Main command-line entrypoint that orchestrates modes and subsystems · `crates/wrkflw/src/main.rs`

### Workflow ingestion

Parsing, canonical models, validation, and matrix expansion

- [Parser](https://github.com/bahdotsh/wrkflw/blob/main/crates/parser/src/lib.rs): workflow parser · Reads GitHub Actions and GitLab CI YAML into typed workflow structures · `crates/parser/src/lib.rs`
- [Validators](https://github.com/bahdotsh/wrkflw/blob/main/crates/validators/src/lib.rs): semantic checks · Applies job, step, trigger, matrix, action, and GitLab validation rules · `crates/validators/src/lib.rs`
- [Models](https://github.com/bahdotsh/wrkflw/blob/main/crates/models/src/lib.rs): domain types · Canonical workflow and job types shared across the workspace · `crates/models/src/lib.rs`
- [Matrix](https://github.com/bahdotsh/wrkflw/blob/main/crates/matrix/src/lib.rs): fan-out · Expands matrix definitions into executable job variants · `crates/matrix/src/lib.rs`

### Execution engine

Planning, resolving, and running workflows

- [Executor](https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/lib.rs): engine · Coordinates dependency resolution, substitutions, and execution order · `crates/executor/src/lib.rs`
- [Dependencies](https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/dependency.rs): graph planning · Resolves job ordering and dependency relationships · `crates/executor/src/dependency.rs`
- [Actions](https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/action_resolver.rs): action resolution · Finds and normalizes local, composite, JavaScript, Docker, and reusable workflow actions · `crates/executor/src/action_resolver.rs`
- [Environment](https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/environment.rs): run context · Builds job and step environment state for execution · `crates/executor/src/environment.rs`
- [Substitution](https://github.com/bahdotsh/wrkflw/blob/main/crates/executor/src/substitution.rs): template expansion · Interpolates workflow expressions and runtime values · `crates/executor/src/substitution.rs`

### Runtime backends

Container and emulation execution boundaries

- [Runtime](https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/lib.rs): backend facade · Abstracts container and emulation execution backends · `crates/runtime/src/lib.rs`
- [Container](https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/container.rs): container backend · Runs workloads in Docker or Podman containers · `crates/runtime/src/container.rs`
- [Emulation](https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/emulation.rs): host backend · Executes workflows without containers in emulated mode · `crates/runtime/src/emulation.rs`
- [Secure emu](https://github.com/bahdotsh/wrkflw/blob/main/crates/runtime/src/secure_emulation.rs): security boundary · Hardened emulation path for untrusted workflow execution · `crates/runtime/src/secure_emulation.rs`

### Remote integrations

External service clients for triggering workflows

- [GitHub](https://github.com/bahdotsh/wrkflw/blob/main/crates/github/src/lib.rs): remote client · Triggers GitHub workflows remotely · `crates/github/src/lib.rs`
- [GitLab](https://github.com/bahdotsh/wrkflw/blob/main/crates/gitlab/src/lib.rs): remote client · Triggers GitLab pipelines remotely · `crates/gitlab/src/lib.rs`

### Presentation

Terminal UI and log display

- [UI](https://github.com/bahdotsh/wrkflw/blob/main/crates/ui/src/lib.rs): TUI app · Interactive terminal interface for workflows, execution, and logs · `crates/ui/src/lib.rs`
- [Log processor](https://github.com/bahdotsh/wrkflw/blob/main/crates/ui/src/log_processor.rs): log ingestion · Normalizes runtime output for UI display and masking · `crates/ui/src/log_processor.rs`

### Shared support

Cross-cutting libraries used by multiple subsystems

- [Secrets](https://github.com/bahdotsh/wrkflw/blob/main/crates/secrets/src/lib.rs): secret manager · Loads, validates, masks, stores, and substitutes secrets · `crates/secrets/src/lib.rs`
- [Logging](https://github.com/bahdotsh/wrkflw/blob/main/crates/logging/src/lib.rs): log support · Shared logging and masking support across crates · `crates/logging/src/lib.rs`

## Connections

- wrkflw → Parser: parse · Loads workflow definitions before any semantic processing
- wrkflw → Validators: validate · Runs validation mode and surfaces issues
- wrkflw → Executor: run · Starts local workflow execution
- wrkflw → UI: tui · Launches interactive terminal mode
- wrkflw → GitHub: trigger · Dispatches remote GitHub workflows
- wrkflw → GitLab: trigger · Triggers remote GitLab pipelines
- Parser → Models: emit · Produces canonical workflow data structures
- Parser → Validators: input · Parsed workflows are checked semantically
- Validators → Models: inspect · Validates the shared domain model
- Validators → Matrix: gate · Matrix rules are validated before expansion
- Matrix → Models: expand · Turns canonical jobs into expanded job variants
- Models → Executor: plan · Executor consumes canonical workflow and job definitions
- Executor → Dependencies: schedule · Computes dependency-aware job ordering
- Executor → Actions: resolve · Resolves action and reusable workflow references
- Executor → Environment: prepare · Builds per-job execution environment
- Executor → Substitution: expand · Interpolates expressions and runtime values
- Executor → Runtime: dispatch · Hands runnable work to the backend runtime
- Runtime → Container: container · Uses container-based execution when available
- Runtime → Emulation: emulate · Runs workflows without container infrastructure
- Emulation → Secure emu: harden · Uses secure emulation for stricter isolation
- Runtime → Secrets: inject · Consumes secret values during execution
- Runtime → Logging: emit · Produces logs and status events
- UI → Log processor: ingest · Consumes normalized execution logs
- UI → Logging: mask · Shares logging and masking conventions
- UI → Executor: control · Issues execution commands and observes state
- GitHub → Logging: report · Uses shared logging for remote trigger operations
- GitLab → Logging: report · Uses shared logging for remote trigger operations
