AI-Driven Three-Stage Software R&D Workflow: A Practical Guide

    Large language models are increasingly capable of assisting with code generation, but generating code is not the same as delivering reliable software. This article presents a three-stage methodology for building a controlled, traceable, and resumable AI-assisted R&D pipeline, covering documentation-first requirements and design, two-mode coding with checkpoint recovery, and self-loop testing with four-layer quality gates.

    AI-Driven Three-Stage Software R&D Workflow: A Practical Guide

    As large-model-assisted programming becomes more mature, more teams are trying to involve intelligent coding tools deeply in the full delivery chain from requirements to testing. However, “letting AI write code” is not the same as “letting AI deliver software.” Code generation without process constraints often leads to requirement drift, quality loss, and difficulty recovering from mid-process failures. Based on a practiced three-stage methodology, this article systematically explains how to build a controlled, traceable, and resumable intelligent R&D pipeline.

    1. Overall Philosophy: Documentation First, Closed-Loop Process

    The workflow follows three core principles:

    1. Documentation first: Establish a complete design contract before generating code. The design document is both an object of human review and the single source of truth for subsequent code generation and test validation.
    2. Self-loop testing: Do not proceed to the next step until tests pass. Continuously converge defects through an automated loop of “failure—analysis—fix—retest.”
    3. Checkpoint resume and human confirmation: Any long-running process may be interrupted, so it must support recovery from the interruption point. Keep human confirmation at key decision points to avoid the risk of an uncontrolled fully automated process.

    These three principles run through the following three stages.

    2. Stage One: Requirements and Design

    The output of this stage is a complete design document containing five components:

    • Requirements specification: Define functional boundaries, inputs and outputs, and non-functional constraints such as performance, security, and availability.
    • Use case specification: Describe each use case using the standard structure of actor—precondition—main flow—extension flow.
    • Database design: Table structures, field types, indexes, constraints, and relationships between tables.
    • API design: Interface paths, request methods, request/response data structures, and error code definitions.
    • Menu and permission design: Page navigation structure and role-permission mapping.

    The most important engineering practice in this stage is the business rule numbering system. Every business rule must be explicitly defined with a unique ID, such as BR-001 or BR-002. Each rule describes a decidable business constraint, for example: “BR-001: Orders are prohibited when the user’s balance is insufficient.”

    The value of the numbering system lies in full-chain traceability:

    • In code review during Stage Two, every core business logic point should be commented or mapped to the corresponding rule ID.
    • Test cases in Stage Three directly reference rule IDs, enabling bidirectional traceability from “rule → code → test.”
    • When requirements change, locating the affected IDs is enough to precisely determine which code must be modified and which tests must be rerun.

    After the design document is completed, it must pass human review and confirmation before entering the next stage. This is one of the most important quality gates in the entire workflow.

    3. Stage Two: Coding and Implementation

    Using the reviewed design document as input, AI outputs three types of artifacts: frontend source code, backend source code, and database scripts. This stage provides two working modes.

    3.1 Greenfield Creation Mode

    This mode applies to new modules developed from scratch. The process is divided into six standard steps. A typical breakdown can be: data model and script generation → data access layer → business service layer → API controller layer → frontend pages and components → frontend-backend integration skeleton. The purpose of step-by-step generation is to:

    • Keep the output of each step manageable for review.
    • Use the confirmation result of the previous step as context for the next step, reducing accumulated generation drift.
    • Localize problems at a finer granularity and lower rework cost.

    3.2 Brownfield Modification Mode

    This mode applies to incremental changes in existing codebases. Its core is impact analysis: based on the changed requirement rule IDs, locate affected files and functions, and perform incremental updates only on those files rather than a full rewrite. This avoids accidental damage to unaffected code and significantly shortens generation and review time.

    3.3 Checkpoint and Resume Mechanism

    Long-running generation may be interrupted at any time due to network issues, quota limits, or human intervention. Checkpoint resume requires the system to persist progress state during execution—recording the current step, which files have been generated, and which validations have passed. On resume, the system reads the state and continues from the last checkpoint instead of starting over. An illustrative state record structure is shown below:

    1. {
    2. "sessionId": "task-20240501-01",
    3. "currentStep": 4,
    4. "completedArtifacts": ["schema.sql", "repository/", "service/"],
    5. "pendingArtifacts": ["controller/", "frontend/"],
    6. "lastCheckpoint": "2024-05-01T10:32:00Z"
    7. }

    4. Stage Three: Test Validation

    4.1 Self-Loop Testing Mechanism

    Handling a test failure is not simply “trying again,” but a structured loop: test failure → 5-Why root-cause questioning → targeted fix → retest. The value of 5-Why questioning is that it prevents symptomatic fixes. For example, an API error should not be fixed only at the surface exception level; it should be traced to whether the cause is a data model mismatch, a missing business rule, or a misunderstanding of the API contract. Each loop should record the failure phenomenon, root-cause conclusion, and fix action, forming an auditable repair history. A loop limit must also be set, such as 3 to 5 rounds. If the limit is exceeded, the issue should be escalated to human intervention to avoid ineffective oscillation.

    4.2 Four-Layer Quality Gates

    Using a common backend build toolchain as an example, quality validation progresses bottom-up through four layers:

    1. Compile gate: Code must compile, eliminating syntax and type-level issues.
    2. Static check gate: Code style and potential defect pattern scanning.
    3. Unit test gate: Core business logic corresponding to rule IDs must be covered and pass.
    4. Integration verification gate: API connectivity, database script executability, and frontend-backend integration smoke testing.

    Failure at any layer triggers the self-loop in 4.1. Delivery is allowed only after all four layers pass. This layered design follows the principle of “low-cost checks first”: when compilation fails, there is no need to run tests, which significantly saves validation time.

    5. Conclusion

    Documentation first ensures that generated code has a basis to follow. The rule numbering system connects requirements, code, and tests into a traceability chain. Dual-mode coding supports both greenfield and brownfield scenarios. Checkpoint resume improves the robustness of long-running processes. Self-loop testing and four-layer quality gates protect the baseline of delivery quality. The essence of this methodology is to upgrade AI from a “code completion tool” to a “process-constrained engineering participant.” Teams can tailor it to their own technology stacks and, combined with general capabilities such as cloud-based continuous integration, logging services, and monitoring and alerting, further automate the entire pipeline and achieve a reliable balance between efficiency and quality.