DNA Architectural Engineering Standard

This document defines the architectural engineering standard for DNA organisms and the DNA runtime itself. While individual Hale language features…

This document defines the architectural engineering standard for DNA organisms and the DNA runtime itself. While individual Hale language features (surfaces, topics, effect classes, units, constitutional claims) are opt-in for general-purpose programs, a distributed DNA organism requires uniform conventions across every process so the compiler can verify cross-process contracts, authority boundaries, memory bounds, and units end to end.

Core Principle

Section titled “Core Principle”

Every boundary crossing must be declared in source code and statically checked by the compiler. In DNA, boundaries include process boundaries, locus ownership boundaries, authority/principal transitions, physical/monetary units of measure, and secret material.

Summary Matrix: Today vs. Roadmap

Section titled “Summary Matrix: Today vs. Roadmap”
Domain Rule Status in dna/ Today
Structure Single locus tree per program (accept / dissolve lifecycle) Enforced Today (dna::Dna tower; workflows/tasks/steps are accepted children)
Structure Thread and pool placement via placement { } on main locus Enforced Today (host, head, reflexes, and generated dna/org)
Structure Multi-process composition via fleet locus (hale fleet check) Roadmap Goal (bindings currently duplicated across host and dna/org)
Boundaries Inter-process RPC via api surfaces (api::serve + hale api client) Partial (HeadCommands mutations use api; head reads and face client are a Roadmap Goal)
Boundaries External system calls via consumed api::client surfaces Enforced Today (spec/api.md § Calling a surface)
Boundaries Asynchronous events via typed topic declarations and bindings { } Enforced Today in dna/core/topics.hl (~50 topics); typed heart events are a Roadmap Goal
Boundaries Committed OpenAPI/MCP/Schema/client artifacts verified by tests Enforced Today in the reference todo application
Boundaries Surface and interface failures declared with fallible(E) Roadmap Goal (head commands currently return {ok, code}; awaits fallible interface methods)
Data Record rows defined as typed structs with json tags Roadmap Goal (rows are currently built and parsed as raw JSON strings)
Data Closed string sets represented as enum types Roadmap Goal
Data Currency as Decimal, time as Time/Duration, measures as quantity Roadmap Goal (spend is currently integer micro-dollars; timestamps are Int)
Data Boundary lists typed as bounded[T; N] or collection loci Roadmap Goal (currently passed as newline-delimited strings)
Authority Shared base constitution ([claims] base) across all programs Partial (dna/org/law.hl is checked under no_base; host/head/reflexes/face are a Roadmap Goal)
Authority Direct OS syscalls attributed via require attributed(all syscall) Partial (dna/core/types.hl annotates core carriers; host/head binaries are a Roadmap Goal)
Authority Record projections marked @no_syscall and @deterministic Partial (1 projection annotated today; remaining projections are a Roadmap Goal)
Authority Secrets confined to @sealed loci via std::secret Enforced Today for model keys and NATS passwords; provisioning/DB/forge tokens are a Roadmap Goal
Authority Principal tracking via runs_under(locus, principal) Roadmap Goal
Resources All long-lived allocations proven with @bounded_by(<input>) Enforced Today across all of dna/ (270 functions annotated, zero @unbounded, gated by hale verify)
Resources Health/readiness/capacity served via std::observe::Probes Roadmap Goal for dna/ binaries (supported by the runtime today)
Quality Verification pipeline reads structured JSON output from hale tools Partial (dna/core/verification.hl runs the suite; hale test --json and facet topology diffing are a Roadmap Goal)
Quality hale verify zero-finding CI gate Enforced Today on dna/core, dna/host, dna/host/verb, dna/operations, and dna/api
Quality API surfaces tested via std::api::test::Rpc and models via FakeModel / RecordedModel Enforced Today
Observability Unified metrics via std::metrics and structured logs via std::log Roadmap Goal (standard nursery pack proposes structured logging as law)

1. Structure: One Locus Tree and One Fleet Plan

Section titled “1. Structure: One Locus Tree and One Fleet Plan”

Single Locus Tree per Process

Section titled “Single Locus Tree per Process”

Every program is structured as a single locus hierarchy where child components are declared as params, dynamic per-request or per-execution units are spawned via accept and reclaimed on dissolve, and structural failures route upward to the parent’s on_failure handler (spec/semantics.md § Locus instantiation).

Placement on main locus

Section titled “Placement on main locus”

