Model-driven full-stack code automatic generation method and system

By integrating design models and software factory asset libraries through a model-driven full-stack automatic code generation method, and adopting GJB5000B verification rules and a two-way synchronization mechanism, the problem of inconsistent code generation in the software factory is solved, and efficient and automated code generation and iteration support are achieved.

CN121742811APending Publication Date: 2026-03-27BEIJING SPACEFLIGHT TUOPUGAO SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-09
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Existing technologies in software factories suffer from problems such as fragmented design models, lack of deep integration with software factory asset libraries and compliance standards, and weak model-code synchronization mechanisms. These issues lead to inconsistent code generation and require extensive manual modifications, making it impossible to support iterative development.

Method used

A model-driven full-stack code generation method is adopted, which integrates multiple design inputs through a unified semantic model, utilizes built-in templates in the software factory asset library and GJB5000B verification rules, and combines a two-way synchronization mechanism to achieve consistency between the model and the code throughout their entire lifecycle.

Benefits of technology

It achieves integrated design and development, built-in quality, maximizes asset value, and enables sustainable evolution, significantly improving code quality and compliance while reducing maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121742811A_ABST
    Figure CN121742811A_ABST
Patent Text Reader

Abstract

The invention discloses a model-driven full-stack code automatic generation method and system.The method comprises the steps that a multi-dimensional design model is constructed, the multi-dimensional design model generates a model view through design codes, and full-stack codes are automatically generated in the model view generation process, and the full-stack code automatic generation method comprises the steps that S1, a unified semantic model is constructed, mapping the unified semantic model to a preset multi-language template, and generating target code frames of at least two languages of C + +, Java and JavaScript by the multi-language template; s2, establishing a bidirectional synchronization mechanism of the multi-dimensional design model and the target code framework; when the multi-dimensional design model is changed, automatically triggering an incremental code generation task; when the code is iterated, reversely analyzing and updating the corresponding model view; according to the method, the diversity of generated languages, the comprehensiveness of a design model, the flexibility of a template system, engineering support and the like are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software engineering automation technology, specifically to a model-driven full-stack code automatic generation method and system, which is applicable to industrial software production scenarios that require high standardization, rapid iteration, multi-technology stack collaboration, and strict compliance. Background Technology

[0002] Currently, software factories face three major technical bottlenecks when attempting to automate code generation: First, design models, such as UML, Swagger, and ER diagrams, are fragmented, making it difficult to form a unified semantic view and leading to inconsistent generated code. Second, a lack of deep integration with the software factory's asset repository and compliance standards results in poor code usability, requiring extensive manual modification and adaptation. Third, the synchronization mechanism between the model and code is weak; once the code is manually modified, the model becomes invalid, failing to support iterative development. Existing tools are mostly general-purpose code generators, failing to address the core needs of software factories such as standardization, componentization, and automated pipelines. Summary of the Invention

[0003] To address the aforementioned issues, this invention proposes a model-driven full-stack code automatic generation method and system. This method and system is geared towards software factories. It integrates multiple design inputs through a unified semantic model and utilizes templates built into the software factory's asset library and verification rules conforming to GJB5000B to drive a highly adaptable code generation engine. Finally, a bidirectional synchronization mechanism maintains the consistency between the model and the code throughout the entire software lifecycle.

[0004] To achieve the above objectives, the technical solution adopted by the present invention is as follows: A model-driven full-stack code automatic generation method includes constructing a multi-dimensional design model, generating a model view from the multi-dimensional design model through design code, wherein full-stack code is automatically generated during the model view generation process, and the full-stack code automatic generation method includes: Step S1: Construct a unified semantic model, map the unified semantic model to a preset multilingual template, and generate target code frameworks in at least two of the following languages: C++, Java, and JavaScript from the multilingual template. Step S2: Establish a two-way synchronization mechanism between the multi-dimensional design model and the target code framework; when the multi-dimensional design model changes, automatically trigger the incremental code generation task; when the code iterates, reverse parse and update the corresponding model view; The multi-dimensional design model is a multi-dimensional design model for constructing UML diagrams, database table relationship diagrams, and Swagger API interface models.

[0005] The solution further states that the multi-dimensional design model is a multi-dimensional design model built using the visual graphics modeling engine Draw.io.

