# fieldryand/goflow architecture

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

- Interactive diagram: https://gitdiagram.com/fieldryand/goflow
- Repository: https://github.com/fieldryand/goflow

## Overview

#### Purpose and Entry Points
Goflow is an embeddable Go DAG scheduler with a REST/SSE monitoring API and optional browser dashboard. Consumers construct an engine, register code-defined jobs, add middleware/handlers, then start the HTTP service through `Goflow.Run`. Core public construction and lifecycle are in `goflow.go`; a runnable usage reference is `example/goflow-example.go`.

#### Workflow Model and DAG Validation
A `Job` owns named `Task` nodes, schedule/active state, and dependency definitions. Tasks reference an `Operator`, retry policy, and trigger rule. DAG construction and dependency traversal/validation are centralized in `job.go` and `dag.go`; task state and execution settings live in `task.go`. The scheduler boundary is explicitly DAG-based: downstream work is released or skipped according to upstream outcomes and trigger rules.

#### Scheduling and Execution
The engine maintains registered jobs, applies cron schedules, accepts manual submissions, and coordinates concurrent runs. `execution.go` represents/persists job execution state, while `goflow.go` owns engine startup and job registration. A run executes ready tasks concurrently, records outcomes, retries failures using configured delays, and determines terminal job status from task results.

#### Operator Boundary
`Operator` is the extension point for actual workload execution: user-defined operators implement the execution contract, separating orchestration from domain work. Built-in command and HTTP operators are defined in `operator.go`; retry strategies and shared execution behavior are in `utils.go`. Operators may invoke local shell commands or external HTTP services, so task code is the primary boundary for side effects.

#### Persistence and Recovery
Execution history is stored through a pluggable `gokv.Store`; the default is in-memory, while callers can supply Redis, PostgreSQL-backed, S3, or other gokv-compatible storage. Persistence-facing execution logic is in `execution.go`, with engine store configuration in `goflow.go`. This enables history/recovery across restarts without coupling the scheduler to a specific database.

#### HTTP API, Streaming, and UI
Gin is the HTTP runtime. API routing covers health, job inspection/submission/schedule toggling, and execution queries in `routes.go`; the API contract is documented by `swagger.json`. Optional SSE streaming pushes execution updates to clients through `stream.go`. When configured with a UI path, Go serves the dashboard templates/assets from `ui/html/index.html.tmpl`, `ui/html/job.html.tmpl`, and the bundled frontend source `ui/src/index.js`.

#### Packaging and Deployment
The service runs as a single Go binary or container. `Dockerfile` defines image packaging, and `.github/workflows/deploy-image.yml` publishes deployment images. The example compose setup at `example/docker-compose.yml` demonstrates containerized operation with PostgreSQL-oriented integration.

