← All Blogs

February 22, 2026

AI Is Not a Rewrite — It Is a Dependency

Most AI content today assumes one of two extremes: either you are training models, or you are prompting ChatGPT. Neither reflects how real production systems adopt AI.

For senior backend developers, AI is best treated as a volatile external dependency that must be controlled, governed, and isolated. This article explains how to plan AI programming when you own production systems, care about uptime, security, and audits, and cannot afford architectural regressions.


The Mental Shift: From "AI Features" to "AI Capabilities"

Traditional feature development follows a simple rule: deterministic input produces deterministic output. AI-enabled development breaks that contract — deterministic input now produces a probabilistic suggestion. That single difference changes everything: validation, security, persistence, testing, and ownership.

AI may suggest. Your domain must decide.


Stack Selection: Why Backend-First Still Wins

Choose your stack based on production responsibility, not AI trend velocity.

Recommended Stack (Enterprise-Ready)

LayerTechnologyWhy
API & Core.NET / JavaStrong typing, security, maturity
DomainClean Architecture + DDDDeterministic business logic
AI AccessSDK-based (OpenAI / Azure OpenAI)Replaceable inference
RetrievalSQL + Vector StoreStructured + semantic
AsyncMessage queuesCost & latency control
UITypeScriptAI interaction surfaces
PythonOptional, isolatedExperiments only

Python excels at research, prototyping, and exploration. Production systems require stability, governance, and clear ownership. Most companies consume AI — they do not invent it.


Clean Architecture for AI Systems

AI must sit outside your domain.

Clients / UI
    ↓
API Layer
    ↓         ↓
AI Orchestration   Domain Layer
    ↓                  ↓
LLM Provider      Infrastructure

If your domain depends on AI, you lose testability, auditability, and trust. AI changes fast. Domains must not.


Domain-Driven Design: How AI Fits (and How It Must Not)

AI belongs to application services, orchestration, and advisory logic. It must never create aggregates, persist entities, or bypass invariants.

Example:

AI: "This order should be refunded"

Domain:
  - RefundPolicy.Evaluate(context)
  - Raises RefundProposed event
  - Human or workflow approves

AI produces context, not commands.


AI-Oriented Application Layer

Your application layer becomes responsible for prompt versioning, model selection, token budgeting, tool exposure, and output validation.

Application/
 ├─ AI/
 │   ├─ Prompts/
 │   ├─ Pipelines/
 │   ├─ Policies/
 │   └─ OutputSchemas/

AI output must be parsed, schema-validated, and rejected if unsafe. Never trust free-form text.


Retrieval-Augmented Generation (RAG): The Production Way

RAG is not "search + AI." Production RAG requires tenant isolation, domain filtering, and traceability. The mandatory constraints are clear: no cross-tenant embeddings, no raw documents in prompts, and no direct database writes from AI.


Asynchronous AI: The Default, Not the Exception

AI is slow, expensive, and rate-limited. Therefore, AI calls belong in background jobs, message-driven pipelines, and idempotent handlers:

Event → AI Handler → Result Event

If AI fails, your system must still work.


Governance: Why Companies Say "Yes" to AI in Production

Most AI proofs of concept fail not technically, but organizationally. Companies require three things.

Observability — token usage per tenant, cost per request, latency per model, and failure rates.

Auditability — who requested AI, what data scope was used, which model answered, and which prompt version was active.

Control — feature flags, kill switches, model fallback, and rate limits.

If you cannot turn AI off safely, it will not ship.


Security: AI-Specific Threat Model

Traditional security is insufficient. You must also address prompt injection, data leakage, tool abuse, over-permissioned context, and output manipulation.

Production safeguards include: AI access only via the backend, explicit tool whitelisting, context minimization, output schema enforcement, and role-based retrieval filters.

Treat AI endpoints like payment APIs, not search boxes.


How Companies Actually Accept AI in Production

Organizations approve AI when domain logic remains deterministic, AI is observable and auditable, costs are predictable, failures are contained, and humans can override decisions.

They reject AI when it bypasses rules, writes data directly, or cannot be explained.


Runtime Request Flow

Every AI-enabled request follows a predictable sequence through the system. Understanding this flow is essential for debugging, auditing, and designing reliable pipelines.

User Action
  → ASP.NET Core API
      → Auth + Tenant Resolution
      → Input Validation
      → AI Orchestrator
          → (Optional) RAG Retrieval
          → LLM Call
          → Structured AI Result
      → Domain Validation
      → Domain Event / Response
  → Client

Notice that domain validation always happens after the AI result is returned — never before, and never inside the AI orchestrator. The domain has the final word.


Translating Architecture into a Real .NET Solution

The layered architecture maps directly to a concrete folder structure. This is not theoretical — it is how you should structure your solution from day one.

src/
├─ Presentation/
│   └─ Api/
├─ Application/
│   ├─ AiOrchestration/
│   ├─ Pipelines/
│   └─ Policies/
├─ Domain/
│   ├─ Models/
│   ├─ Services/
│   └─ Events/
├─ Infrastructure/
│   ├─ Persistence/
│   ├─ VectorSearch/
│   ├─ OpenAI/
│   └─ Messaging/
└─ Observability/