[0006] The solution further includes: the construction of the unified semantic model includes: 1. An architecture rule engine is used to perform real-time compliance checks on the multi-dimensional design model. The compliance checks include at least API interface model verification, database normalization constraints, and class diagram relationship integrity verification. Second, through a multi-language code generator, the language design code of the multi-dimensional design model that has passed compliance checks is converted into the target language code framework; Third, based on the ANTLR syntax tree parsing, a multi-dimensional design model that has been verified and passed compliance checks is used to construct a unified semantic model.

[0007] The solution further includes the following: the mapping of the unified semantic model to the preset multilingual template is implemented based on the Mustache template engine.

[0008] The solution further includes: the architecture rule engine has a built-in interface specification rule set that conforms to the GJB5000B standard, and the API interface model verification includes the standardization of interface naming, the conformity of communication protocols, and the compatibility check with domestic operating systems.

[0009] The solution further includes: the framework for generating target code in at least two of the languages ​​C++, Java, and JavaScript includes: For the C++ language, generate communication interface code conforming to the GJB5000B protocol and underlying driver adaptation layer code adapted to Kylin or Tongxin domestic operating systems. For the Java language, it generates JPA entity classes, MyBatisMapper interfaces, RESTful controllers, and data transfer objects based on the Spring Boot framework; For JavaScript, it generates view components, route configurations, and state management code based on the Vue.js framework.

[0010] The solution further includes: the bidirectional synchronization mechanism specifically comprises: Model-to-code synchronization involves comparing model version differences, identifying change sets, regenerating only the affected code modules, and outputting incremental code patch files. The synchronization of code to model is achieved by using the TreeSitter static code analysis tool to parse the abstract syntax tree of the target code, extract class structure, method signatures and dependencies, and update the UML class diagram model accordingly.

[0011] A system for implementing the method, the system comprising: a visual modeling module, a multilingual code generator module, and a model-driven engine module; The visualization modeling module provides a graphical interface for users to create multi-dimensional design models. The multilingual code generator module is connected to the visualization modeling module, which generates the unified semantic model. The model is mapped to a preset multilingual template, and the validated multi-dimensional design model is parsed and converted into multilingual code. The model-driven engine module describes the connection between the visualization modeling module and the multilingual code generator module, and is used to maintain the bidirectional synchronization relationship between the model and the code.

[0012] A further aspect of the solution is that the visualization modeling module integrates a Swagger parser and a database metadata interface, which is used to automatically import Swagger API specification files and database table structures, and convert them into unified model elements within the system.

[0013] A further aspect of the solution is that the multilingual code generator module has a built-in template repository, which stores configurable C++, Java, and JavaScript code templates based on Mustache syntax, allowing users to define template content according to project specifications.

[0014] The beneficial effects of this invention are: Deep integration of model-driven development (MWD) with the software factory environment, achieving: Integrated design and development: Automated conversion from design to production code, streamlining a key link in the automated software factory pipeline. Built-in quality: Real-time architecture rule verification and high-quality templates prevent defects at the design stage, significantly improving code quality and compliance. Maximized asset value: Transforming the core assets of the software factory, including specifications, components, and templates, into automated productivity, achieving knowledge accumulation and efficient reuse. Sustainable evolution: A two-way synchronization mechanism ensures that the model and code remain consistent during rapid iterations, reducing maintenance costs.

[0015] This invention achieves true full-stack, multi-language code automatic generation through an innovative multi-model integration architecture and a flexible template engine design. Compared with existing technologies, it offers significant improvements in the diversity of generated languages, the comprehensiveness of design models, the flexibility of the template system, and engineering support, thereby greatly enhancing the efficiency and quality of software development.

[0016] The invention will be further explained in detail below with reference to the accompanying drawings and specific embodiments. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating the overall system workflow of the present invention. Figure 2 This is a diagram illustrating multi-model integration and code generation. Figure 3 This is a diagram showing the two-way synchronization between the model and the code. Detailed Implementation

[0018] Example 1: A model-driven full-stack code auto-generation method includes constructing a multi-dimensional design model, generating a model view from the multi-dimensional design model through design code, and automatically generating full-stack code during the model view generation process. This method aims to solve the problem of code consistency when constructing different multi-dimensional design models. The full-stack code auto-generation method includes: Step S1: Construct a unified semantic model, map the unified semantic model to a preset multilingual template, and generate target code frameworks in at least two of the following languages: C++, Java, and JavaScript from the multilingual template. Step S2: Establish a two-way synchronization mechanism between the multi-dimensional design model and the target code framework; when the multi-dimensional design model changes, automatically trigger the incremental code generation task; when the code iterates, reverse parse and update the corresponding model view; The multi-dimensional design model is a multi-dimensional design model for constructing UML diagrams, database table relationship diagrams, and Swagger API interface models, and has multi-window synchronization functionality.

