> ## Documentation Index
> Fetch the complete documentation index at: https://docs.manthan.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# runtime

> @parmana/runtime — orchestration, the execution pipeline, and ExecutionTrustApplication

`@parmana/runtime` is the composition layer between [`policy`](/docs/packages/policy), [`storage`](/docs/packages/storage), and [`crypto`](/docs/packages/crypto). `packages/api` depends on it directly and on almost nothing else at this level — see [Packages Overview](/docs/packages/overview) for the full call chain from an HTTP request down to this package.

## Entry points

`packages/runtime/src/index.ts` exports, among others:

* **`ExecutionTrustApplication`** — the top-level orchestrator. `execute()` runs accept → execute → verify → generate receipt → return the trust record, in that order, as four sequential `await`s (not a single pipeline object).
* **`RuntimeFactory`** — `RuntimeFactory.create(transactions, trustRecords, policyRepository)` wires up all four application services (`BusinessTransactionService`, `ExecutionService`, `VerificationService`, `ReceiptService`) and a `Runtime`, and returns a ready `ExecutionTrustApplication`. This is exactly what `packages/api/src/application.ts` calls.
* **`RuntimeBuilder`** — builder used internally by `RuntimeFactory` to assemble a `Runtime` from a list of `RuntimeComponent`s plus a `PolicyRepository`.
* **`Runtime`** — a thin façade over `RuntimeEngine`; its own `execute()` persists the resulting trust record via `ExecutionTrustRecordRepository.create()`.

## What's actually in the pipeline

`RuntimeFactory.create` only adds two components to the `RuntimeBuilder`:

```ts theme={null}
new RuntimeBuilder()
  .withPolicyRepository(policyRepository)
  .addStage(new TrustChainValidationComponent())
  .addStage(new ExecutionComponent(executionService))
  .build(trustRecords);
```

<Warning>
  `packages/runtime/src/components/` also exports `VerificationComponent` and `ReceiptComponent`, but neither is added here. Verification and Receipt generation are not pipeline stages in practice — they're separate, direct method calls (`this.verification.verify(...)`, `this.receipts.generate(...)`) made by `ExecutionTrustApplication.execute()` itself, after the `Runtime`'s pipeline has already finished. If you're extending the pipeline, know that adding to `RuntimeBuilder`'s stages only affects the execution phase, not verification or receipting.
</Warning>

`RuntimeEngine` (constructed inside `RuntimeBuilder.build`) additionally composes `PolicyRouter`, `PolicyEngine` (both from [`policy`](/docs/packages/policy)), `DecisionBuilder`, `ExecutionGate`, `ExecutionBuilder`, and `ExecutionTrustPipeline` — the latter only assembles the final `ExecutionTrustRecord` from whatever's already in its `RuntimeContext` (transaction, execution, optional override/verification/receipt); it contains no business rules of its own.

## Application services

`packages/runtime/src/services/`:

| Service                      | Responsibility                                                                                                    |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `BusinessTransactionService` | Accepts and persists a new `BusinessTransaction`.                                                                 |
| `ExecutionService`           | Creates, completes, and fails `Execution` artifacts — does not evaluate policy or build Decisions itself.         |
| `VerificationService`        | Calls `VerificationCrypto.verify()` from [`crypto`](/docs/packages/crypto) and persists a `Verification`.         |
| `ReceiptService`             | Requires the latest `Verification` to be `VERIFIED`, then calls `ReceiptCrypto` to build and persist a `Receipt`. |

These are the services described in more detail in [REST API → Execute](/docs/api/execute), [Verify](/docs/api/verify), and [Receipt](/docs/api/receipt) — the routes call `ExecutionTrustApplication` methods, which call these services directly.

## Related

<CardGroup cols={2}>
  <Card title="Execution Lifecycle" href="/docs/runtime/execution-lifecycle">The domain-level version of this flow.</Card>
  <Card title="Runtime Pipeline" href="/docs/runtime/runtime-pipeline">Component-level detail, including the gap above.</Card>
  <Card title="Runtime Architecture" href="/docs/architecture/runtime-architecture">How this package fits the broader system.</Card>
  <Card title="api" href="/docs/packages/api">The only consumer of `RuntimeFactory`.</Card>
</CardGroup>
