This article explores how AI coding assistants, trained on prevalent 2020-era architectural patterns like Spring's annotation-driven dependency injection, might influence future software architecture. It investigates whether AI acts as a conservative force or if new, explicitly defined architectural patterns can be readily adopted by AI, shifting the focus to the quality and completeness of documentation for AI-driven development.
Read original on DZone MicroservicesThe rise of AI coding assistants presents a fascinating challenge to software architecture evolution. AI models are highly proficient in established patterns, particularly those like Spring's annotation-driven dependency injection and implicit control flow, due to their vast presence in training data. This raises the question of whether AI's inherent bias towards familiar patterns could hinder the adoption of novel architectural approaches.
Traditional `@RestController` patterns in frameworks like Spring rely heavily on implicit control flow, where the order of operations (validation, business logic, auditing) is embedded within the call stack and method invocations. To understand or modify this flow, human developers must read and interpret code, as the wiring is not explicitly defined as data. This reliance on implicit behavior makes it challenging for AI, which excels at pattern recognition but struggles with inferring complex, unstated relationships across a codebase.
The article proposes Function Injection as an architectural evolution, moving "what happens next" from the implicit call stack to explicit, configured data. Similar to how Dependency Injection externalized dependencies from imperative constructor code, Function Injection externalizes control flow. In the example provided, REST endpoints are defined in YAML files, where the sequence of functions (validate, build, audit) and conditional branches are declared, not buried in code. This creates an explicit
validate:
class: ValidateGreetingLogic
outputs:
valid: build
build:
class: PostGreetingLogic
next: audit
audit:
class: AuditGreetingLogicArchitectural Legibility for AI
Explicit, structured configurations (like YAML-based control flow) become a significant advantage when working with AI. They act as a searchable index, providing the AI with a complete behavioral contract of an endpoint without needing to infer relationships from complex call stacks, making the system more legible and maintainable by AI.
The core finding is that AI is not inherently conservative. While it defaults to familiar patterns due to training data prevalence, it can readily adopt new architectures if they are clearly and completely specified. The bottleneck for adopting new architectural patterns with AI is often the lack of comprehensive and unambiguous documentation. If new approaches are well-documented with clear schemas, conventions, and examples, AI can quickly learn and apply them, shifting the burden of explicit configuration from human developers (who preferred code-adjacent annotations) to comprehensive documentation for AI.