[0019] The construction of the unified semantic model involves using ANTLR to parse the input sources. For example, to parse Swagger, an OpenApiV3.g4 syntax file is defined. After parsing, all elements are mapped to a Java object model called a Unified Semantic Intermediate Representation (USIR). The structure of the USIR is predefined, and the corresponding template directory is checked out from the Git template repository based on the `techStack` field in the USIR. The Mustache engine is used to bind the USIR object to the template. For example, a JavaEntity template, `Entity.java.mustache`, with the following content, generates standard Java source code conforming to the Software Factory Architecture specification after rendering.

[0020] Wherein: the multi-dimensional design model is a multi-dimensional design model built using the visual graphics modeling engine Draw.io, including: (1) Domain Component Loading: When the system starts, it pulls the domain component library of the current project from the software factory asset library via the RESTful API: GET / asset-library / domain-palette, which is a JSON description file. This file defines the component's attributes, icon, and constraint rules.

[0021] (2) Model drawing and synchronization: Users drag and drop components to draw in the Draw.io-based interface. The front end uses the Socket.IO library to establish a WebSocket long connection and send drawing operations such as shapeAdded and propertyChanged to the server in real time.

[0022] (3) Model persistence: The server serializes the received operations and converts them into the standard XMI format, storing them in the central database (PostgreSQL 13). At the same time, to support collaboration, the Operational Transformation (OT) algorithm is used to resolve operation conflicts.

[0023] The construction of the unified semantic model includes: 1. An architecture rule engine is used to perform real-time compliance checks on the multi-dimensional design model. The compliance checks include at least API interface model verification, database normalization constraints, and class diagram relationship integrity verification. Second, through a multi-language code generator, the language design code of the multi-dimensional design model that has passed compliance checks is converted into the target language code framework; Third, based on the ANTLR syntax tree parsing, a multi-dimensional design model that has been verified and passed compliance checks is used to construct a unified semantic model.

[0024] Specifically, the architecture rule engine is used to perform real-time compliance checks on the multi-dimensional design model: (1) Rule set loading: The rule engine listens for Webhook notifications from the asset library. When a rule is updated, it automatically pulls the latest .drl file set via GET / asset-library / rule-sets and dynamically updates it to the Drools engine by calling the KieContainer interface.

[0025] (2) Compliance verification execution: When the model changes, the system inserts the current unified semantic model Java object graph as a Fact into Drools' KieSession.

[0026] (3) Example of a rule (Drools DSL).

[0027] The mapping of the unified semantic model to the preset multilingual template is implemented based on the Mustache template engine.

[0028] The architecture rule engine has a built-in interface specification rule set that conforms to the GJB5000B standard. The API interface model verification includes checks on the standardization of interface naming, compliance with communication protocols, and compatibility with domestic operating systems.

[0029] The framework for generating target code in at least two of the languages ​​C++, Java, and JavaScript includes: For the C++ language, generate communication interface code conforming to the GJB5000B protocol and underlying driver adaptation layer code adapted to Kylin or Tongxin domestic operating systems. For the Java language, it generates JPA entity classes, MyBatisMapper interfaces, RESTful controllers, and data transfer objects based on the Spring Boot framework; For JavaScript, it generates view components, route configurations, and state management code based on the Vue.js framework.

[0030] The bidirectional synchronization mechanism is specifically as follows: Model-to-code synchronization involves comparing model version differences, identifying change sets, regenerating only the affected code modules, and outputting incremental code patch files. The synchronization of code to model is achieved by using the TreeSitter static code analysis tool to parse the abstract syntax tree of the target code, extract class structure, method signatures and dependencies, and update the UML class diagram model accordingly.

[0031] The process utilizes EMF Compare technology, which works as follows: The system saves the previous version of the model, M_old. When a user submits a new version, M_new, EMFCompare calculates the difference, Diff(Model_old, Model_new). This difference is translated into a series of file system operations (CreateFile, UpdateFile, DeleteFile). The system only performs these operations. For files where user code needs to be preserved, a BSDiff 4.3 format patch file is generated and the developer is prompted to merge it during the CI process.