This maps 1:1 with the architecture diagram. Each layer has a single responsibility, clear ownership, and no upward dependencies. AI concerns live entirely within Application/AiOrchestration/ — isolated, replaceable, and testable in isolation.


The Senior Developer Advantage

Junior engineers learn prompts and call APIs. Senior engineers design boundaries, control failure modes, and own governance.

AI does not replace backend engineering — it exposes weak architecture faster.


Final Guidance

Do not abandon your stack. Do not chase frameworks. Do not embed AI into your domain.

Instead: anchor in clean architecture, treat AI as a volatile dependency, and design for failure, audit, and control. That is how AI reaches production — and stays there.


Agentic Flows: What Actually Changes (and What Must NOT)

This is an excellent and necessary question, and it's where most "AI architectures" quietly break.

You're essentially asking: what changes when AI stops being advisory and starts acting autonomously — without destroying domain integrity, auditability, or production trust?

Below is a clear, production-safe answer — not hype, not "let the agent decide."

A Critical Correction First

AI must never "take over" domain control. It may only be delegated bounded authority.

If AI truly owns domain decisions, you lose determinism, audits, legal defensibility, and rollback. Agentic systems require explicit architectural upgrades — not shortcuts.


New Mental Model: From "AI as Advisor" → "AI as Operator Under Policy"

Traditional AI flow:

AI → Suggestion → Domain decides

Agentic flow:

AI → Proposes Action → Policy validates → Domain executes

The domain still executes. AI never does.


What Actually Changes in the Architecture

What does NOT change:

  • Clean Architecture boundaries
  • Domain invariants
  • Aggregate ownership
  • Persistence rules
  • Audit requirements

What MUST be added:

  • Agent Runtime Layer
  • Explicit Capability Model
  • Policy & Guardrail Engine
  • Human Escalation Paths
  • Agent Memory (Non-Domain)

AI never touches Domain directly. The Policy Engine is mandatory.


The Agent Runtime Layer

This is not just "LLM + tools." The Agent Runtime is a workflow engine that reasons probabilistically.

Responsibilities:

  • Planning (multi-step reasoning)
  • Tool selection
  • State tracking
  • Retry & rollback
  • Timeout handling

What it is NOT allowed to do:

  • Persist domain state
  • Bypass validation
  • Execute side effects directly

Capability-Based Control (Non-Negotiable)

Agents must not have access. They must have capabilities.

AgentCapabilities:
  - ReadOrderSummary
  - ProposeRefund
  - RequestHumanApproval

Not allowed:

# Forbidden
- WriteOrder
- DeleteCustomer
- ExecutePayment

Capabilities are explicit, auditable, and revocable.


The Policy Engine: The Real Gatekeeper

This is where companies say "OK, ship it."

Policy inputs:

  • Agent identity
  • Capability requested
  • Domain context
  • Confidence score
  • Risk classification

Policy outcomes:

  • Allow
  • Deny
  • Escalate
  • Throttle
IF RefundAmount > €500
AND AgentConfidence < 0.85
→ Require Human Approval

This is deterministic code — not AI.


Domain Layer: What Changes (Very Little)

The domain still validates invariants, raises events, and controls persistence.

What's new:

  • "Proposed Action" commands
  • Confidence-aware execution
  • Escalation-aware workflows
ProposeRefundCommand
  - OrderId
  - Reason
  - Confidence
  - AgentId

The domain may still reject it.


Agent Memory: Where It May Exist (Safely)

Agents need memory — but not domain memory.

Allowed memory:

  • Conversation context
  • Task history
  • Planning notes
  • External summaries

Forbidden memory:

  • Source of truth
  • Financial state
  • Customer records

Memory must be time-bound, namespaced, and disposable.


Observability Becomes Mandatory (Not Optional)

Agentic systems must log every plan step, every capability request, every policy decision, every domain rejection, and every human escalation.

If you cannot answer "Why did the agent do this?" — you cannot ship.


Human-in-the-Loop Is Not a Failure

In agentic systems, humans are control surfaces — not fallback hacks.

Design explicit approval queues, review dashboards, and override actions. Companies trust systems that ask for help and admit uncertainty.


Anti-Patterns (Hard No)

  • AI writes directly to DB
  • AI executes payments
  • AI bypasses policies
  • AI "learns" domain rules
  • AI confidence replaces validation

These systems do not survive audits.


The Final Rule

Agents may reason. Policies may decide. Domains may act.

If you violate that order, your system will fail — technically, legally, or reputationally.


What's Next

  • Design a capability model for a real domain (ERP / CRM)
  • Build a C# agent runtime skeleton
  • Design policy-as-code for agent governance
  • Map agentic maturity levels (L1 → L4)
Tech Innovation Hub
Modern Software Architecture

Exploring cutting-edge technologies and architectural patterns that drive innovation in software development.

Projects

© 2025 Tech Innovation Hub. Built with Gatsby and modern web technologies.