# miskovy/parallel-javascript architecture

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

- Interactive diagram: https://gitdiagram.com/miskovy/parallel-javascript
- Repository: https://github.com/miskovy/parallel-javascript

## Overview

PJS is a persistent Node worker runtime for explicitly registered CPU tasks. Its main workflow is an application registering local module exports, creating and starting a runtime, submitting work, and receiving results before shutdown. Internally, task coordination feeds bounded admission and worker dispatch; workers bootstrap registered modules and communicate through a validated message protocol. Separate capabilities handle partitioned ranges and streams, buffer ownership and result backpressure, plus diagnostics. README documents these public capabilities; some subsystem links rely on documented behavior because their implementation was not sampled.

Main entry points: [`packages/runtime/src/partition/coordinator.ts`](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/coordinator.ts) (Partition coordinator), [`packages/runtime/src/dispatch/dispatcher.ts`](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/dispatch/dispatcher.ts) (Execution dispatcher), [`packages/runtime/src/runtime.ts`](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/runtime.ts) (PjsRuntime), [`packages/runtime/src/tasks/coordinator.ts`](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/coordinator.ts) (Task coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Runtime API"]
  node_runtime["PjsRuntime<br/>[runtime.ts]"]
  node_registry["Task registry<br/>[registry.ts]"]
end

subgraph group_execution["Task Execution"]
  node_task_coord["Task coordinator<br/>[coordinator.ts]"]
  node_dispatcher["Execution dispatcher<br/>[dispatcher.ts]"]
  node_scheduler["FIFO scheduler<br/>[fifo.ts]"]
end

subgraph group_workers["Worker System"]
  node_pool["Worker pool<br/>[pool.ts]"]
  node_worker["Worker host<br/>[worker.ts]"]
  node_bootstrap["Worker bootstrap<br/>[bootstrap.ts]"]
  node_protocol["Worker protocol<br/>[protocol.ts]"]
end

subgraph group_partition["Partitioned Work"]
  node_partition_coord["Partition coordinator<br/>[coordinator.ts]"]
  node_range["Range planning<br/>[range.ts]"]
  node_operation["Range operations<br/>[operation.ts]"]
  node_stream["Range streaming<br/>[stream.ts]"]
end

subgraph group_ownership["Memory and Results"]
  node_transfer["Buffer transfer<br/>[transfer.ts]"]
  node_shared["Shared input<br/>[shared.ts]"]
  node_credits["Result credits<br/>[credit.ts]"]
end

subgraph group_diagnostics["Diagnostics"]
  node_metrics["Runtime metrics<br/>[metrics.ts]"]
  node_profile["Internal profiling<br/>[profile.ts]"]
  node_telemetry["Statistics surface<br/>[runtime.ts]"]
end

node_app(("Node application"))
node_task_modules["Registered task modules"]

node_app -->|"registers tasks"| node_registry
node_app -->|"creates and runs"| node_runtime
node_registry -->|"references exports"| node_task_modules
node_runtime -->|"snapshots registry"| node_registry
node_runtime -->|"constructs coordinator"| node_task_coord
node_runtime -->|"constructs dispatcher"| node_dispatcher
node_runtime -->|"starts range work"| node_partition_coord
node_task_coord -->|"submits tasks"| node_dispatcher
node_dispatcher -->|"schedules tasks"| node_scheduler
node_dispatcher -->|"dispatches through"| node_pool
node_pool -->|"spawns workers"| node_worker
node_worker -->|"starts bootstrap"| node_bootstrap
node_worker -->|"validates messages"| node_protocol
node_bootstrap -->|"loads task exports"| node_task_modules
node_partition_coord -->|"creates operations"| node_operation
node_partition_coord -->|"plans partitions"| node_range
node_partition_coord -->|"produces stream results"| node_stream
node_partition_coord -->|"submits child tasks"| node_task_coord
node_task_coord -->|"validates transfers"| node_transfer
node_app -->|"uses shared input"| node_shared
node_partition_coord -->|"accounts result capacity"| node_credits
node_dispatcher -->|"marks dispatch and completion"| node_credits
node_task_coord -->|"records task metrics"| node_metrics
node_dispatcher -->|"checks profiling"| node_profile
node_runtime -->|"exposes statistics"| node_telemetry
node_telemetry -->|"reads execution stats"| node_dispatcher
node_telemetry -->|"reads range stats"| node_partition_coord
node_telemetry -->|"reads task stats"| node_task_coord

click node_runtime "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/runtime.ts"
click node_registry "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/registry.ts"
click node_task_coord "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/coordinator.ts"
click node_dispatcher "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/dispatch/dispatcher.ts"
click node_scheduler "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/scheduler/fifo.ts"
click node_pool "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/pool/pool.ts"
click node_worker "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/workers/worker.ts"
click node_bootstrap "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/workers/bootstrap.ts"
click node_protocol "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/workers/protocol.ts"
click node_partition_coord "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/coordinator.ts"
click node_range "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/range.ts"
click node_operation "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/operation.ts"
click node_stream "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/stream.ts"
click node_transfer "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/transfer.ts"
click node_shared "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/shared.ts"
click node_credits "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/results/credit.ts"
click node_metrics "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/telemetry/metrics.ts"
click node_profile "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/telemetry/profile.ts"
click node_telemetry "https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/telemetry/runtime.ts"

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_runtime,node_registry toneBlue
class node_task_coord,node_dispatcher,node_scheduler toneAmber
class node_pool,node_worker,node_bootstrap,node_protocol toneMint
class node_partition_coord,node_range,node_operation,node_stream,node_task_modules toneRose
class node_transfer,node_shared,node_credits,node_app toneIndigo
class node_metrics,node_profile,node_telemetry toneTeal
```

## Components

### Runtime API

- [PjsRuntime](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/runtime.ts): `packages/runtime/src/runtime.ts`
- [Task registry](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/registry.ts): `packages/runtime/src/tasks/registry.ts`

### Task Execution

- [Task coordinator](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/coordinator.ts): `packages/runtime/src/tasks/coordinator.ts`
- [Execution dispatcher](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/dispatch/dispatcher.ts): `packages/runtime/src/dispatch/dispatcher.ts`
- [FIFO scheduler](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/scheduler/fifo.ts): `packages/runtime/src/scheduler/fifo.ts`

### Worker System

- [Worker pool](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/pool/pool.ts): `packages/runtime/src/pool/pool.ts`
- [Worker host](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/workers/worker.ts): `packages/runtime/src/workers/worker.ts`
- [Worker bootstrap](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/workers/bootstrap.ts): `packages/runtime/src/workers/bootstrap.ts`
- [Worker protocol](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/workers/protocol.ts): `packages/runtime/src/workers/protocol.ts`

### Partitioned Work

- [Partition coordinator](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/coordinator.ts): `packages/runtime/src/partition/coordinator.ts`
- [Range planning](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/range.ts): `packages/runtime/src/partition/range.ts`
- [Range operations](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/operation.ts): `packages/runtime/src/partition/operation.ts`
- [Range streaming](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/partition/stream.ts): `packages/runtime/src/partition/stream.ts`

### Memory and Results

- [Buffer transfer](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/transfer.ts): `packages/runtime/src/tasks/transfer.ts`
- [Shared input](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/tasks/shared.ts): `packages/runtime/src/tasks/shared.ts`
- [Result credits](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/results/credit.ts): `packages/runtime/src/results/credit.ts`

### Diagnostics

- [Runtime metrics](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/telemetry/metrics.ts): `packages/runtime/src/telemetry/metrics.ts`
- [Internal profiling](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/telemetry/profile.ts): `packages/runtime/src/telemetry/profile.ts`
- [Statistics surface](https://github.com/miskovy/parallel-javascript/blob/main/packages/runtime/src/telemetry/runtime.ts): `packages/runtime/src/telemetry/runtime.ts`

### Other components

- **Node application**
- **Registered task modules**

## Connections

- Node application → Task registry: registers tasks (evidence: `README.md`)
- Node application → PjsRuntime: creates and runs (evidence: `README.md`)
- Task registry → Registered task modules: references exports (evidence: `packages/runtime/src/tasks/registry.ts`)
- PjsRuntime → Task registry: snapshots registry (evidence: `packages/runtime/src/runtime.ts`)
- PjsRuntime → Task coordinator: constructs coordinator (evidence: `packages/runtime/src/runtime.ts`)
- PjsRuntime → Execution dispatcher: constructs dispatcher (evidence: `packages/runtime/src/runtime.ts`)
- PjsRuntime → Partition coordinator: starts range work (evidence: `packages/runtime/src/runtime.ts`)
- Task coordinator → Execution dispatcher: submits tasks (evidence: `packages/runtime/src/tasks/coordinator.ts`)
- Execution dispatcher → FIFO scheduler: schedules tasks (evidence: `packages/runtime/src/dispatch/dispatcher.ts`)
- Execution dispatcher → Worker pool: dispatches through (evidence: `packages/runtime/src/dispatch/dispatcher.ts`)
- Worker pool → Worker host: spawns workers (evidence: `packages/runtime/src/pool/pool.ts`)
- Worker host → Worker bootstrap: starts bootstrap (evidence: `packages/runtime/src/workers/worker.ts`)
- Worker host → Worker protocol: validates messages (evidence: `packages/runtime/src/workers/worker.ts`)
- Worker bootstrap → Registered task modules: loads task exports (evidence: `README.md`)
- Partition coordinator → Range operations: creates operations (evidence: `packages/runtime/src/partition/coordinator.ts`)
- Partition coordinator → Range planning: plans partitions (evidence: `packages/runtime/src/partition/coordinator.ts`)
- Partition coordinator → Range streaming: produces stream results (evidence: `packages/runtime/src/partition/coordinator.ts`)
- Partition coordinator → Task coordinator: submits child tasks (evidence: `packages/runtime/src/partition/coordinator.ts`)
- Task coordinator → Buffer transfer: validates transfers (evidence: `packages/runtime/src/tasks/coordinator.ts`)
- Node application → Shared input: uses shared input (evidence: `README.md`)
- Partition coordinator → Result credits: accounts result capacity (evidence: `packages/runtime/src/partition/coordinator.ts`)
- Execution dispatcher → Result credits: marks dispatch and completion (evidence: `packages/runtime/src/dispatch/dispatcher.ts`)
- Task coordinator → Runtime metrics: records task metrics (evidence: `packages/runtime/src/tasks/coordinator.ts`)
- Execution dispatcher → Internal profiling: checks profiling (evidence: `packages/runtime/src/dispatch/dispatcher.ts`)
- PjsRuntime → Statistics surface: exposes statistics (evidence: `packages/runtime/src/runtime.ts`)
- Statistics surface → Execution dispatcher: reads execution stats (evidence: `packages/runtime/src/telemetry/runtime.ts`)
- Statistics surface → Partition coordinator: reads range stats (evidence: `packages/runtime/src/telemetry/runtime.ts`)
- Statistics surface → Task coordinator: reads task stats (evidence: `packages/runtime/src/telemetry/runtime.ts`)
