Site search

Find architecture, research, and terms

Start typing to search the editorial index.

Production practiceAdvanced

Clean Architecture for Machine Intelligence Runtime

Apply Clean Architecture, Hexagonal Architecture, and Ports-and-Adapters principles to Machine Intelligence Runtime without placing policy, state, or authority in prompts.

Why AI needs stricter architecture, not looser architecture

AI-assisted generation and agentic coding can accelerate delivery while dissolving system boundaries. Model calls, tool calls, persistence, prompts, policy checks, and domain behavior often collapse into one script, controller, or loop. MiRuntime calls this architectural liquefaction: infrastructure and authority spread until the system has no reliable place where business truth, permissions, or lifecycle rules are enforced.

  • A raw model call inside business logic is not architecture.
  • Prompt instructions are not authorization.
  • Chat history is not a lifecycle state machine.
  • Logs without typed events are not evidence.
  • Tool descriptions are not policy.

The dependency rule remains useful because it keeps business rules independent from frameworks, databases, and provider SDKs. In MIR, that separation also prevents probabilistic output from becoming ambient authority. Source: Microsoft architecture guidance Source: Prompt-injection guidance

Clean Architecture layer mapping

Clean Architecture Layer MIR Responsibility Must Not Depend On
Domain / Entities Run, objective, risk class, approval, evidence event, tool action, memory scope, model route LLM providers, databases, web frameworks
Use Cases / Application Runtime workflows, validation, policy checks, recovery, approval orchestration Provider-specific APIs, direct SQL, prompt-only logic
Interface Adapters Model adapters, tool connectors, repositories, controllers, presenters Inner-layer implementation details
Frameworks / Drivers WordPress page, API host, queue, model server, database, object store, observability stack Runtime business rules

Logical dependency direction matters more than deployment shape. A modular monolith can follow this rule; a network of microservices can violate it.

Ports and adapters

A runtime use case should depend on interfaces defined toward the core. Concrete adapters translate those interfaces into provider SDKs, protocols, queues, stores, and observability backends.

IModelAdapterIToolConnectorIPolicyEngineIEvidenceLedgerIMemoryProjectionStoreIRuntimeStateStoreIApprovalGatewayICheckpointStore

The use case therefore does not depend on OpenAI, Anthropic, Gemini, vLLM, Triton, ONNX Runtime, PostgreSQL, Redis, Kafka, S3, or a specific cloud. Those technologies can be valid adapters; they are not the runtime’s domain model.

Deterministic boundary

What belongs outside the prompt

CredentialsPolicy decisionsApproval stateTool authorityLifecycle stateRetention rulesEvidence semanticsTenant boundaryModel routing policyRollback authority

Prompt text can describe intent to a model. It must not be the only enforcement point for any of these controls.

Capability-first organization for AI-assisted development

Traditional layer-first repositories can scatter one capability across many distant directories. Human developers may internalize that map, while coding agents repeatedly spend context on navigation and unrelated abstractions. A capability-first layout keeps a feature’s domain types, use cases, ports, adapters, tests, and intent documents close enough to load together without reversing the dependency rule.

/src
  /Runs
    /Domain
    /UseCases
    /Ports
    /Adapters
    /Tests
    AGENTS.md
  /Policies
    /Domain
    /UseCases
    /Ports
    /Adapters
    /Tests
    AGENTS.md
  /Evidence
    /Domain
    /UseCases
    /Ports
    /Adapters
    /Tests
    AGENTS.md

A root-level AGENTS.md, CLAUDE.md, or equivalent intent file should describe the architectural constitution: dependency direction, invariants, forbidden shortcuts, source-of-truth boundaries, required tests, and the controls that may never be delegated to prompt text. Capability-level files can narrow that context without weakening the root rules.

Practice status

Ports, adapters, dependency inversion, and explicit authorization are production practices. Capability-first organization for coding-agent context is an emerging practice and should be evaluated against repository size, team ownership, and tooling.

Source record

References

Suggest a correction
  1. Microsoft. Microsoft Learn. Published Current documentation; last reviewed 2026-06-23 UTC. Official architecture guidance.

  2. National Institute of Standards and Technology. NIST. Published 2023-01-26; last reviewed 2026-06-20 UTC. Government framework.

  3. OWASP GenAI Security Project. OWASP. Published 2025; last reviewed 2026-06-20 UTC. Security guidance.