Thread pools, core pinning, and worker replicas are declared exclusively in the placement { } block on the main locus—never via ad-hoc threading calls or CLI flags.

Multi-Process Composition via fleet locus

Section titled “Multi-Process Composition via fleet locus”

All processes of an organism (host, organization, head, application heart, and reflexes) should be declared as instances inside a single fleet locus whose bindings wire inter-process topics, verified by hale fleet check and rendered by deployment backends.


2. Boundaries: Typed Surfaces and Topics

Section titled “2. Boundaries: Typed Surfaces and Topics”

Inter-Process RPC via api Surfaces

Section titled “Inter-Process RPC via api Surfaces”

Every synchronous call between processes is declared on an api surface, served via api::serve over the configured transport (unix::Rpc, http::Rpc, mcp::Rpc) with role guards on each operation, and called through generated clients (hale api client) verified in CI.

External Calls via Consumed api::client Surfaces

Section titled “External Calls via Consumed api::client Surfaces”

Calls to external services use an api NAME from openapi|mcp declaration imported via hale api import (or a peer Hale surface) and invoked through a typed api::client(NAME, http::Client { … } | mcp::Client { … }) parameter backed by vault credentials.

Events via Declared Topics and Adapters

Section titled “Events via Declared Topics and Adapters”

Asynchronous events between components use typed topic declarations bound on main locus via bindings { T: Adapter }, using keyed_by subscriptions to filter traffic at the bus layer.

Generated Machine Artifacts and fallible(E) Handlers

Section titled “Generated Machine Artifacts and fallible(E) Handlers”

3. Data: Explicit Types, Enums, and Units

Section titled “3. Data: Explicit Types, Enums, and Units”

4. Authority: Constitutions, Attributed Effects, and @sealed Secrets

Section titled “4. Authority: Constitutions, Attributed Effects, and @sealed Secrets”

Shared Base Constitution

Section titled “Shared Base Constitution”

Every program in an organism should adopt a constitution in hale.toml over a shared base ([claims] base = "…"), using dna/org/law.hl as the foundational law.

Attributed OS Syscalls (require attributed(all syscall))

Section titled “Attributed OS Syscalls (require attributed(all syscall))”

Every function that directly invokes a built-in syscall effect must carry a domain-specific @effects(is: { … }) annotation so constitutional claims (forbid reaches(…)) can constrain why a boundary is crossed, not just where.

Pure Record Projections (@no_syscall, @deterministic)

Section titled “Pure Record Projections (@no_syscall, @deterministic)”

Functions that project state from record rows must be marked @no_syscall (and @deterministic where applicable) to guarantee deterministic replay.

Secret Confinement (@sealed and std::secret)

Section titled “Secret Confinement (@sealed and std::secret)”

Secrets are held exclusively inside @sealed loci via std::secret and revealed only inside the expression that writes to the wire—never read from environment variables into String bindings or passed on child process command lines.

Principal Tracking (runs_under)

Section titled “Principal Tracking (runs_under)”

Associating loci with runtime principals (runs_under(locus, principal)) to project backend ACLs (Postgres roles, NATS accounts, Vault policies) directly from the compiler graph is a Roadmap Goal (The habitat, as designed).


5. Resources: Proven Memory Bounds and Health Probes

Section titled “5. Resources: Proven Memory Bounds and Health Probes”

Memory-Bound Proofs (@bounded_by)

Section titled “Memory-Bound Proofs (@bounded_by)”

Because DNA daemons run continuously for months over arena-allocated loci, every growing allocation flagged by the compiler’s memory-bound survey must be either refactored to run in a per-iteration helper method (whose scratch arena reclaims on return) or explicitly proven bounded with @bounded_by(<input>):

Runtime Health and Capacity Probes (std::observe::Probes)

Section titled “Runtime Health and Capacity Probes (std::observe::Probes)”

Long-lived programs attach std::observe::Probes { port } on their main locus to expose liveness, readiness, and arena/queue capacity from runtime telemetry (Observing a program).


6. Quality Gates, Observability, and Project Layout

Section titled “6. Quality Gates, Observability, and Project Layout”

Automated Toolchain Gates (hale verify)

Section titled “Automated Toolchain Gates (hale verify)”

Candidate verification (dna/core/verification.hl) runs hale fmt --check, hale check, hale verify, hale test, hale fleet check, and hale model diff.

Unified Metrics and Structured Logging

Section titled “Unified Metrics and Structured Logging”

Standard Directory Layout

Section titled “Standard Directory Layout”