Skip to content

Sendust: Architecture Overview

Status: approved design baseline at P02-005; implementation validation remains gated by downstream phases.
Authoritative constraints: requirements.
Detailed design: system design.
Decisions: ADR index.

Sendust is a two-crate Rust workspace plus a thin TypeScript package.

Consumer application (Node.js / Bun / Deno)
│ import { createTransport } from "@sendust/ts"
▼
ts/src ── public API, option shape, result/error classes, ESM+CJS entry points
│ calls generated napi exports
▼
crates/sendust-napi ── Node-API adapter: copy inputs, map errors, own async tasks
│ calls core types and functions
▼
crates/sendust-core ── validation, message model, MIME, transport state, SMTP orchestration
│ uses
▼
Sendust SMTP client (Tokio 1 + rustls) ── SMTP protocol, TLS, AUTH, DATA
│
▼
Consumer-configured SMTP relay
Boundary Responsibility Reason
TypeScript wrapper Public names, types, defaults documentation, error classes, module formats Keeps the native surface small and lets JS-facing ergonomics change without recompiling Rust
napi adapter Convert JS values to owned Rust values; convert core results/errors; schedule async work Isolates all Node-API and unsafe-adjacent code in one crate
Rust core All protocol-independent policy and all SMTP/MIME behavior Testable without Node; enforces validation, limits, lifecycle, and delivery semantics
Sendust SMTP client (native) SMTP protocol, TLS, AUTH, DATA Owns the engine on rustls/Tokio primitives (ADR-0017); lettre 0.11.23 was superseded and removed from the tree at PHASE-06

The TypeScript wrapper is deliberately thin. It validates only public shape and option compatibility that cannot be expressed in generated types. It MUST NOT reinterpret core statuses or implement SMTP/MIME policy. This prevents the two implementations from drifting.

The workspace has exactly two crates in the MVP:

  • crates/sendust-core
  • crates/sendust-napi

A separate sendust-mime or sendust-smtp crate is not justified yet: MIME and SMTP share the message model and validation policy, and splitting them would add versioning and visibility overhead without independent consumers. The boundary that matters is Node-free core, which two crates already provide. If a future transport needs to reuse core, the core API is already transport-shaped enough to extract later; that extraction is post-MVP and requires an ADR.

  1. The caller constructs a transport with relay, TLS, auth, timeout, attachment, and cap options.
  2. send(message) synchronously prepares an owned native operation, snapshots JS-owned buffers/strings, and reserves the single-send slot; synchronous preparation failures become Promise rejections.
  3. The binding schedules the owned operation on napi-managed Tokio 1.
  4. Core validates in deterministic order, composes the MIME message, enforces caps, and opens one native SMTP session.
  5. The Sendust client performs connect, TLS/required STARTTLS, AUTH, MAIL, one RCPT command per recipient, and one DATA transaction for the accepted-recipient subset.
  6. Core maps the final observable state to accepted, rejected, or unknown and closes the session.
  7. The binding converts the result or error into a stable JS object; the wrapper returns it unchanged.

No queue, worker, scheduler, queue adapter, or persistence layer exists or is planned in the current scope. No automatic retry exists at any layer. No per-recipient message fan-out exists. Queueing and scheduling remain caller-owned.

  • JavaScript values are valid only during the synchronous portion of the call.
  • Every Buffer, ArrayBuffer, typed array, and string is copied into Rust-owned memory synchronously before async work is scheduled.
  • Attachment files are read into bounded Rust-owned buffers after opt-in validation.
  • The native transport object owns the core transport and its lifecycle state.
  • JavaScript close() explicitly transitions the transport; garbage collection never closes it.
  • In-flight async work holds its own owned state and cannot borrow JS memory.

Failures are categorized before they reach JavaScript:

Category Example Public behavior
Validation Non-ASCII local part, 101 recipients, CRLF in header send() Promise rejection with stable code; transport-option validation in createTransport() is synchronous
Configuration Missing host, unsupported auth mode Synchronous createTransport() error before any network attempt
Limit Attachment > 10 MiB, wire > 30 MiB Rejection before DATA
TLS Self-signed, expired, wrong host Closed, non-retryable error
Authentication 535 Closed, non-retryable error
Protocol MAIL/DATA/final DATA refusal or all RCPT replies negative Overall rejected
Protocol One RCPT refusal in a mixed envelope That recipient is rejected; accepted subset proceeds to one DATA transaction
Protocol Abrupt close / missing final reply after DATA unknown only when final disposition cannot be established
Timeout Connect/operation/total budget exceeded Timeout category with elapsed budget
Lifecycle Send after close, concurrent send CLOSED / BUSY, no network attempt
Internal Panic or invariant violation Converted to generic internal error; never unwinds across FFI

Success means relay acceptance. An explicit negative final DATA reply is rejected; unknown is reserved for a missing/indeterminate final disposition after DATA may have reached the relay. Neither is automatically retried. See error model.

  • Certificate and hostname verification are always enabled; no bypass exists.
  • Credentials are held only in owned memory and never serialized into errors or logs.
  • Headers and envelope fields reject CRLF and control characters.
  • Attachments require explicit filesystem opt-in; only regular files are read; no URLs.
  • Caps bound recipients, attachment bytes, wire size, and close duration.
  • Panics do not cross the FFI boundary; recoverable failures use Result.

The npm package is a root package plus platform packages selected by OS/CPU/libc. Consumers install no Rust toolchain. Native artifacts are built in CI, tested on the declared matrix, and published with provenance. See distribution strategy.

The public TypeScript API is runtime-neutral. Native loading is isolated in the loader. Node-API 8 remains the shared native boundary; no separate runtime adapter or WASM fallback is added without a failing compatibility test and superseding ADR. Node.js, Bun, and Deno are required MVP runtime targets under ADR-0015, but none is claimed supported until Sendust blocking CI passes. Deno requires local node_modules and —allow-ffi. See runtime research.

Sendust is a modular monolith, not a microservice system or a crate-per-feature workspace. The installable product remains one package, the native addon remains shared, and the Rust workspace remains exactly two crates. Inside sendust-core, configuration, address, message, validation, attachments, MIME, delivery orchestration, SMTP adapter, lifecycle, and errors/results have explicit ownership. Domain modules remain independent of SMTP and runtime bindings. SMTP is isolated behind a narrow internal delivery port; it is the only MVP adapter. No public plugin registry, speculative extension points, or alternate transport is added. See ADR-0016.

11. What the architecture deliberately excludes

Section titled “11. What the architecture deliberately excludes”
  • Connection pooling and keep-alive.
  • Automatic retry, backoff, or dead-letter handling.
  • Per-recipient independent sends.
  • SMTPUTF8.
  • AbortSignal as a required mechanism.
  • URL or streamed attachments.
  • Additional transports (SES, SendGrid, etc.).
  • Templates, queues, tracking, or analytics.

Their classifications are recorded individually in the feature matrix. Queue/job orchestration and queue adapters are HELD, not post-MVP commitments; reconsideration requires a separate product decision.

Every page here is rendered from fandyajpo/sendust@v1.2.1, the source of truth. We just make it look good; fixes go there, not here.