[0032] In this embodiment: The multilingual code generator is responsible for converting the unified semantic model, validated by the architecture rule engine, into source code that conforms to the target technology stack. Its internal structure includes: a Unified Semantic Intermediate Representation (USIR) builder: using ANTLR 4.9.3 to parse inputs from multiple sources such as Swagger / OpenAPI 3.0, database DDL, and UMLXMI, mapping them to a unified, language-independent intermediate representation structure. This structure is defined using JSON Schema and contains metadata such as entities, relationships, interfaces, and constraints, supporting cross-model association and consistency maintenance; a template repository and version management: the template repository uses Git for version control, organized by technology stack (C++ / Java / JavaScript, etc.) and component type (entity classes / controllers / front-end components, etc.). Each template is in Mustache format and supports variable substitution, conditional branching, and loop structures. Users can dynamically update templates via a RESTful API, and the system supports canary releases and rollbacks of templates; and a multilingual rendering engine: implemented based on Mustache.java 0.9.10, supporting hot template reloading and caching mechanisms. During rendering, the USIR object is bound to the template, generating source code files that conform to the target language syntax and project specifications. The system supports custom rendering strategies, such as generating file directory structures, package name mappings, and comment conventions. Post-processing and formatting: After generating the code, language-specific formatting tools (such as clang-format for C++ and prettier for JavaScript) are automatically invoked to ensure consistent code style. It also supports the automatic generation and updating of project-specific copyright notices and dependency management files (such as pom.xml and package.json).

[0033] Below is an example of Java code generation based on Swagger and database models: Step 1: First, define two resource endpoints, ` / user` and ` / products`, using the Swagger Editor; then, create the corresponding `USER` and `PRODUCT` table structures using the database design tool. The system will then execute the following steps: Step 2: Use the Swagger parser to read the OpenAPI 2.0 specification file and extract the resource paths, methods, and parameters from ` / api / users` and ` / api / products`. Operation methods include GET, POST, PUT, DELETE, etc.

[0034] Step 3: Connect to the development database via the JDBC metadata interface and obtain the foreign key relationship between the two tables, then read the structures of the User and PRODUCT tables; the USER table structure contains fields such as id, name, and Email. The PRODUCT table structure contains fields such as id, name, and price.

[0035] Step 4: Establish mapping relationships through model integration. Swagger's User model corresponds to the USER table. For example, the User model corresponds to UserEntity, and the / api / user endpoint corresponds to the User controller class. GET / api / user corresponds to the getUserList() method.

[0036] Step 5: Select a Java / Spring Boot technology stack template, including the Entity template to generate JPA entity classes; the Repository template to generate Mybatis Mapper interfaces; and the Controller template to generate REST controllers, etc.

[0037] Step 6: After the code generation engine executes, it outputs the complete Spring Boot project structure.

[0038] Step 7: The system automatically generates a Maven POM file, which contains the necessary dependencies and supports direct import into Eclipse or IntelliJ IDEA.

[0039] The following is an example of JavaScript front-end code generation: Based on the same Swagger model specification system, the corresponding front-end code can be generated. First, select the Vue 3 technology stack template to generate Vue components including User list, add, edit, and detail components, Product list, add, edit, and detail components, etc., output standard Vue Router configuration and Axios interface calls, and finally run it directly through npm start.

[0040] Example 2: A system for implementing the method described in Embodiment 1, the system comprising: a visualization modeling module, a multilingual code generator module, and a model-driven engine module; The visualization modeling module provides a graphical interface for users to create multi-dimensional design models. The multilingual code generator module is connected to the visualization modeling module, which generates the unified semantic model. The model is mapped to a preset multilingual template, and the validated multi-dimensional design model is parsed and converted into multilingual code. The model-driven engine module describes the connection between the visualization modeling module and the multilingual code generator module, and is used to maintain the bidirectional synchronization relationship between the model and the code.

[0041] The visualization modeling module integrates a Swagger parser and a database metadata interface, which is used to automatically import Swagger API specification files and database table structures, and convert them into unified model elements within the system.

[0042] The multilingual code generator module has a built-in template repository that stores configurable C++, Java, and JavaScript code templates based on Mustache syntax, allowing users to define template content according to project specifications.

[0043] The above embodiments 1 and 2 are passed through Figures 1 to 3 It was vividly displayed, including: Figure 1 It demonstrates the complete process from "requirement input" through "design modeling", "rule engine verification", "multi-language code generation" to "two-way synchronous maintenance", highlighting the data interaction and feedback loop between each stage.

