What Is the Per-Unit Loop in the AI-DLC Construction Phase?
The per-unit loop is a fixed sequence of design and generation stages executed iteratively for every unit of work during the Construction phase, ensuring complete design-to-code delivery before the workflow advances to the next unit.
The per-unit loop forms the core processing logic of the Construction phase in the awslabs/aidlc-workflows repository. After the system divides work into discrete units during the Units Generation step, this loop guarantees that each unit undergoes comprehensive architectural design and code generation before the next unit begins. According to the workflow specification in core-workflow.md, the loop runs stages in strict order, culminating in mandatory code generation for every unit.
Stages of the Per-Unit Loop
The per-unit loop processes each unit through five distinct stages. Four stages run conditionally based on unit requirements, while one executes universally.
Functional Design
The Functional Design stage runs conditionally when a unit requires detailed business-logic design. This step defines the specific behaviors and data models needed for the unit to fulfill its purpose within the larger system.
NFR Requirements
NFR Requirements identifies performance, security, scalability, and technology-stack needs. This conditional stage activates when the unit has non-functional requirements that must be addressed before implementation.
NFR Design
When NFR requirements exist, the NFR Design stage translates them into concrete design patterns and architectural components. This conditional step bridges the gap between requirements documentation and implementation strategy.
Infrastructure Design
The Infrastructure Design stage maps the unit's functionality to specific cloud services, networking configurations, and storage solutions. This conditional execution ensures resources are only provisioned for units requiring infrastructure changes.
Code Generation
Code Generation is the only always-execute stage, running for every unit regardless of other design activities. This stage produces the actual source code, tests, and deployment artifacts through a two-part process of planning and generation, guaranteeing consistent deliverables across all units.
Execution Flow and Logic
The per-unit loop enforces a complete design-to-code progression for each unit before any subsequent unit begins processing. This sequential approach simplifies dependency management and maintains architectural coherence throughout the system.
Conditional stages execute only when specific triggers indicate necessity—such as new data models, performance constraints, or infrastructure changes. In contrast, the Code Generation stage runs unconditionally to ensure every unit exits the loop with tangible artifacts.
The loop structure appears in aidlc-rules/aws-aidlc-rules/core-workflow.md at lines 110-124, defining the conditional checks and mandatory execution pattern.
for unit in units: # Units generated earlier
if needs_functional_design(unit):
run_stage("functional-design", unit) # Conditional
if needs_nfr_requirements(unit):
run_stage("nfr-requirements", unit) # Conditional
if needs_nfr_design(unit):
run_stage("nfr-design", unit) # Conditional
if needs_infra_design(unit):
run_stage("infrastructure-design", unit) # Conditional
run_stage("code-generation", unit) # Always executed
The YAML configuration below illustrates how the workflow engine defines these conditional checks:
construction:
per-unit-loop:
- stage: functional-design
condition: "{{ unit.requires_complex_logic }}"
- stage: nfr-requirements
condition: "{{ unit.has_nfrs }}"
- stage: nfr-design
condition: "{{ unit.nfrs_defined }}"
- stage: infrastructure-design
condition: "{{ unit.needs_infra_mapping }}"
- stage: code-generation
condition: true
Source Code Reference
The Construction phase and per-unit loop logic are defined across several files in the awslabs/aidlc-workflows repository:
aidlc-rules/aws-aidlc-rules/core-workflow.md(lines 97-104, 110-124): Master definition of the per-unit loop composition and execution orderaidlc-rules/aws-aidlc-rule-details/construction/functional-design.md: Implementation details for the Functional Design conditional stageaidlc-rules/aws-aidlc-rule-details/construction/nfr-requirements.md: Specifications for gathering non-functional requirements per unitaidlc-rules/aws-aidlc-rule-details/construction/nfr-design.md: Architectural patterns for NFR Design implementationaidlc-rules/aws-aidlc-rule-details/construction/infrastructure-design.md: Cloud resource mapping guidelines for Infrastructure Designaidlc-rules/aws-aidlc-rule-details/construction/code-generation.md: Documentation of the two-part Code Generation process that always executes
After the per-unit loop processes all units, the workflow transitions to the Build and Test stage, which runs unconditionally once for the entire set of completed units.
Summary
- The per-unit loop processes each work unit through five stages: Functional Design, NFR Requirements, NFR Design, Infrastructure Design, and Code Generation.
- Four stages are conditional, executing only when the unit requires specific architectural attention, while Code Generation runs for every unit.
- The loop enforces sequential unit completion, preventing partial designs from advancing and maintaining system coherence.
- Source definitions reside in
aidlc-rules/aws-aidlc-rules/core-workflow.mdwith detailed stage implementations in theconstruction/rule details directory. - After all units complete the loop, the workflow executes the Build and Test stage.
Frequently Asked Questions
What is the difference between conditional and always-execute stages in the per-unit loop?
Conditional stages (Functional Design, NFR Requirements, NFR Design, and Infrastructure Design) run only when the unit meets specific criteria, such as requiring new business logic or infrastructure changes. Always-execute stages (specifically Code Generation) run for every unit regardless of other conditions, ensuring consistent artifact generation across the entire system.
How does the per-unit loop handle dependencies between units?
The per-unit loop enforces complete design-to-code processing for each unit before advancing to the next. This sequential approach means units are fully architected and generated in isolation, simplifying dependency management by ensuring no unit enters the loop with incomplete upstream deliverables. The workflow processes units in the order generated by the Units Generation step.
Where is the per-unit loop defined in the source code?
The per-unit loop is defined in aidlc-rules/aws-aidlc-rules/core-workflow.md at lines 97-104 (overview) and lines 110-124 (detailed stage enumeration). Individual stage implementations are documented in files within aidlc-rules/aws-aidlc-rule-details/construction/, including functional-design.md, nfr-requirements.md, nfr-design.md, infrastructure-design.md, and code-generation.md.
What happens after all units complete the per-unit loop?
After the per-unit loop finishes processing the final unit, the workflow executes the Build and Test stage, which runs unconditionally for the entire set of generated artifacts. This stage compiles the code, executes tests, and validates the integrated system before proceeding to subsequent phases of the AI-DLC workflow.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →