A UI design draft-to-code method, device, equipment and medium

By employing a multi-stage anti-illusion constraint mechanism, the illusion problem in the conversion of UI design drafts to code is solved, achieving high availability and plug-and-play functionality in the generated code, ensuring consistency between the code and project specifications, and reducing the workload for developers.

CN123137650APending Publication Date: 2026-11-20ZIXUN TECHNOLOGY (FUJIAN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611083174.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-21
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing UI design draft to code conversion technologies suffer from illusion problems, lack of project context awareness, inaccurate component selection, and lack of independent verification mechanisms, resulting in generated code that is not plug-and-play and requires extensive modification.

Method used

Through a multi-stage anti-illusion constraint mechanism, including read-before-write context scanning, map-driven deterministic component selection, template library constraint generation, and independent cross-validation, the generated code is ensured to conform to project specifications.

Benefits of technology

It achieves high availability and plug-and-play functionality in the generated code, reduces the workload for developers, improves the compileability and runnability of the code, and ensures that the code is consistent with project specifications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137650A_ABST
    Figure CN123137650A_ABST
Patent Text Reader

Abstract

The application provides a UI design draft code conversion method, device, equipment and medium, the method comprises the following steps: positioning the target project and performing context scanning, establishing the project context knowledge base based on the principle of reading first and writing later; obtain design draft DSL data, identify page type and component requirement, and extract DSL style value; use a mapping table driven mechanism to map component requirements to real existing components of the target project, and map DSL style values to project style variables; generate front-end code based on a standardized template library in hierarchical order; start an independent large language model review instance for multidimensional cross-validation; automatically repair the code and output according to the review report; through a multi-stage anti-illusion constraint mechanism, the illusion problem of the large model in the design draft code conversion scene is effectively solved, the generated code strictly conforms to the project specification, and high available code generation is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence-assisted software development technology, and in particular to a method, apparatus, device, and medium for converting UI design drafts into code. Background Technology

[0002] With the widespread application of Large Language Models (LLMs) in software engineering, Design-to-Code (D2C) has become an important direction for improving front-end development efficiency. Currently, mainstream D2C solutions typically employ the following approach: directly inputting the Domain Specific Language (DSL) data exported from the design tool into the Large Language Model, which then generates the front-end code in one go.

[0003] However, the above solution has the following technical drawbacks: First, the illusion problem is serious. When generating code, large language models are prone to reasoning based on patterns in the training data, generating seemingly reasonable but actually non-existent component import paths, component attribute interfaces, API call addresses, and style variable names. This causes the generated code to fail to compile or run, requiring developers to spend a lot of time troubleshooting and manually correcting errors.

[0004] Second, there is a lack of project context awareness. Existing solutions typically only focus on the structural information of the design draft itself, without actively recognizing the target project's existing component library system, state management pattern, style system specifications, and directory organization structure. This results in generated code that is inconsistent with the project's existing specifications, failing to achieve plug-and-play functionality and requiring developers to make extensive adaptation modifications.

[0005] Third, component selection relies on semantic reasoning from a large language model. In existing solutions, the large language model selects UI components based on semantic understanding rather than deterministic matching based on the actual component library available in the project. This can easily lead to the selection of components that do not exist in the project or the neglect of high-level components that have been encapsulated in the project and conform to design specifications, resulting in code redundancy and inconsistent style.

[0006] Fourth, the generated results lack an independent verification mechanism. Existing solutions typically perform self-checks by the same model or context after code generation. The generator and verifier share the same knowledge limitations and reasoning biases, making it impossible to effectively detect self-introduced illusion errors, which are then missed in subsequent development stages.

[0007] The aforementioned shortcomings severely restrict the usability and promotion of design draft to code conversion technology in actual projects. Summary of the Invention

[0008] The technical problem to be solved by this invention is to provide a method, device, equipment and medium for converting UI design drafts into code. Through a multi-stage anti-illusion constraint mechanism, it effectively solves the illusion problem of large models in the scenario of converting design drafts into code, so that the generated code strictly conforms to the project specifications and achieves highly available code generation.

[0009] In a first aspect, the present invention provides a method for converting UI design drafts into code, comprising the following steps: Step S1: In response to the location command of the target project, scan the file system of the target project based on the read-before-write principle to build a project context knowledge base; Step S2: Obtain the DSL data of the UI design draft, perform structured analysis on the DSL data, identify page type and component requirements, and extract DSL style values ​​from the DSL data; Step S3: Based on the preset mapping table of DSL visual features to project components, determine the corresponding component mapping rule from the mapping table according to the identified page type, map the identified component requirements to the target components that actually exist in the project context knowledge base, and map the DSL style values ​​to the style variables of the target project based on the preset style mapping rule. Step S4: Based on a predefined standardized code template library, and in combination with the target component and the style variables, generate the front-end code file corresponding to the UI design draft according to a preset file generation order; Step S5: Start a large language model review instance that is independent of the code generation context, perform multi-dimensional cross-validation on the generated front-end code files, and output a review report containing the validation results and repair suggestions; Step S6: Repair the generated front-end code file according to the repair suggestions in the review report, and output the repaired final code file.

[0010] Secondly, the present invention provides a UI design draft to code conversion device, comprising: The context scanning module, in response to the location command of the target project, scans the file system of the target project based on the read-before-write principle to build a project context knowledge base; The DSL acquisition and parsing module acquires the DSL data of the UI design draft, performs structured analysis on the DSL data, identifies page types and component requirements, and extracts DSL style values ​​from the DSL data. The deterministic mapping module, based on a preset mapping table of DSL visual features to project components, determines the corresponding component mapping rules from the mapping table according to the identified page type, maps the identified component requirements to the target components that actually exist in the project context knowledge base, and maps DSL style values ​​to style variables of the target project based on preset style mapping rules. The template generation module, based on a predefined standardized code template library, combines the target component and the style variables to generate the front-end code file corresponding to the UI design draft according to a preset file generation order; The independent cross-validation module initiates a large language model review instance independent of the code generation context, performs multi-dimensional cross-validation on the generated front-end code files, and outputs a review report containing the validation results and fix suggestions. The repair and output module repairs the generated front-end code file according to the repair suggestions in the review report and outputs the repaired final code file.

[0011] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.

[0012] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0013] One or more technical solutions provided by this invention have at least the following technical effects or advantages: 1. This invention establishes anti-illusion constraints at every stage of code generation by constructing a read-before-write context scanning mechanism, a mapping table-driven deterministic component selection mechanism, a standardized generation mechanism with template library constraints, and a cross-validation mechanism for independent sub-agents. This effectively avoids the introduction of non-existent components, paths, attributes, and style variables in D2C scenarios by large language models, and significantly improves the compileability and runnability of the generated code.

[0014] 2. This invention can automatically sense the existing component library system, state management method, service layer structure and style variable system of the target project, ensuring that all generated code strictly conforms to the existing technical specifications of the target project in terms of component reference, state management, API calls and style usage, achieving a truly plug-and-play code generation effect and greatly reducing the amount of manual modification work for developers.

[0015] 3. This invention employs a deterministic mechanism for component selection driven by a mapping table, replacing the free semantic reasoning of large language models and fundamentally eliminating the illusionary risks in the component selection phase. Simultaneously, it adheres to the principle of prioritizing project components, preferentially selecting custom high-level components already encapsulated in the target project rather than original components from the basic UI library, ensuring consistency between the generated code and the project's design system and avoiding code redundancy.

[0016] 4. After code generation, this invention initiates a review sub-agent independent of the generation context to perform six-stage cross-validation, covering import path verification, component attribute verification, style variable verification, code pattern compliance check, and design draft fidelity check. All verifications are based on actual file system reading rather than model inference, which can effectively detect various errors introduced during the generation stage and ensure the quality of the final delivered code through a priority-based automatic repair mechanism.

[0017] 6. This invention generates a type definition layer, service layer, state management layer, view layer, and page entry layer in a fixed hierarchical order using a standardized template library. It also adopts standardized features such as function component declaration, observer higher-order component wrapping, IProps interface naming, CSS Modules style isolation, and internationalized text wrapping, ensuring that the generated code has a good structural hierarchy and style consistency, which facilitates subsequent manual maintenance and secondary development.

[0018] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description

[0019] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0020] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation

[0021] The overall concept of the technical solution in this application embodiment is as follows: This application provides a UI design draft to code conversion method based on an anti-illusion multi-stage pipeline. Before obtaining the design draft, the target project is first scanned in context. A knowledge base of real project assets is established based on the principle of "read before writing," which serves as the factual basis for all subsequent generation and verification operations, fundamentally eliminating the basis for illusions caused by large models relying on training data for reasoning. Then, the design draft DSL data is obtained, and page types, component requirements, and style values ​​are extracted from it. Next, a deterministic mapping mechanism driven by a mapping table is used to map the UI elements and style values ​​in the DSL to the actual components and style variables in the project knowledge base, replacing the free reasoning of the large model with a deterministic lookup method. Afterward, code is generated based on a standardized template library in a hierarchical order of type definition layer, service layer, state management layer, view layer, and page entry layer, ensuring that the generated code is strictly consistent in structure and specification. Finally, a large language model review instance independent of the generation context is launched to perform six-stage cross-validation on the generated code, including import path verification, component attribute verification, style variable verification, code pattern compliance check, and design draft fidelity check. Failure items are automatically repaired according to priority before output.

[0022] The above stages form a progressive anti-illusion system that includes prior knowledge constraint generation, deterministic mapping to replace reasoning, standardized templates to eliminate free play, and independent verification to ensure quality. This system ensures that the generated code strictly conforms to the technical stack specifications and code conventions of the target project, achieving highly available and plug-and-play code generation.

[0023] Example 1 like Figure 1 As shown, this embodiment provides a method for converting UI design drafts into code, including the following steps: Step S1: In response to the location command of the target project, scan the file system of the target project based on the read-before-write principle to build a project context knowledge base; Step S2: Obtain the DSL data of the UI design draft, perform structured analysis on the DSL data, identify page type and component requirements, and extract DSL style values ​​from the DSL data; Step S3: Based on the preset mapping table of DSL visual features to project components, determine the corresponding component mapping rule from the mapping table according to the identified page type, map the identified component requirements to the target components that actually exist in the project context knowledge base, and map the DSL style values ​​to the style variables of the target project based on the preset style mapping rule. Step S4: Based on a predefined standardized code template library, and in combination with the target component and the style variables, generate the front-end code file corresponding to the UI design draft according to a preset file generation order; Step S5: Start a large language model review instance that is independent of the code generation context, perform multi-dimensional cross-validation on the generated front-end code files, and output a review report containing the validation results and repair suggestions; Step S6: Repair the generated front-end code file according to the repair suggestions in the review report, and output the repaired final code file.

[0024] In this embodiment, preferably, the step S1 of building the project context knowledge base specifically includes: Scan the first preset directory of the target project to obtain a list of existing pages and a list of common components; Scan the second preset directory of the target project to obtain the status management Store list and the service layer Service list; Read the style variable definition file of the target project to obtain the actual set of style variable definitions.

[0025] In this embodiment, preferably, the mapping table contains multiple sets of component mapping rules corresponding to different page types, and the page types include at least list pages, form pages, detail pages, pop-ups, and composite pages; In step S3, based on the identified page type, a set of component mapping rules corresponding to the page type are retrieved from the mapping table to map the component requirement to the target component. The mapping table also includes layout class mapping, data display class mapping, form class mapping and operation class mapping; Step S3 follows the principle of prioritizing project components. When the target project has a custom encapsulation component for the basic UI component, the custom encapsulation component is selected first instead of the basic UI component.

[0026] In this embodiment, preferably, the style mapping rules in step S3 specifically include: Map the color values ​​in the DSL data to the corresponding color variables in the style variables of the target project; Map the spacing values ​​in the DSL data to the corresponding spacing variables in the style variables of the target project; When the DSL style value cannot be matched precisely, the style variable with the closest value among the style variables is selected for mapping, and a TODO comment is added to the generated code.

[0027] In this embodiment, preferably, step S4, which generates the front-end code file corresponding to the UI design draft according to a preset file generation order, specifically includes: First, generate the code file for the type definition layer, which is used to define the data structure; Next, generate the service layer code files to encapsulate API calls; Regenerate the code file for the state management layer to manage component state; Then, the code file for the view layer is generated, which is used to build the user interface; Finally, the code file for the page entry layer is generated to expose the route entry point; The code files of the view layer shall include at least the following constraints: use function component declarations, use the observer higher-order component to wrap exports, use the IProps naming convention for the Props interface, use internationalized function wrappers for user interface text, and use the CSS Modules specification for style files.

[0028] In this embodiment, preferably, step S5 specifically comprises: Read all generated front-end code files and extract the reference information to be verified contained therein; By accessing the file system of the target project, verify whether the target file referenced by each import statement actually exists; if the verification result fails, attach the path of the matching file in the project's file system that is closest to the import path; Read the source code definition of the referenced component and verify whether the attribute names and types used by the component match the source code definition. In the style variable definition file of the target project, verify that each referenced style variable exists; if the verification fails, attach the name of the matching variable in the style variable definition file that is closest to the name of the referenced style variable. Using preset regular expression rules, verify whether the generated code conforms to the preset coding specifications of the target project; Compare the component hierarchy of the generated code with the node hierarchy of the original DSL data to check for any missing key elements; The review report is in JSON format, and the verification results are divided into P0, P1 and P2 levels according to priority. The P0 level is used to indicate error items that will cause compilation or running failure, the P1 level is used to indicate defects that do not conform to the project's preset specifications, and the P2 level is used to indicate suggested optimization items. Step S6 specifically involves: repairing failed items according to the priority order of P0, P1, and P2 levels; wherein, errors at the P0 level are repaired immediately, defects at the P1 level are repaired in a standardized manner, and suggested optimization items at the P2 level are marked with TODO comments in the code, and then the final repaired code file is output.

[0029] In this embodiment, preferably, step S2 further includes: If the DSL data contains component document links, then the usage document of the corresponding component is obtained from the component document links; The design tool's design draft to code conversion interface is used to obtain general reference code, and the layout structure, element hierarchy relationship and text content are extracted from the general reference code as structural understanding reference. The general reference code is not directly used for code generation. The target project's location command determines the target project's root path according to the following priority: The project path explicitly specified by the user; The current working directory contains the project flag file; Search upwards from the current directory, level by level, for the parent directory containing the project identifier file; If none of the above can be found, ask the user.

[0030] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.

[0031] Example 2 like Figure 2 As shown, this embodiment provides a UI design draft to code conversion device, including: The context scanning module, in response to the location command of the target project, scans the file system of the target project based on the read-before-write principle to build a project context knowledge base; The DSL acquisition and parsing module acquires the DSL data of the UI design draft, performs structured analysis on the DSL data, identifies page types and component requirements, and extracts DSL style values ​​from the DSL data. The deterministic mapping module, based on a preset mapping table of DSL visual features to project components, determines the corresponding component mapping rules from the mapping table according to the identified page type, maps the identified component requirements to the target components that actually exist in the project context knowledge base, and maps DSL style values ​​to style variables of the target project based on preset style mapping rules. The template generation module, based on a predefined standardized code template library, combines the target component and the style variables to generate the front-end code file corresponding to the UI design draft according to a preset file generation order; The independent cross-validation module initiates a large language model review instance independent of the code generation context, performs multi-dimensional cross-validation on the generated front-end code files, and outputs a review report containing the validation results and fix suggestions. The repair and output module repairs the generated front-end code file according to the repair suggestions in the review report and outputs the repaired final code file.

[0032] In this embodiment, preferably, the construction of a project context knowledge base in the context scanning module specifically includes: Scan the first preset directory of the target project to obtain a list of existing pages and a list of common components; Scan the second preset directory of the target project to obtain the status management Store list and the service layer Service list; Read the style variable definition file of the target project to obtain the actual set of style variable definitions.

[0033] In this embodiment, preferably, the mapping table contains multiple sets of component mapping rules corresponding to different page types, and the page types include at least list pages, form pages, detail pages, pop-ups, and composite pages; In the deterministic mapping module, based on the identified page type, a set of component mapping rules corresponding to the page type are called from the mapping table to map the component requirement to the target component; The mapping table also includes layout class mapping, data display class mapping, form class mapping, and operation class mapping; The deterministic mapping module follows the principle of prioritizing project components. When the target project has a custom encapsulation component for the basic UI component, the custom encapsulation component is selected first instead of the basic UI component.

[0034] In this embodiment, preferably, the style mapping rules in the deterministic mapping module specifically include: Map the color values ​​in the DSL data to the corresponding color variables in the style variables of the target project; Map the spacing values ​​in the DSL data to the corresponding spacing variables in the style variables of the target project; When the DSL style value cannot be matched precisely, the style variable with the closest value among the style variables is selected for mapping, and a TODO comment is added to the generated code.

[0035] In this embodiment, preferably, the template generation module generates the front-end code file corresponding to the UI design draft according to a preset file generation order, specifically including: First, generate the code file for the type definition layer, which is used to define the data structure; Next, generate the service layer code files to encapsulate API calls; Regenerate the code file for the state management layer to manage component state; Then, the code file for the view layer is generated, which is used to build the user interface; Finally, the code file for the page entry layer is generated to expose the route entry point; The code files of the view layer shall include at least the following constraints: use function component declarations, use the observer higher-order component to wrap exports, use the IProps naming convention for the Props interface, use internationalized function wrappers for user interface text, and use the CSS Modules specification for style files.

[0036] In this embodiment, preferably, the independent cross-validation module specifically comprises: Read all generated front-end code files and extract the reference information to be verified contained therein; By accessing the file system of the target project, verify whether the target file referenced by each import statement actually exists; if the verification result fails, attach the path of the matching file in the project's file system that is closest to the import path; Read the source code definition of the referenced component and verify whether the attribute names and types used by the component match the source code definition. In the style variable definition file of the target project, verify that each referenced style variable exists; if the verification fails, attach the name of the matching variable in the style variable definition file that is closest to the name of the referenced style variable. Using preset regular expression rules, verify whether the generated code conforms to the preset coding specifications of the target project; Compare the component hierarchy of the generated code with the node hierarchy of the original DSL data to check for any missing key elements; The review report is in JSON format, and the verification results are divided into P0, P1 and P2 levels according to priority. The P0 level is used to indicate error items that will cause compilation or running failure, the P1 level is used to indicate defects that do not conform to the project's preset specifications, and the P2 level is used to indicate suggested optimization items. The repair and output module specifically repairs failed items according to the priority order of P0, P1, and P2 levels; wherein, errors at the P0 level are repaired immediately, defects at the P1 level are repaired in a standardized manner, and suggested optimization items at the P2 level are marked with TODO comments in the code, and then the final repaired code file is output.

[0037] In this embodiment, preferably, the DSL acquisition and parsing module further includes: If the DSL data contains component document links, then the usage documentation for the corresponding component is obtained from the component document links; The design tool's design draft to code conversion interface is used to obtain general reference code, and the layout structure, element hierarchy relationship and text content are extracted from the general reference code as structural understanding reference. The general reference code is not directly used for code generation. The target project's location command determines the target project's root path according to the following priority: The project path explicitly specified by the user; The current working directory contains the project identifier file; Search upwards from the current directory, level by level, for the parent directory containing the project identifier file; If none of the above can be found, ask the user.

[0038] Since the apparatus described in Embodiment 2 of the present invention is an apparatus used to implement the method of Embodiment 1 of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the method described in Embodiment 1 of the present invention, and therefore will not be described again here. All apparatuses used in the method of Embodiment 1 of the present invention fall within the scope of protection of the present invention.

[0039] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.

[0040] Example 3 This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement any of the implementation methods in Embodiment 1.

[0041] Since the electronic device described in this embodiment is the device used to implement the method in Embodiment 1 of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in Embodiment 1 of this application. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection of this application.

[0042] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.

[0043] Example 4 This embodiment provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it can implement any of the implementation methods in Embodiment 1.

[0044] Example 5 This embodiment uses the front-end development scenario of an enterprise-level back-end management system as an example to detail the specific implementation process of this method. The target project is based on the React + TypeScript technology stack, uses MobX for state management, uses SCSS as a style preprocessor and defines a complete design variable system, and uses Ant Design for the UI component library, encapsulating advanced components such as SuperTable, SuperModal, and SuperButton that conform to business design specifications. The task is to convert a page design draft provided by the product manager into a front-end code file that conforms to the project's existing specifications.

[0045] Step S1: Locate the target item and perform a context scan. First, the root path of the target project is determined. The system performs project location in the following priority order: It checks whether the user explicitly specified the project path in the command; if so, it uses it directly. Otherwise, it checks whether the current working directory contains a project identifier file (e.g., .umirc.ts, package.json, etc.); if it does, the current directory is determined as the project root path. If the current directory does not contain the identifier file, it searches upwards from the current directory, level by level, until a directory containing the project identifier file is found. If the project is not found even after traversing to the root directory of the file system, the system prompts the user to manually specify the project path through the interactive interface. In this embodiment, the user specified the project path as / home / developer / project-x in the command.

[0046] After determining the root path of the target project, the system performs a parallel context scan of the project's file system, which includes: The first scan operation involves scanning the target project's page and component directories. The system traverses all subdirectories under ` / home / developer / project-x / src / views / `, checking each subdirectory for an `index.tsx` file. If found, the page path and name are recorded in the existing page list, for example, ` / src / views / dashboard / index.tsx` or ` / src / views / user-management / index.tsx`. Simultaneously, the system traverses all subdirectories under ` / home / developer / project-x / src / components / `, checking each subdirectory for an `index.tsx` file. If found, the name and path of the common component are recorded in the existing common component list, for example, ` / src / components / super-table / index.tsx` or ` / src / components / super-modal / index.tsx`. Through this scan, the system learns that the target project has a total of 23 existing pages and 15 existing common components.

[0047] The second scan operation: Scanning the target project's data layer directory. The system traverses all .ts files under the / home / developer / project-x / src / stores / directory to obtain a list of existing state management Stores, such as userStore.ts, permissionStore.ts, and appStore.ts. Simultaneously, the system traverses all subdirectories under the / home / developer / project-x / src / services / directory, checking each subdirectory for an index.ts file to obtain a list of existing service layers, such as / src / services / user / index.ts and / src / services / order / index.ts. Through this scan operation, the system learns that the target project has a total of 7 Stores and 12 Services.

[0048] The third scan operation: Reading the style variable definition file of the target project. The system reads the file ` / home / developer / project-x / src / styles / variable.scss`, parses the defined SCSS variables and their values, and constructs a set of style variable definitions, such as `$color-primary: #3569fd`, `$color-danger: #ff4d4f`, `$color-success: #52c41a`, `$color-warning: #faad14`, `$color-text: rgba(0,0,0,0.88)`, `$padding-middle: 16px`, `$padding-small: 12px`, `$padding-large: 24px`, `$margin-middle: 16px`, `$margin-small: 12px`, and `$margin-large: 24px`. Through this read operation, the system obtains a total of 56 style variable definitions.

[0049] Through the parallel scanning operations described above, the system constructs a complete project context knowledge base. This knowledge base records the project's existing page list, common component list, Store list, Service list, and style variable definition set, serving as the factual basis for all subsequent generation and verification steps. The core of this step lies in the "read-before-write" principle, meaning that before generating any code, the context must be established by actually reading the target project's file system, ensuring that all subsequent steps are based on real-world project assets, rather than relying on reasoning or memory from a large language model.

[0050] Step S2: Obtain the design draft DSL data The user provides a link to the design tool; in this example, it's a Figma design draft link: https: / / www.figma.com / file / abc123 / DesignSystem?node-id=456%3A789. The system extracts the file identifier (fileId) as abc123 and the layer identifier (nodeId) as 456:789 from this link.

[0051] The system calls the Figma REST API, sending a GET request to https: / / api.figma.com / v1 / files / abc123 / nodes?ids=456:789 with a valid access token to retrieve the structured DSL data for this design layer. The DSL data contains a complete node tree structure, with each node containing the following attributes: node type (e.g., FRAME, TEXT, RECTANGLE, INSTANCE), node name, size (width, height), position coordinates (x, y), fill color (fills), text content (characters), font information, and a list of child nodes.

[0052] Simultaneously, the system checks whether the DSL data contains component document links (componentDocumentLinks). If so, it retrieves the usage documentation for each corresponding component, which is used as a reference for correct component usage during subsequent component mapping. In this embodiment, the DSL data contains references to basic Ant Design components but does not contain document links for project-custom components; therefore, this step only retrieves the DSL data itself.

[0053] In addition, the system calls Figma's REST API endpoint to retrieve generic D2C reference code for the design drafts. It's important to note that the generic code returned by this D2C interface is only used as a reference for structural understanding. The system only extracts structural information such as the overall page layout, element hierarchy, and text content from it; it does not directly use this generic code for code generation. This constraint is the second line of defense against code illusion, preventing generic code that does not conform to project specifications from being mixed into the final output.

[0054] In this embodiment, the root node of the DSL data is a FRAME type node with a size of 1440×900, containing three sub-FRAME nodes, corresponding to the search area, table area, and operation area, respectively. The search area contains an input box node, a drop-down selector node, and a query button node; the table area contains a table structure node with column header rows and data rows; and the operation area contains a pop-up trigger button node.

[0055] Step S3: DSL Analysis and Page Type Identification The system performs structured analysis on the DSL data obtained in step S2, and automatically identifies page types and component requirements.

[0056] Page type identification is based on the functional semantics of DSL nodes rather than their appearance features. The system traverses the DSL node tree, extracting the node type, name, hierarchical relationship, and child node combination pattern, and matches them with preset page type identification rules. These page type identification rules include at least the following five categories: List page recognition: When the direct child nodes of the DSL root node contain both a combination of nodes with search functionality (such as a container node containing a text input box, drop-down selector, and query button) and a table structure node with multi-row and multi-column data display functionality, the system recognizes the page as a list page.

[0057] Form page recognition: When the direct child nodes of the DSL root node contain three or more form control nodes of different types (such as input boxes, drop-down selectors, date pickers, radio buttons, check boxes, etc.) and contain submit button nodes, the system recognizes the page as a form page.

[0058] Detail page recognition: When the direct child nodes of the DSL root node contain tab structure nodes (such as containers containing multiple tab titles and corresponding content panels) and description list structure nodes (such as containers in key-value pair display format), the system recognizes the page as a detail page.

[0059] Pop-up window recognition: When the root node of the DSL itself or its parent node is a small container with a fixed aspect ratio (e.g., width ≤ 600px and height ≤ 400px) and contains confirmation and cancel operation button nodes, the system recognizes the page as a pop-up window.

[0060] Composite page recognition: When the DSL structure has a combination of features of two or more of the above page types, the system recognizes the page as a composite page and splits it into corresponding sub-component requirements according to functional areas.

[0061] In this embodiment, the child nodes of the DSL root node simultaneously contain a search area (including input boxes, drop-down selectors, and query buttons) and a table structure area (including column headers and data rows), and do not contain the characteristics of a tab structure or a fixed-size pop-up container. Therefore, the system identifies this page type as a list page. Simultaneously, the system extracts a component requirement list from the DSL node, including: 1 input box component requirement, 1 drop-down selector component requirement, 1 table component requirement (containing 5 columns), 2 button component requirements (1 query button and 1 operation area trigger button), and 1 pop-up component requirement (used to hold a new or edit form).

[0062] Step S4: Mapping table-driven component selection and style planning This step uses a deterministic mapping table to replace the free reasoning of the large language model to complete component selection and style mapping.

[0063] Component mapping mechanism The system loads a pre-defined mapping table of DSL visual features to project components. This mapping table is pre-configured based on the target project's existing component library. The mapping table includes at least the following four types of component mapping rules: Layout mapping: When the DSL node is the top-level container of the page, it is mapped to the LayoutPc component of the target project; when the DSL node is a container of multiple elements arranged horizontally, it is mapped to the Row / Col or Flex component.

[0064] Data display mapping: When the DSL node is a multi-row, multi-column data table structure, it is mapped to the SuperTable component of the target project (a custom-encapsulated advanced table component for the project); when the DSL node is a key-value pair display format, it is mapped to the Descriptions component.

[0065] Form class mapping: When the DSL node is a single-line text input control, it is mapped to an Input component; when the DSL node is a drop-down selection control, it is mapped to a Select component; when the DSL node is a date picker control, it is mapped to a DatePicker component.

[0066] Operation class mapping: When the DSL node is the main operation button, it is mapped to the SuperButton component of the target project (a custom-encapsulated advanced button component of the project); when the DSL node is a pop-up container, it is mapped to the SuperModal component of the target project (a custom-encapsulated advanced pop-up component of the project).

[0067] The mapping table contains multiple sets of component mapping rules corresponding to different page types. Based on the page type identified in step S3 (a list page in this embodiment), the system retrieves a set of component mapping rules corresponding to the list page from the mapping table. This set of rules prioritizes SuperTable as the data display component and associates it with the form component combination required for the search area.

[0068] The mapping process follows a project component priority principle: when the target project has custom wrappers around basic UI components, these custom wrappers must be used instead of the basic UI components. Specifically, in this embodiment, the target project's ` / src / components / ` directory contains a `super-table` component, so the system maps the table structure nodes in the DSL to `SuperTable` components instead of the original Ant Design `Table` components; similarly, if a `super-modal` component exists, the system maps the popup container nodes to `SuperModal` components instead of the original `Modal` components; and if a `super-button` component exists, the system maps the main operation button to `SuperButton` components instead of the original `Button` components. For the input boxes and dropdown selectors in the search area, since the target project has not custom-wrapped these basic components, the system maps them to Ant Design's `Input` and `Select` components.

[0069] Through the aforementioned deterministic mapping mechanism, the system maps the component requirements identified in step S3 to the actual target components that exist in the project context knowledge base: Input box → Input, Drop-down selector → Select, Table → SuperTable, Query button → SuperButton, Operation area trigger button → SuperButton, Pop-up container → SuperModal.

[0070] Automatic style mapping mechanism The system simultaneously performs a deterministic mapping of style values. The system matches the style values ​​(including color values ​​and spacing values) extracted from the DSL data in step S2 with the set of style variable definitions constructed in step S1.

[0071] The style mapping rules specifically include: comparing the color values ​​in the DSL style value set with the color variable set of the target project one by one. If the color values ​​are equal or the color difference is less than a preset threshold (e.g., △E≤2), then the DSL color value is mapped to the corresponding color variable name. For example, if a fill color value in the DSL is #3569fd, and the system finds $color-primary: #3569fd in the style variable definition set, then the color value is mapped to $color-primary.

[0072] The spacing values ​​in the DSL style value set are compared one by one with the spacing variable set of the target item. If the spacing values ​​are equal or the difference is within the preset tolerance range (e.g., ±1px), the DSL spacing value is mapped to the corresponding spacing variable name. For example, if an inner padding value in the DSL is 16px, and the system finds $padding-middle: 16px in the style variable definition set, then the spacing value is mapped to $padding-middle.

[0073] When a DSL style value cannot be precisely matched, the system calculates the distance between the value and all style variable values ​​in its category (color or spacing), selects the style variable with the closest value for mapping, and adds a TODO comment to the generated code to remind the developer to manually verify it. For example, if a color value in the DSL is #3570fd and cannot be precisely matched with any style variable, the system calculates that its color difference with $color-primary: #3569fd is the smallest, so it is mapped to $color-primary and marked with / / TODO: Color value needs to be verified.

[0074] In this embodiment, the background color value of the search area in the DSL is #f5f7fa. The system did not find a completely matching variable in the style variable definition set. Calculation showed that it is closest to $color-bg-secondary: #f5f6f8, so it is mapped to $color-bg-secondary and marked with a TODO comment. The table border color value #e8ecf1 precisely matches $color-border and is directly mapped. All spacing values ​​can be found to be exactly matched in the style variable definition set and do not require annotation.

[0075] Step S5: Code generation for template library constraints This step generates code based on a predefined standardized code template library, rather than being freely generated by a large language model. The standardized code template library predefines code structures and placeholders that conform to the target project specifications for each level of code file. The system fills the target component name and style variable name obtained from step S4 into the corresponding placeholder positions to generate a complete code file.

[0076] The system generates code files sequentially according to the following preset file generation order: First, the code files for the type definition layer are generated. The system creates or expands type definition files in the ` / home / developer / project-x / src / types / ` directory, defining the request parameter interfaces and response data structure interfaces involved in this list page. The type definition template must include at least: declaring types using the `interface` keyword, using Pascal naming conventions with the first letter capitalized, and including JSDoc comments for each attribute explaining the meaning of the field. In this embodiment, the system generates the ` / src / types / user-list.ts` file, defining two interfaces: `IUserListParams` (query parameters) and `IUserListResponse` (response data).

[0077] Second, generate the service layer code files. The system creates corresponding service files in the ` / home / developer / project-x / src / services / ` directory, encapsulating the API call logic. Key constraints of the service layer template include: using the project's unified generic HTTP call method (httpService). <t>() Initiate network requests; use standard REST methods such as GET and POST for naming; each API method carries a JSDoc comment explaining its function, parameters, and return value; for uncertain API paths, mark / / TODO: API path needs to be confirmed. In this embodiment, the system generates the file / src / services / user-list / index.ts, defining the getUserList method, with the API path being / api / v1 / users. Since this path is inferred by the system based on DSL metadata, it is uncertain, therefore mark / / TODO: API path needs to be confirmed.

[0078] Third, the code files for the state management layer are generated. The system creates a corresponding Store file in the / home / developer / project-x / src / stores / directory to manage the state data of this list page. Key constraints of the Store layer template include: the class constructor must call makeAutoObservable(this) to implement reactive state; state properties are declared using the @observable decorator; state assignments after asynchronous operations (such as API calls) must be wrapped in runInAction() to ensure reactive updates; error handling uniformly uses the to() pattern (i.e., the destructuring assignment method [err, response]) to catch asynchronous exceptions. In this embodiment, the system generates the / src / stores / user-list-store.ts file, which contains state properties such as loading, userList, and pagination, as well as the fetchUserList asynchronous operation method and the setSearchParams synchronous operation method.

[0079] Fourth, generate the view layer code files. This is the core file for code generation. The system creates the corresponding view component files in the ` / home / developer / project-x / src / views / ` directory. The key constraints of the view layer template include at least: Use functional component declarations (function ComponentName() { ...}) instead of arrow functions (const ComponentName = () => { ...}) to ensure that component names are displayed correctly in React DevTools; The Props interface is uniformly named interface IProps, and contains all external property definitions received by the component. Component exports must be wrapped with an observer() higher-order component to enable the component to respond to changes in MobX state; All user-facing interface text must be wrapped with the internationalization function intl.t(), for example, intl.t('user.list.title'), to ensure multilingual support; The style file adopts the CSS Modules specification and is named index.module.scss. It is imported using the command `import stylesfrom '. / index.module.scss'`. The style class name is used in the format `className={styles.className}` to ensure style isolation and avoid global pollution.

[0080] When the logic complexity of a view layer component exceeds a preset threshold (e.g., the table has more than 10 columns, or the search criteria have more than 5 fields), the system automatically extracts the logic related to table column configuration and search criteria management into a separate custom Hook file (e.g., useColumns.ts, useSearch.ts) to maintain the simplicity and maintainability of the main view component. In this embodiment, since the number of table columns is 5, which does not exceed the threshold, the system does not extract the Hook file.

[0081] In this embodiment, the system generates ` / src / views / user-list / index.tsx` as the main view component, uses the SuperTable component and configures the `columns` property (5 columns), uses Input and Select components to construct the search area, uses the SuperButton component as the query button, and uses the SuperModal component as the pop-up container. Simultaneously, the corresponding style file ` / src / views / user-list / index.module.scss` is generated.

[0082] Fifth, generate the code file for the page entry layer. The system generates a Page file containing only the route entry point in the / home / developer / project-x / src / pages / directory. The Page file is a thin file, containing no business logic. It directly imports the view layer component generated in step S4-4 and exports it by default to meet the project's routing configuration conventions. In this embodiment, the system generates a file / src / pages / user-list / index.tsx, which only imports and exports the UserListView component.

[0083] Through the layer-by-layer generation of the aforementioned standardized template library, all code files produced by the system maintain strict consistency in terms of structure, naming conventions, export methods, state management patterns, and style isolation methods, eliminating the uncertainty brought about by the free interpretation of large language models.

[0084] Step S6: Cross-validation of independent sub-agents This step initiates a large language model review instance independent of the code generation context, cross-validating all code files generated in step S5 within a completely independent dialogue context. The core principle of this review sub-agent is zero trust; that is, it does not trust any judgments made during the code generation phase, and all references and calls must be verified for their existence by actually reading the file system. The review sub-agent uses the same underlying model as the large language model generation step, but employs an independent dialogue context and is given different system prompts than the generation agent, focusing on the review task rather than the generation task.

[0085] The review process consists of the following six stages: S6-1. Extracting Review Targets The review sub-agent reads all code files generated in step S5, including type definition layer files, service layer files, state management layer files, view layer files, and page entry layer files. For each file, the review sub-agent performs the following extraction operations: Extract all import statements and their import paths from the code file, such as `import SuperTable from '@ / components / super-table'` and `import { observer} from 'mobx-react-lite'`. Extract all used component names and their property lists from the code file, such as... <supertable tableKey="userList" columns="{columns}" / > The component name is SuperTable, and its properties are tableKey and columns. All referenced SCSS variable names are extracted from the code file, such as $color-primary in color: $color-primary. All Store and Service call information is extracted from the code file, such as userListStore.fetchUserList().

[0086] In this embodiment, the review sub-agent extracted a total of 23 import statements, 7 instances of component usage, 12 instances of SCSS variable references, and 3 instances of Store calls from the 5 generated code files.

[0087] S6-2 Import Path Verification The inspection sub-agent verifies the existence of each import path extracted by S6-1 by accessing the target project's file system. The verification logic is as follows: convert the import path to an absolute path or a path relative to the project root directory, and call the file system's `fs.existsSync()` or `fs.accessSync()` method to check if the target file exists. For import paths using path aliases (e.g., `@ / `), the inspection sub-agent resolves the alias to the actual path based on the project configuration file (e.g., the `paths` configuration in `tsconfig.json`) before performing verification.

[0088] If the target file exists, the verification result is PASS. If the target file does not exist, the verification result is FAIL. The review sub-agent calculates the string edit distance (Levenshtein distance) between the import path and all file paths in the project's file system, selects the file path with the smallest distance as the closest matching file path, and appends it to the verification result for the developer's reference.

[0089] In this embodiment, the sub-agent verification found that the file / src / components / super-table / index.tsx corresponding to import { SuperTable} from '@ / components / super-table' actually exists, and the verification passed. Of all 23 import statements, 22 passed the verification, and 1 failed: the file / src / utils / date.ts corresponding to import { formatDate} from '@ / utils / date' does not exist. After calculation, the sub-agent found the closest matching file to be / src / utils / format.ts.

[0090] S6-3, Component Property Validation The sub-agent examines each component's usage and attribute list extracted by S6-1. It reads the Props interface definition from the component's source code file and verifies that the name and type of each attribute match the interface definition. The verification logic is as follows: Locate the component's source code file (e.g., / src / components / super-table / index.tsx), parse the attribute list of the exported Props interface (e.g., interface IProps or type Props), perform exact string matching between the actual used attribute names and the attribute names defined in the interface, and perform type matching between the actual used attribute value types and the attribute types defined in the interface.

[0091] If all properties are defined in the interface and their types match, the validation result is PASS. If any property is not defined in the interface, or the property value type does not match the interface definition, the validation result is FAIL. Inspect the sub-agent with the specific error reason (e.g., "Property 'tableKey' is not defined in the interface IProps" or "Property 'columns' should be of type 'ColumnType[]', but is actually 'any[]'").

[0092] In this embodiment, the sub-agent verification is reviewed. <supertable tableKey="userList" columns="{columns}" pagination="{pagination}" / > The component usage was verified by reading the IProps interface definition in the file / src / components / super-table / index.tsx, confirming that the three properties tableKey, columns, and pagination are all defined in the interface and their types match. The verification passed. The other six instances of component usage also passed verification.

[0093] S6-4, Style Variable Validation Examine each SCSS variable reference extracted by the sub-agent in S6-1, search for the variable name in the style variable definition file read in step S1, and verify whether it actually exists. The verification logic is as follows: perform an exact string match of the variable name in the style variable definition set.

[0094] If the variable exists in the style variable definition file, the validation result is PASS. If the variable does not exist in the style variable definition file, the validation result is FAIL. The review sub-agent calculates the string edit distance between the variable name and all variable names in the style variable definition set, selects the variable name with the smallest distance as the closest matching variable name, and appends it to the validation result for the developer's reference.

[0095] In this embodiment, of the 12 SCSS variable references, 11 passed the validation and 1 failed: the $color-bg-light referenced in color: $color-bg-light does not exist in the style variable definition set, and the inspector sub-delegate is assigned the closest matching variable after calculation as $color-bg-secondary.

[0096] S6-5, Code Pattern Compliance Check The review sub-agent uses a pre-defined set of regular expression rules to verify whether the generated code conforms to the target project's pre-defined coding standards. The regular expression rule set is pre-configured based on the target project's coding standards and includes at least the following check rules: Component export format check: Use the regular expression `export default observer(\s*\w+\s*\)` to verify whether view layer components are exported using the `observer()` higher-order component wrapper. Props interface naming check: Use the regular expression `interface IProps` to verify whether the Props interface follows the IProps naming convention. CSS Modules file naming check: Verify that style file names end with `.module.scss`. Store injection method check: Verify that the Store is correctly obtained through the `useStore()` hook or dependency injection. Internationalized text wrapping check: Use the regular expression `intl.t(['"].+['"]\)` to verify that all user-facing interface text is wrapped by the `intl.t()` function.

[0097] If all rule checks pass, the validation result is PASS. If any rule check fails, the validation result is FAIL, and the review sub-agent should include the specific reason for the failure and the code location (file path plus line number).

[0098] In this embodiment, all code pattern compliance checks passed, and the generated code conformed to project specifications in terms of component export format, Props interface naming, CSS Modules file naming, Store injection method, and internationalized text wrapping.

[0099] S6-6, Design Draft Reproducibility Check The review sub-agent compares the component hierarchy of the generated code with the node hierarchy of the original DSL data to check whether key elements were omitted during code generation. The verification logic is as follows: extract key element nodes (such as button nodes, input box nodes, table column nodes, etc.) from the original DSL data, extract the corresponding component usage information from the generated code, and compare whether the quantity and type of the two are consistent.

[0100] If all key elements are implemented in the generated code, the verification result is PASS. If there are key elements in the DSL but missing in the generated code, the verification result is FAIL, and the sub-agent is reviewed along with a list of missing elements.

[0101] In this embodiment, the DSL includes one input box, one drop-down selector, one table (5 columns), and two buttons. The generated code includes one Input component, one Select component, one SuperTable component (5 columns), and two SuperButton components. The key elements correspond one-to-one, and the verification is successful.

[0102] Review report output and automatic repair After the above six stages of verification are completed, the review sub-agent outputs a structured JSON format review report. The review report includes the result (PASS / FAIL) for each check, specific evidence (file path and line number), and remediation recommendations. Verification results are categorized into three priority levels: P0 level: Indicates errors that will cause compilation or runtime failures, such as missing import paths or undefined component properties in interfaces. P1 level: Indicates defects that do not conform to project specifications, such as missing SCSS variables or missing internationalization wrappers. P2 level: Indicates suggested optimizations, such as code splitting suggestions and performance optimization suggestions.

[0103] In this embodiment, the review report includes 0 P0 level errors, 2 P1 level defects (import path @ / utils / date does not exist, SCSS variable $color-bg-light does not exist), and 0 P2 level optimization suggestions.

[0104] The system performs automatic repair based on the repair suggestions in the review report: For P0 level errors, the system immediately performs repair operations. Repair methods include: correcting the erroneous import path to the closest matching path recommended by the inspected sub-delegates, correcting the component attribute name to the actual name existing in the interface definition, and correcting type errors, etc.

[0105] For P1 level defects, the system performs standardization fixes. Fixes include: replacing non-existent SCSS variables with the closest matching variable recommended by the inspector sub-agent; adding an `intl.t()` wrapper to text lacking an internationalization wrapper; and adding an `observer()` higher-order component to components lacking an `observer` wrapper.

[0106] For P2-level optimization suggestions, the system does not actively modify the code. Instead, it marks the corresponding code location with a / / TODO comment, writing the optimization suggestion into the comment content, so that developers can handle it as needed during subsequent development.

[0107] In this embodiment, the system corrects `import { formatDate} from '@ / utils / date'` to `import { formatDate} from '@ / utils / format'` (automatically correcting a P1 level defect), and replaces `$color-bg-light` with `$color-bg-secondary` (automatically correcting a P1 level defect). After the correction is complete, the system can optionally execute the TypeScript type checking command `tsc --noEmit` to compile and verify the generated code, further ensuring that the code has no type errors.

[0108] Finally, the system outputs the following deliverables to the user: a list of generated files (including the paths and responsibilities of all generated files, such as / src / views / user-list / index.tsx - the main view component of the list page), a summary of the review results (including the number of approved items, the number of failed items, and the number of items that need to be fixed), a decision explanation (including the basis for component selection, such as "the reason for choosing SuperTable as the table component: there is a custom encapsulated component in the target project" and the basis for style mapping, such as "#3569fd is mapped to $color-primary"), and a list of uncertain items (including API paths, field names, etc. that require manual confirmation by the user, such as / api / v1 / users - the API path needs to be confirmed to be correct).

[0109] The code files generated in this embodiment are compiled and tested in the project. All files are compiled using TypeScript and can run normally without any manual modification by the developer, achieving a plug-and-play, highly available code generation effect.

[0110] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0111] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0112] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0113] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0114] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.< / t>

Claims

1. A method for converting UI design drafts into code, characterized in that, Includes the following steps: Step S1: In response to the location command of the target project, scan the file system of the target project based on the read-before-write principle to build a project context knowledge base; Step S2: Obtain the DSL data of the UI design draft, perform structured analysis on the DSL data, identify page type and component requirements, and extract DSL style values ​​from the DSL data; Step S3: Based on the preset mapping table of DSL visual features to project components, determine the corresponding component mapping rule from the mapping table according to the identified page type, map the identified component requirements to the target components that actually exist in the project context knowledge base, and map the DSL style values ​​to the style variables of the target project based on the preset style mapping rule. Step S4: Based on a predefined standardized code template library, and in combination with the target component and the style variables, generate the front-end code file corresponding to the UI design draft according to a preset file generation order; Step S5: Start a large language model review instance that is independent of the code generation context, perform multi-dimensional cross-validation on the generated front-end code files, and output a review report containing the validation results and repair suggestions; Step S6: Repair the generated front-end code file according to the repair suggestions in the review report, and output the repaired final code file.

2. The method according to claim 1, characterized in that, The step S1 of building the project context knowledge base specifically includes: Scan the first preset directory of the target project to obtain a list of existing pages and a list of common components; Scan the second preset directory of the target project to obtain the status management Store list and the service layer Service list; Read the style variable definition file of the target project to obtain the actual set of style variable definitions.

3. The method according to claim 1, characterized in that, The mapping table contains multiple sets of component mapping rules corresponding to different page types, and the page types include at least list pages, form pages, detail pages, pop-ups, and composite pages; In step S3, based on the identified page type, a set of component mapping rules corresponding to the page type are retrieved from the mapping table to map the component requirement to the target component. The mapping table also includes layout class mapping, data display class mapping, form class mapping, and operation class mapping; Step S3 follows the principle of prioritizing project components. When the target project has a custom encapsulation component for the basic UI component, the custom encapsulation component is selected first instead of the basic UI component.

4. The method according to claim 1, characterized in that, The style mapping rules in step S3 specifically include: Map the color values ​​in the DSL data to the corresponding color variables in the style variables of the target project; Map the spacing values ​​in the DSL data to the corresponding spacing variables in the style variables of the target project; When the DSL style value cannot be matched precisely, the style variable with the closest value among the style variables is selected for mapping, and a TODO comment is added to the generated code.

5. The method according to claim 1, characterized in that, Step S4 involves generating the front-end code file corresponding to the UI design draft according to a preset file generation order, specifically including: First, generate the code file for the type definition layer, which is used to define the data structure; Next, generate the service layer code files to encapsulate API calls; Regenerate the code file for the state management layer to manage component state; Then, the code file for the view layer is generated, which is used to build the user interface; Finally, the code file for the page entry layer is generated to expose the route entry point; The code files of the view layer shall include at least the following constraints: use function component declarations, use the observer higher-order component to wrap exports, use the IProps naming convention for the Props interface, use internationalized function wrappers for user interface text, and use the CSS Modules specification for style files.

6. The method according to claim 1, characterized in that, Step S5 specifically involves: Read all generated front-end code files and extract the reference information to be verified contained therein; By accessing the file system of the target project, verify whether the target file referenced by each import statement actually exists; if the verification result fails, attach the path of the matching file in the project's file system that is closest to the import path; Read the source code definition of the referenced component and verify whether the attribute names and types used by the component match the source code definition. In the style variable definition file of the target project, verify that each referenced style variable exists; if the verification fails, attach the name of the matching variable in the style variable definition file that is closest to the name of the referenced style variable. Using preset regular expression rules, verify whether the generated code conforms to the preset coding specifications of the target project; Compare the component hierarchy of the generated code with the node hierarchy of the original DSL data to check for any missing key elements; The review report is in JSON format, and the verification results are divided into P0, P1 and P2 levels according to priority. The P0 level is used to indicate error items that will cause compilation or running failure, the P1 level is used to indicate defects that do not conform to the project's preset specifications, and the P2 level is used to indicate suggested optimization items. Step S6 specifically involves: repairing failed items according to the priority order of P0, P1, and P2 levels; wherein, errors at the P0 level are repaired immediately, defects at the P1 level are repaired in a standardized manner, and suggested optimization items at the P2 level are marked with TODO comments in the code, and then the final repaired code file is output.

7. The method according to claim 1, characterized in that, Step S2 further includes: If the DSL data contains component document links, then the usage documentation for the corresponding component is obtained from the component document links; The design tool's design draft to code conversion interface is used to obtain general reference code, and the layout structure, element hierarchy relationship and text content are extracted from the general reference code as structural understanding reference. The general reference code is not directly used for code generation. The target project's location command determines the target project's root path according to the following priority: The project path explicitly specified by the user; The current working directory contains the project identifier file; Search upwards from the current directory, level by level, for the parent directory containing the project identifier file; If none of the above can be found, ask the user.

8. A UI design draft to code conversion device, characterized in that, include: The context scanning module, in response to the location command of the target project, scans the file system of the target project based on the read-before-write principle to build a project context knowledge base; The DSL acquisition and parsing module acquires the DSL data of the UI design draft, performs structured analysis on the DSL data, identifies page types and component requirements, and extracts DSL style values ​​from the DSL data. The deterministic mapping module, based on a preset mapping table of DSL visual features to project components, determines the corresponding component mapping rules from the mapping table according to the identified page type, maps the identified component requirements to the target components that actually exist in the project context knowledge base, and maps DSL style values ​​to style variables of the target project based on preset style mapping rules. The template generation module, based on a predefined standardized code template library, combines the target component and the style variables to generate the front-end code file corresponding to the UI design draft according to a preset file generation order; The independent cross-validation module initiates a large language model review instance independent of the code generation context, performs multi-dimensional cross-validation on the generated front-end code files, and outputs a review report containing the validation results and fix suggestions. The repair and output module repairs the generated front-end code file according to the repair suggestions in the review report and outputs the repaired final code file.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.