Main entry points: [`execution.go`](https://github.com/fieldryand/goflow/blob/main/execution.go) (Execution coordinator), [`goflow.go`](https://github.com/fieldryand/goflow/blob/main/goflow.go) (Goflow engine), [`routes.go`](https://github.com/fieldryand/goflow/blob/main/routes.go) (Gin REST API), [`job.go`](https://github.com/fieldryand/goflow/blob/main/job.go) (Job & DAG model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Scheduler Core"]
  node_engine["Goflow engine<br/>lifecycle &amp; registry<br/>[goflow.go]"]
  node_job["Job &amp; DAG model<br/>workflow definition<br/>[job.go]"]
  node_dag["DAG traversal<br/>dependency validation<br/>[dag.go]"]
  node_task["Task model<br/>execution settings<br/>[task.go]"]
  node_execution["Execution coordinator<br/>run state &amp; scheduler<br/>[execution.go]"]
end

subgraph group_extensions["Extensions &amp; Storage"]
  node_operator{{"Operator boundary<br/>workload contract<br/>[operator.go]"}}
  node_execution_utils["Retry behavior<br/>execution utilities<br/>[utils.go]"]
  node_store[("gokv store<br/>pluggable persistence")]
  node_side_effects(("Shell / HTTP targets<br/>external workloads"))
end

subgraph group_service["Service Interface"]
  node_http_api["Gin REST API<br/>routes<br/>[routes.go]"]
  node_api_contract["API contract<br/>OpenAPI document<br/>[swagger.json]"]
  node_sse["SSE updates<br/>event stream<br/>[stream.go]"]
  node_dashboard["Browser dashboard<br/>optional UI<br/>[index.html.tmpl]"]
  node_frontend["Dashboard frontend<br/>browser source<br/>[index.js]"]
end

subgraph group_delivery["Packaging"]
  node_container["Container image<br/>Docker packaging"]
  node_image_publish["Image publishing<br/>CI workflow<br/>[deploy-image.yml]"]
  node_compose_example["Compose integration<br/>deployment example<br/>[docker-compose.yml]"]
end

node_consumer(("Embedding consumer<br/>Go application"))
node_example["Runnable example<br/>example app<br/>[goflow-example.go]"]

node_consumer -->|"embeds and configures"| node_engine
node_example -->|"demonstrates"| node_engine
node_engine -->|"registers"| node_job
node_job -->|"validates dependencies"| node_dag
node_job -->|"owns named tasks"| node_task
node_engine -->|"schedules and submits runs"| node_execution
node_execution -->|"releases or skips downstream work"| node_dag
node_execution -->|"runs ready tasks"| node_task
node_task -->|"selects workload"| node_operator
node_execution -->|"applies retry delays"| node_execution_utils
node_operator -->|"executes"| node_side_effects
node_execution -->|"persists run state"| node_store
node_engine -->|"starts HTTP service"| node_http_api
node_http_api -.->|"documents"| node_api_contract
node_http_api -->|"exposes updates"| node_sse
node_execution -->|"publishes status changes"| node_sse
node_http_api -->|"serves optionally"| node_dashboard
node_dashboard -->|"loads"| node_frontend
node_container -->|"packages service"| node_engine
node_image_publish -->|"publishes"| node_container
node_compose_example -->|"runs"| node_container
node_compose_example -.->|"uses persistent backend"| node_store

click node_example "https://github.com/fieldryand/goflow/blob/main/example/goflow-example.go"
click node_engine "https://github.com/fieldryand/goflow/blob/main/goflow.go"
click node_job "https://github.com/fieldryand/goflow/blob/main/job.go"
click node_dag "https://github.com/fieldryand/goflow/blob/main/dag.go"
click node_task "https://github.com/fieldryand/goflow/blob/main/task.go"
click node_execution "https://github.com/fieldryand/goflow/blob/main/execution.go"
click node_operator "https://github.com/fieldryand/goflow/blob/main/operator.go"
click node_execution_utils "https://github.com/fieldryand/goflow/blob/main/utils.go"
click node_http_api "https://github.com/fieldryand/goflow/blob/main/routes.go"
click node_api_contract "https://github.com/fieldryand/goflow/blob/main/swagger.json"
click node_sse "https://github.com/fieldryand/goflow/blob/main/stream.go"
click node_dashboard "https://github.com/fieldryand/goflow/blob/main/ui/html/index.html.tmpl"
click node_frontend "https://github.com/fieldryand/goflow/blob/main/ui/src/index.js"
click node_container "https://github.com/fieldryand/goflow/blob/main/Dockerfile"
click node_image_publish "https://github.com/fieldryand/goflow/blob/main/.github/workflows/deploy-image.yml"
click node_compose_example "https://github.com/fieldryand/goflow/blob/main/example/docker-compose.yml"

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_engine,node_job,node_dag,node_task,node_execution toneBlue
class node_operator,node_execution_utils,node_store,node_side_effects toneAmber
class node_http_api,node_api_contract,node_sse,node_dashboard,node_frontend toneMint
class node_container,node_image_publish,node_compose_example toneRose
class node_consumer,node_example toneNeutral
```

## Components

### Scheduler Core

DAG orchestration and execution lifecycle.

- [Goflow engine](https://github.com/fieldryand/goflow/blob/main/goflow.go): lifecycle & registry · Registers jobs, configures storage, and starts the service. · `goflow.go`
- [Job & DAG model](https://github.com/fieldryand/goflow/blob/main/job.go): workflow definition · Owns tasks, dependencies, schedules, and validation. · `job.go`
- [DAG traversal](https://github.com/fieldryand/goflow/blob/main/dag.go): dependency validation · Determines dependency traversal and release eligibility. · `dag.go`
- [Task model](https://github.com/fieldryand/goflow/blob/main/task.go): execution settings · Defines operator, retry policy, and trigger rule. · `task.go`
- [Execution coordinator](https://github.com/fieldryand/goflow/blob/main/execution.go): run state & scheduler · Coordinates concurrent tasks, retries, and terminal status. · `execution.go`

### Extensions & Storage

Workload and persistence boundaries.

- [Operator boundary](https://github.com/fieldryand/goflow/blob/main/operator.go): workload contract · Built-in command and HTTP operators execute task work. · `operator.go`
- [Retry behavior](https://github.com/fieldryand/goflow/blob/main/utils.go): execution utilities · `utils.go`
- **gokv store**: pluggable persistence · Stores execution history for recovery across restarts.
- **Shell / HTTP targets**: external workloads

### Service Interface

HTTP monitoring, streaming, and dashboard.

- [Gin REST API](https://github.com/fieldryand/goflow/blob/main/routes.go): routes · Exposes health, jobs, submissions, schedules, and executions. · `routes.go`
- [API contract](https://github.com/fieldryand/goflow/blob/main/swagger.json): OpenAPI document · `swagger.json`
- [SSE updates](https://github.com/fieldryand/goflow/blob/main/stream.go): event stream · Pushes execution updates to connected clients. · `stream.go`
- [Browser dashboard](https://github.com/fieldryand/goflow/blob/main/ui/html/index.html.tmpl): optional UI · Served when a UI path is configured. · `ui/html/index.html.tmpl`
- [Dashboard frontend](https://github.com/fieldryand/goflow/blob/main/ui/src/index.js): browser source · `ui/src/index.js`

### Packaging

Container build and publishing.

- [Container image](https://github.com/fieldryand/goflow/blob/main/Dockerfile): Docker packaging · `Dockerfile`
- [Image publishing](https://github.com/fieldryand/goflow/blob/main/.github/workflows/deploy-image.yml): CI workflow · `.github/workflows/deploy-image.yml`
- [Compose integration](https://github.com/fieldryand/goflow/blob/main/example/docker-compose.yml): deployment example · Demonstrates PostgreSQL-oriented container operation. · `example/docker-compose.yml`

### Other components

- **Embedding consumer**: Go application · Constructs and configures the engine.
- [Runnable example](https://github.com/fieldryand/goflow/blob/main/example/goflow-example.go): example app · `example/goflow-example.go`

## Connections

- Embedding consumer → Goflow engine: embeds and configures
- Runnable example → Goflow engine: demonstrates
- Goflow engine → Job & DAG model: registers
- Job & DAG model → DAG traversal: validates dependencies
- Job & DAG model → Task model: owns named tasks
- Goflow engine → Execution coordinator: schedules and submits runs
- Execution coordinator → DAG traversal: releases or skips downstream work
- Execution coordinator → Task model: runs ready tasks
- Task model → Operator boundary: selects workload
- Execution coordinator → Retry behavior: applies retry delays
- Operator boundary → Shell / HTTP targets: executes
- Execution coordinator → gokv store: persists run state
- Goflow engine → Gin REST API: starts HTTP service
- Gin REST API → API contract: documents
- Gin REST API → SSE updates: exposes updates
- Execution coordinator → SSE updates: publishes status changes
- Gin REST API → Browser dashboard: serves optionally
- Browser dashboard → Dashboard frontend: loads
- Container image → Goflow engine: packages service
- Image publishing → Container image: publishes
- Compose integration → Container image: runs
- Compose integration → gokv store: uses persistent backend
