# openworkers/openworkers-task-executor architecture

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

- Interactive diagram: https://gitdiagram.com/openworkers/openworkers-task-executor
- Repository: https://github.com/openworkers/openworkers-task-executor

## Overview

OpenWorkers Task Executor runs one-off or queued background tasks using the runtime backend selected at build time. The workflow starts at the CLI, NATS, or PostgreSQL queue; the executor obtains the script and payload, invokes the selected task backend, and returns or records the result. JavaScript backends lower module syntax and use native task dispatch or a fetch shim; Wasm delivers tasks through an HTTP component interface. The graph preserves the documented source and backend options. Some listener internals were only partially excerpted, so uncertain internal call paths are omitted.

Main entry points: [`src/task/mod.rs`](https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/mod.rs) (Task API), [`src/main.rs`](https://github.com/openworkers/openworkers-task-executor/blob/main/src/main.rs) (CLI and listeners), [`src/ops.rs`](https://github.com/openworkers/openworkers-task-executor/blob/main/src/ops.rs) (Fetch operations), [`src/db.rs`](https://github.com/openworkers/openworkers-task-executor/blob/main/src/db.rs) (Database listener)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Task sources"]
  node_cli["CLI and listeners<br/>[main.rs]"]
  node_nats["NATS queue"]
  node_postgres[("PostgreSQL queue")]
end

subgraph group_execution["Task execution"]
  node_task_api["Task API<br/>[mod.rs]"]
end

subgraph group_backends["Runtime backends"]
  node_native["Native task dispatch<br/>[native.rs]"]
  node_shim["Fetch task shim<br/>[shim.rs]"]
  node_wasm["Wasm component task<br/>[component.rs]"]
end

subgraph group_integrations["Operations and queues"]
  node_db_listener["Database listener<br/>[db.rs]"]
  node_fetch_ops["Fetch operations<br/>[ops.rs]"]
  node_http_services(("HTTP services"))
end

node_cli -->|"subscribes to"| node_nats
node_cli -->|"starts listener"| node_db_listener
node_cli -->|"invokes task"| node_task_api
node_db_listener -->|"claims and updates"| node_postgres
node_db_listener -->|"uses execution callback"| node_cli
node_task_api -->|"selects backend"| node_native
node_task_api -->|"selects backend"| node_shim
node_task_api -->|"selects backend"| node_wasm
node_native -->|"configures operations"| node_fetch_ops
node_shim -->|"configures operations"| node_fetch_ops
node_wasm -->|"configures operations"| node_fetch_ops
node_fetch_ops -->|"sends fetch requests"| node_http_services

click node_cli "https://github.com/openworkers/openworkers-task-executor/blob/main/src/main.rs"
click node_task_api "https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/mod.rs"
click node_native "https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/native.rs"
click node_shim "https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/shim.rs"
click node_wasm "https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/component.rs"
click node_db_listener "https://github.com/openworkers/openworkers-task-executor/blob/main/src/db.rs"
click node_fetch_ops "https://github.com/openworkers/openworkers-task-executor/blob/main/src/ops.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_cli,node_nats,node_postgres toneBlue
class node_task_api toneAmber
class node_native,node_shim,node_wasm toneMint
class node_db_listener,node_fetch_ops,node_http_services toneRose
```

## Components

### Task sources

- [CLI and listeners](https://github.com/openworkers/openworkers-task-executor/blob/main/src/main.rs): `src/main.rs`
- **NATS queue**
- **PostgreSQL queue**

### Task execution

- [Task API](https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/mod.rs): `src/task/mod.rs`

### Runtime backends

- [Native task dispatch](https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/native.rs): `src/task/native.rs`
- [Fetch task shim](https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/shim.rs): `src/task/shim.rs`
- [Wasm component task](https://github.com/openworkers/openworkers-task-executor/blob/main/src/task/component.rs): `src/task/component.rs`

### Operations and queues

- [Database listener](https://github.com/openworkers/openworkers-task-executor/blob/main/src/db.rs): `src/db.rs`
- [Fetch operations](https://github.com/openworkers/openworkers-task-executor/blob/main/src/ops.rs): `src/ops.rs`
- **HTTP services**

## Connections

- CLI and listeners → NATS queue: subscribes to (evidence: `src/main.rs`)
- CLI and listeners → Database listener: starts listener (evidence: `src/main.rs`)
- CLI and listeners → Task API: invokes task (evidence: `src/main.rs`)
- Database listener → PostgreSQL queue: claims and updates (evidence: `src/db.rs`)
- Database listener → CLI and listeners: uses execution callback (evidence: `src/main.rs`)
- Task API → Native task dispatch: selects backend (evidence: `src/task/mod.rs`)
- Task API → Fetch task shim: selects backend (evidence: `src/task/mod.rs`)
- Task API → Wasm component task: selects backend (evidence: `src/task/mod.rs`)
- Native task dispatch → Fetch operations: configures operations (evidence: `src/task/native.rs`)
- Fetch task shim → Fetch operations: configures operations (evidence: `src/task/shim.rs`)
- Wasm component task → Fetch operations: configures operations (evidence: `src/task/component.rs`)
- Fetch operations → HTTP services: sends fetch requests (evidence: `src/ops.rs`)