[0044] Figure 2 It specifically describes how the Swagger API model, UML class diagram model, and database ER model are integrated into a unified semantic model by the ANTLR parser, and how C++, Java, and JavaScript code are generated through different Mustache templates.

[0045] Figure 3 The system uses a two-column comparison format. The left side shows the process of "model change" triggering "incremental code generation", while the right side shows the process of "code submission" triggering "model reverse update", which intuitively demonstrates the principle of bidirectional synchronization.

Claims

1. A model-driven full-stack code automatic generation method, comprising constructing a multi-dimensional design model, wherein the multi-dimensional design model generates a model view through design code, characterized in that, Full-stack code is automatically generated during the generation of the model view. The automatic full-stack code generation method includes: Step S1: Construct a unified semantic model, map the unified semantic model to a preset multilingual template, and generate target code frameworks in at least two of the following languages: C++, Java, and JavaScript from the multilingual template. Step S2: Establish a two-way synchronization mechanism between the multi-dimensional design model and the target code framework; when the multi-dimensional design model changes, automatically trigger the incremental code generation task; when the code iterates, reverse parse and update the corresponding model view; The multi-dimensional design model is a multi-dimensional design model for constructing UML diagrams, database table relationship diagrams, and Swagger API interface models.

2. The automatic generation method according to claim 1, characterized in that, The multi-dimensional design model is a multi-dimensional design model built using the visual graphics modeling engine Draw.io.

3. The automatic generation method according to claim 1, characterized in that, The construction of the unified semantic model includes:

1. An architecture rule engine is used to perform real-time compliance checks on the multi-dimensional design model. The compliance checks include at least API interface model verification, database normalization constraints, and class diagram relationship integrity verification. Second, through a multi-language code generator, the language design code of the multi-dimensional design model that has passed compliance checks is converted into the target language code framework; Third, based on the ANTLR syntax tree parsing, a multi-dimensional design model that has been verified and passed compliance checks is used to construct a unified semantic model.

4. The automatic generation method according to claim 1, characterized in that, The mapping of the unified semantic model to the preset multilingual template is implemented based on the Mustache template engine.

5. The automatic generation method according to claim 3, characterized in that, The architecture rule engine has a built-in interface specification rule set that conforms to the GJB5000B standard. The API interface model verification includes the standardization of interface naming, the conformity of communication protocols, and the compatibility check with domestic operating systems.

6. The automatic generation method according to claim 1, characterized in that, The framework for generating target code in at least two of the languages ​​C++, Java, and JavaScript includes: For the C++ language, generate communication interface code conforming to the GJB5000B protocol and underlying driver adaptation layer code adapted to Kylin or Tongxin domestic operating systems. For the Java language, it generates JPA entity classes, MyBatis Mapper interfaces, RESTful controllers, and data transfer objects based on the Spring Boot framework; For JavaScript, it generates view components, route configurations, and state management code based on the Vue.js framework.

7. The automatic generation method according to claim 1, characterized in that, The bidirectional synchronization mechanism is specifically as follows: Model-to-code synchronization involves comparing model version differences, identifying change sets, regenerating only the affected code modules, and outputting incremental code patch files. The synchronization from code to model is achieved by using the TreeSitter static code analysis tool to parse the abstract syntax tree of the target code, extract class structure, method signatures and dependencies, and then update the UML class diagram model accordingly.

8. A system for implementing the method as described in any one of claims 1 to 7, characterized in that, The system includes: a visual modeling module, a multilingual code generator module, and a model-driven engine module; The visualization modeling module provides a graphical interface for users to create multi-dimensional design models. The multilingual code generator module is connected to the visualization modeling module, which generates the unified semantic model. The model is mapped to a preset multilingual template, and the validated multi-dimensional design model is parsed and converted into multilingual code. The model-driven engine module describes the connection between the visualization modeling module and the multilingual code generator module, and is used to maintain the bidirectional synchronization relationship between the model and the code.

9. The system according to claim 8, characterized in that, The visualization modeling module integrates a Swagger parser and a database metadata interface, which is used to automatically import Swagger API specification files and database table structures, and convert them into unified model elements within the system.

10. The system according to claim 8, characterized in that, The multilingual code generator module has a built-in template repository that stores configurable C++, Java, and JavaScript code templates based on Mustache syntax, allowing users to define template content according to project specifications.