Code module decoupling method and device, equipment, medium and product

By constructing a baseline dependency graph and a change impact subgraph, combined with an architecture health model and a decoupling executor, the problem of architectural degradation caused by complex code dependencies in software systems is solved, and efficient and safe decoupling operations are achieved in an agile development environment.

CN120909644APending Publication Date: 2025-11-07INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511088312.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-05
Publication Date
2025-11-07

AI Technical Summary

Technical Problem

In existing technologies, complex code dependencies in software system development lead to architectural degradation, increased maintenance difficulty, and reduced iteration efficiency. Furthermore, traditional decoupling methods cannot accurately pinpoint the root cause of problems, have high refactoring risks, and are not suitable for agile development environments.

Method used

By constructing a baseline dependency graph, generating a subgraph of the impact of changes, assessing health scores based on the architecture health model, and triggering hierarchical decoupling executors to decouple components, including functional clustering, interface isolation, and circular dependency blocking, combined with syntax, contract, and architecture verification, the accuracy and security of decoupling are ensured.

Benefits of technology

It enables real-time and accurate analysis and decoupling of code dependencies in an agile development environment, reduces refactoring risks, improves iteration efficiency and objective assessment of architectural health, and avoids unnecessary costs caused by excessive decoupling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120909644A_ABST
    Figure CN120909644A_ABST
Patent Text Reader

Abstract

The invention discloses a code module decoupling method and device, a medium and a product, which are applied to the field of financial science and technology, and comprise the following steps: acquiring a source code, and constructing a baseline dependency graph based on the source code; obtaining an incremental code, generating an influence node set according to the incremental code, and generating a change influence subgraph according to the influence node set and the baseline dependency graph; loading a predefined architecture health model, and evaluating the change influence subgraph based on the architecture health model to determine a health score; and according to the health score, triggering a decoupling actuator of a corresponding level to perform decoupling. By constructing the baseline dependency graph, a basic reference is provided for subsequent analysis of a code dependency relationship, and the interference of different language grammar differences on analysis is eliminated. And only the changed part is analyzed, so that the low efficiency of full-dose scanning is avoided, and the analysis time consumption is shortened. According to the method, the architecture risk is quantified into a specific score, a clear triggering basis is provided for subsequent decoupling operation, dependence on subjective judgment is avoided, and hierarchical automatic decoupling is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of financial technology, and in particular to a method, apparatus, device, medium, and product for decoupling code modules. Background Technology

[0002] During software system development, as requirements iterate and code size continues to expand, internal code dependencies become increasingly complex, and architectural degradation issues gradually emerge, leading to increased system maintenance difficulty and reduced iteration efficiency. To achieve effective governance of the software architecture, it is necessary to accurately grasp changes in code dependencies, promptly identify and resolve coupling problems within the architecture. Therefore, establishing a mechanism capable of real-time tracking of dependency changes, quantitatively assessing the health of the architecture, and performing targeted decoupling becomes essential.

[0003] In existing technologies, three main methods are used for code decoupling: First, full dependency analysis, which involves scanning the entire codebase at once to draw a graph of the call relationships between modules, and then using algorithms to identify and reorganize highly coupled modules; second, design pattern-driven decoupling, where developers introduce relevant design patterns according to coding standards, implement them in conjunction with code review, and rely on manual coding constraints; and third, layered architecture constraints, which involves formulating strict hierarchical call rules and using detection tools to check for illegal calls.

[0004] However, full analysis requires freezing the development process, pausing the development of new requirements, hindering business iteration, and is difficult to adapt to agile development environments; it cannot accurately locate the root cause of the problem, although it can find module coupling, it cannot track which requirement change caused it, nor can it predict whether new requirements will exacerbate the problem; refactoring is risky, large-scale code adjustments can easily trigger a chain of errors, and the cost of repair is high; and decoupling decisions rely on the architect's subjective experience, lack data support, and may mistakenly dismantle core modules, leading to performance degradation. Summary of the Invention

[0005] This invention provides a code module decoupling method, apparatus, device, medium, and product. It achieves continuous architecture governance through three stages: baseline monitoring, incremental analysis, and targeted decoupling. It solves the problems of process blockage, inability to accurately locate the root cause of problems, and high refactoring risk of traditional decoupling methods in continuous delivery environments.

[0006] According to one aspect of the present invention, a code module decoupling method is provided, the method comprising:

[0007] Obtain the source code and build a baseline dependency graph based on it;

[0008] Obtain the incremental code, generate an impact node set based on the incremental code, and generate a change impact subgraph based on the impact node set and the baseline dependency graph;

[0009] loading a predefined architecture health model, evaluating the change impact subgraph based on the architecture health model to determine a health score;

[0010] triggering decoupling of a corresponding level of decoupling actuators based on the health score.

[0011] Optionally, a baseline dependency graph is constructed based on the source code, including: converting the source code into a basic syntax tree based on a predefined syntax rule, and generating a cross-language unified abstract syntax tree node through semantic enhancement by a parsing tool; determining a distributed code repository where the source code is located, parsing the distributed code repository based on the abstract syntax tree node to generate a system-level dependency network; refining the dependency relationship of the system-level dependency network to generate an optimized dependency relationship, wherein the dependency relationship refining includes class-level dependency edges, cross-module data flow critical paths, and circular dependency markers; and modularly storing the optimized dependency relationship to generate the baseline dependency graph.

[0012] The advantage of such a setting is that it can eliminate the interference of different language syntax differences on analysis, optimize the dependency network structure to avoid redundancy, improve the subsequent retrieval and analysis efficiency through modular storage, and provide a reliable basic dependency reference for subsequent incremental analysis and change impact evaluation.

[0013] Optionally, an impact node set is generated according to the incremental code, and a change impact subgraph is generated according to the impact node set and the baseline dependency graph, including: capturing key change units in the incremental code through intelligent change capture markers; performing hybrid impact domain analysis based on the key change units to generate the impact node set, and extracting associated edges in the baseline dependency graph according to the impact node set to generate the change impact subgraph.

[0014] The advantage of such a setting is that it can accurately lock the key change part in the incremental code, analyze only the associated path to compress the time-consuming, and intuitively present the dependency structure affected by the change.

[0015] Optionally, the change impact subgraph is evaluated based on the architecture health model to determine a health score, including: calculating the change coupling degree, the module pollution index, and the architecture entropy increase corresponding to the change impact subgraph based on the architecture health model; and substituting the change coupling degree, the module pollution index, and the architecture entropy increase into a preset formula to determine the health score.

[0016] The advantage of such a setting is that it can quantify the architecture risk into a specific score, and realize objective evaluation of the change in the architecture health state caused by the change.

[0017] Optionally, the decoupling of the corresponding level decoupling actuator is triggered according to the health score, including: when the health score is less than a first threshold, grouping the intra-module classes by using a function clustering algorithm to generate a function clustering result and a module reorganization suggestion, and performing a safe migration after user visual confirmation; when the health score is greater than or equal to the first threshold and less than a second threshold, extracting the public methods of the dependent classes based on the change impact subgraph, generating an interface file, modifying the caller code to convert the specific class reference to an interface reference, and registering the implementation class binding in the container; when it is detected that there is a circular dependency in the change impact subgraph, immediately blocking the code submission.

[0018] The advantage of such an arrangement is that targeted decoupling measures can be taken according to the architecture health status, and the module reorganization in man-machine cooperation reduces subjective bias, the interface isolation reduces the module coupling degree, and the circular dependency blocking curbs the architecture degradation from the source, thereby improving the accuracy and safety of decoupling.

[0019] Optionally, the method further comprises: obtaining the refactored code, compiling the refactored code in memory through a compilation tool to generate a syntax error interception result and an error cause explanation; obtaining the original implementation class, capturing the input and output data of the original implementation class through a proxy tool to generate a contract file containing interface description, request parameters and response results, obtaining the new implementation class, verifying the consistency of the new implementation class behavior with the contract file to generate a verification result; obtaining the system architecture design rules, setting the architecture call rules based on a custom rule engine, checking whether the refactored code violates the rules, and generating a violation checking result.

[0020] The advantage of such an arrangement is that the correctness and compliance of the refactored code can be verified comprehensively from the syntax, contract and architecture three aspects, syntax errors can be intercepted in time, the behavior consistency of the new implementation class can be ensured, and the architecture design rules can be ensured, thereby reducing the defect risk caused by refactoring and improving the safety of decoupling operation.

[0021] Optionally, the method further comprises: obtaining the decoupling result, re-parsing the change file to generate an updated baseline graph; calculating re-evaluation indexes of the decoupled modules based on the updated baseline graph, wherein the re-evaluation indexes include coupling degree and cohesion degree; and when the improvement rate of the re-evaluation indexes is greater than a preset threshold, generating a successful decoupling case and storing it.

[0022] The advantage of such an arrangement is that the time effectiveness of the dependency relationship can be maintained by incrementally updating the baseline graph, the re-evaluation indexes intuitively reflect the decoupling effect, the storage of successful cases provides a reference for subsequent decoupling decisions, the decoupling strategy is continuously optimized, and the closed-loop effectiveness of architecture governance is improved.

[0023] According to another aspect of the present application, an electronic device is provided, the electronic device comprising:

[0024] at least one processor;

[0025] and a memory in communication with the at least one processor;

[0026] The memory stores a computer program capable of being executed by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the code module decoupling method according to any one of the embodiments of the application.

[0027] According to another aspect of the application, a computer readable storage medium is provided, which stores computer instructions for enabling a processor to implement the code module decoupling method according to any one of the embodiments of the application when executed by the processor.

[0028] According to another aspect of the application, a computer program product is provided, which comprises a computer program for implementing the code module decoupling method according to any one of the embodiments of the application when executed by a processor.

[0029] The technical scheme of the embodiments of the application provides a baseline dependency graph for subsequent analysis of code dependency relationships and tracking of change impacts, and provides a basic reference, can clearly present the initial dependency state between modules of the system, and eliminates the interference of different language syntax differences on analysis. Only the changed part is analyzed, avoiding the inefficiency of full scanning, quickly and accurately positioning the nodes and dependency relationships affected by the incremental code, intuitively displaying the specific impact of the change on the architecture, and shortening the analysis time. The architecture risk is quantified as a specific score, realizing real-time and objective evaluation of the change in the health state of the architecture caused by the change, providing a clear trigger basis for subsequent decoupling operations, and avoiding dependence on subjective judgment. Hierarchical and targeted automatic decoupling is realized, and appropriate decoupling actions are taken when the health score is in different intervals, which can timely process the architecture risk and avoid unnecessary costs caused by excessive decoupling.

[0030] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the application, nor is it used to limit the scope of the application. Other features of the application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS

[0031] In order to more clearly illustrate the technical solutions in the embodiments of the application, the drawings needed in the embodiment description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.

[0032] Figure 1is a flow chart of a code module decoupling method according to an embodiment of the present application;

[0033] Figure 2 is a flow chart of another code module decoupling method according to another embodiment of the present application;

[0034] Figure 3 is a structural schematic diagram of a code module decoupling device according to an embodiment of the present application;

[0035] Figure 4 is a structural schematic diagram of an electronic device implementing a code module decoupling method according to an embodiment of the present application. DETAILED DESCRIPTION

[0036] In order to make the technical personnel in the art better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should be within the scope of protection of the present application.

[0037] It should be noted that the terms "first", "second" and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0038] Embodiment one

[0039] Figure 1 A flow chart of a code module decoupling method is provided for the first embodiment of the present application. The present embodiment can be applicable to code decoupling scenarios. The method can be performed by a code module decoupling device, which can be realized in the form of hardware and / or software, and can be configured in a computer controller. As shown in the figure, the method comprises: Figure 1

[0040] S110, obtaining source code, and constructing a baseline dependency graph based on the source code.

[0041] ​The source code refers to original code files constituting a software system, and does not include non-code change files such as configuration files, for example, order service files in an e-commerce system, including code elements such as classes and methods. The baseline dependency graph is constructed by static analysis of the source code, and can reflect the dependency relationship between modules in the system, that is, classes, methods and fields.

[0042] Specifically, the baseline dependency graph construction process includes multi-language syntax analysis, cross-file dependency analysis, dependency relationship extraction and modular storage. Multi-language syntax analysis refers to using a hierarchical parsing strategy to convert source code into a basic syntax tree, and then supplementing specific language semantics to finally generate a cross-language unified abstract syntax tree node. Cross-file dependency analysis refers to dividing the parsing task according to the code package path for the distributed code repository, performing symbol collaborative parsing, and finally summarizing and establishing a system-level dependency network. Dependency relationship extraction refers to optimizing the dependency relationship through methods to class promotion, marking data flow critical path, identifying circular dependency, and avoiding excessive expansion of the graph. Modular storage refers to storing the optimized dependency graph in a graph database, while building dynamic indexes and writing in batches.

[0043] Optionally, the baseline dependency graph is constructed based on the source code, including: converting the source code into a basic syntax tree based on predefined syntax rules, and generating a cross-language unified abstract syntax tree node through a parsing tool for semantic enhancement; determining the distributed code repository where the source code is located, and based on the abstract syntax tree node, parsing the distributed code repository to generate a system-level dependency network; dependency relationship extraction is performed on the system-level dependency network to generate an optimized dependency relationship, wherein the dependency relationship extraction includes class-level dependency edges, cross-module data flow critical paths, and circular dependency markers; and the optimized dependency relationship is stored in a modular manner to generate the baseline dependency graph.

[0044] Specifically, the controller will use a hierarchical parsing strategy to parse the source code, first through lexical and syntactic layer processing, load predefined syntax rules, convert the source code into a basic syntax tree, for example, when parsing order service related code, identify classes, import key symbols, etc. Then, in the semantic enhancement layer, with the help of a parsing tool, supplement the specific semantics of the specific language, such as detecting private payment service related definitions, automatically binding to its fully qualified name, solving the ambiguity of cross-file references, and finally generating a cross-language unified abstract syntax tree node, eliminating the interference of syntax differences. The controller will start a distributed computing framework for the distributed code repository where the source code is located, and divide the parsing task according to the code package path, for example, assign order related packages and payment related packages to different computing nodes. During the parsing process, if a symbol that refers to other packages is detected, the node will initiate a query to the global symbol table, the relevant node will respond to the query and return the class definition location, and finally the master node will summarize all cross-package calls to establish a system-level dependency network.

[0045] Further, in optimizing the dependency relationship, the controller will promote the method-level dependency to class-level dependency edges, for example, multiple method calls to the same class method are combined into a single class-level dependency edge and marked with a weight. The controller will also mark the cross-module data flow critical path, only keep cross-module data flow such as the amount field of the order module being read by the payment module, and ignore the internal data transmission of the module. In addition, the controller will identify circular dependencies through related algorithms, such as marking the circular chain from the order module to the inventory module and then to the order module as a high-risk area. Finally, the controller will store the optimized dependency relationship into a graph database for modular storage, and will create dynamic indexes for high-frequency query attributes during storage to improve retrieval speed. In addition, batch compression writing can be used to handle a large number of nodes to improve writing efficiency, while synchronously calculating the cohesion and coupling degrees and other health indicators of the modules, and finally generating a baseline dependency graph.

[0046] S120, acquiring an incremental code, generating an influence node set according to the incremental code, and generating a change influence subgraph according to the influence node set and the baseline dependency graph.

[0047] Among them, the incremental code refers to the change part submitted by the developer relative to the baseline code, including modification of the original code, newly added code or deleted code. For example, in the order function optimization of the e-commerce system, modifying a method of the order service file and adding a new method are all incremental codes. The influence node set refers to the set of nodes affected by the change after mixed influence domain analysis of the change points in the incremental code. The change influence subgraph refers to the code dependency substructure affected by a specific demand change dynamically extracted from the baseline dependency graph.

[0048] Optionally, according to the incremental code, the influence node set is generated, and the change influence subgraph is generated according to the influence node set and the baseline dependency graph, including: marking the key change unit in the incremental code through intelligent change capture; performing mixed influence domain analysis based on the key change unit to generate the influence node set, and extracting the associated edges in the baseline dependency graph according to the influence node set to generate the change influence subgraph.

[0049] Specifically, when the developer submits the code, the relevant engine immediately intercepts the submission event, parses the difference file, and filters out the configuration file and other non-code changes, leaving only the core source file. For example, in the optimization of the order function of an e-commerce system, if it is identified that the payment processing method of the order service file is modified, and a discount application method is added, the file will be marked as a key change unit. Then, the controller will perform hybrid impact domain analysis based on the key change unit to generate a set of impact nodes. Specifically, a double-path tracking strategy can be used, that is, starting from the changed variable or method, all affected methods are scanned by building a definition-use chain, for example, when the discount application method modifies the amount variable, all methods that use the amount variable are included in the impact domain. At the same time, the backward control flow tracking reversely analyzes the call stack, and if the payment processing method is called by the order controller, it traces back to the caller of the order controller to form a complete call chain and include the related nodes in the impact domain. Finally, the controller initiates an induced subgraph query to the database storing the baseline dependency graph, extracts the dependency relationships associated with the impact domain, that is, matches those call, inheritance, and other relationship paths whose source or target belongs to the impact node set, and then integrates the nodes and relationships in the path to form a change impact subgraph. The subgraph automatically labels the newly added cross-module calls and modified existing interface contracts, and directly displays the dependency structure affected by the change.

[0050] S130, load a predefined architecture health model, and evaluate the change impact subgraph based on the architecture health model to determine a health score.

[0051] The architecture health model refers to a model for calculating the architecture risk quantitative indicator, i.e., the health score, in real time based on the change impact subgraph. For example, the calculation rule of the health score is: health score = baseline value - (change coupling degree x 5 + module pollution index x 3 + architecture entropy increase x 2). Wherein, change coupling degree = number of newly added cross-module dependencies ÷ number of changed code lines. Module pollution index = number of affected modules ÷ total number of system modules. Architecture entropy increase = maximum dependency depth x interface change rate. The health score refers to the architecture risk quantitative indicator calculated based on the architecture health model, which can reflect the health degree of the architecture after being subjected to a specific demand change. The level of the health score determines the trigger level of the subsequent decoupling executor.

[0052] Optionally, evaluating the change impact subgraph based on the architecture health model to determine a health score includes: calculating the change coupling degree, the module pollution index, and the architecture entropy increase of the change impact subgraph based on the architecture health model; and substituting the change coupling degree, the module pollution index, and the architecture entropy increase into a preset formula to determine the health score.

[0053] Specifically, the controller will construct a health model, analyze the change impact subgraph, and calculate three key indicators. The first indicator is the change coupling degree, which is calculated by dividing the number of newly added cross-module dependencies in the change impact subgraph by the number of code lines modified this time. For example, if this commit adds 2 cross-module calls and modifies 50 lines of code, the change coupling degree is 2 divided by 50, which is 0.04. The second indicator is the module pollution index, which is calculated by dividing the number of affected modules by the total number of modules in the system. Assuming the system has 10 modules and this change affects 3 modules, the module pollution index is 3 divided by 10, which is 0.3. The third indicator is the architecture entropy increase, which is the product of the maximum dependency depth and the interface change rate. If the maximum depth of the newly added dependency is 4 levels and the interface change rate is 0.25, then the architecture entropy increase is 4 multiplied by 0.25, which is 1.0. Then, the controller will substitute the three composite indicators into the preset health score calculation formula. For example, if the baseline value is 70 points, substitute the values calculated above, the result is 70 minus 3.1, which is 66.9 points. This result is the final determined health score.

[0054] S140, triggering decoupling of the decoupling executor corresponding to the level according to the health score.

[0055] Among them, the decoupling executor refers to the progressive decoupling engine, which is a hierarchical decoupling executor triggered in response to the architecture health score. It includes three levels of automation units: the interface isolation unit is triggered when the health score is above 40 and less than 60, and performs the actions of extracting interfaces and reversing dependencies. The module reorganization unit is triggered when the health score is less than 40, and performs the actions of function clustering analysis and visual migration. The fuse protection unit is triggered when a circular dependency is detected, and immediately blocks the submission.

[0056] Optionally, the method further comprises: obtaining the refactored code, compiling the refactored code in memory through a compilation tool to generate syntax error interception results and error cause explanations; obtaining the original implementation class, capturing the input and output data of the original implementation class through a proxy tool to generate a contract file containing interface description, request parameters and response results; obtaining the new implementation class, verifying the consistency of the new implementation class behavior with the contract file to generate a verification result; obtaining system architecture design rules, setting architecture call rules based on a custom rule engine, checking whether the refactored code violates the rules, and generating a violation check result.

[0057] Specifically, after obtaining the reconstructed code, the controller first performs syntax-level verification. The reconstructed code is compiled in memory by a compilation tool, and if a syntax error is found, the error is immediately intercepted and an error interception result is generated, together with an explanation of the error cause. For example, if the reconstructed order service file has the error "symbol not found: payment processor", it is explicitly pointed out that the cause may be that the payment processor interface is not correctly imported. Then, the controller performs contract-level verification. By obtaining the original implementation class, the input and output data of the original implementation class are captured by a proxy tool, and a contract file is generated accordingly. The contract file contains interface description, request parameters and response results, for example, in the contract file of the payment processing interface, the request parameter is recorded as 100, and the response result is recorded as the status success. Then, the new implementation class is obtained, and it is verified whether its behavior is consistent with the contract file, and then a verification result is generated. In addition, the controller also performs architecture-level verification. By obtaining the system architecture design rules, the architecture call rules are set based on the self-defined rule engine, for example, the order module is prohibited from directly depending on the payment implementation class. Then, it is checked whether the reconstructed code violates the architecture call rules, and if there is a violation, a violation check result is generated, and if the rules are violated, the release process is blocked.

[0058] Optionally, the method further comprises: obtaining the decoupling result, re-parsing the change file, and generating an updated baseline graph; calculating re-evaluation indexes of the decoupled modules based on the updated baseline graph, wherein the re-evaluation indexes include coupling degree and cohesion degree; and when an improvement rate of the re-evaluation indexes is greater than a preset threshold, generating a successful decoupling case and storing it.

[0059] Specifically, after obtaining the decoupling result, the controller re-parses the change file. At this time, only the modified part involved in the decoupling process is incrementally processed, and the entire code library is not re-scanned. According to the parsing result, the node information in the baseline graph is updated, thereby generating an updated baseline graph. Then, the controller calculates the re-evaluation indexes of the decoupled modules based on the updated baseline graph. The re-evaluation indexes include coupling degree and cohesion degree. The calculation method of the cohesion degree is the number of internal calls divided by the total number of calls. For example, the ratio of the number of internal calls to the total number of calls of the order core module after decoupling is the cohesion degree of the order core module. The coupling degree is obtained by analyzing the dependency relationship between the module and other modules. Then, the controller calculates the improvement rate of the re-evaluation indexes, which is (pre-decoupling index value - post-decoupling index value) ÷ pre-decoupling index value × 100%. When the improvement rate is greater than a preset threshold, it indicates that the decoupling operation effectively improves the architecture quality of the module. At this time, the relevant information of the decoupling, such as the dependency status before decoupling, the decoupling measures taken, the index changes before and after decoupling, etc. are sorted into a successful decoupling case, and stored in the knowledge base, providing a reference for subsequent decoupling decisions.

[0060] The technical scheme of the embodiment of the present application constructs a baseline dependency graph, thereby providing a basic reference for subsequent analysis of code dependency relationships and tracking of change influences, enabling clear presentation of initial dependency states among modules of a system and eliminating interference of different language syntax differences on analysis. Only the changed part is analyzed, thereby avoiding inefficiency of full-scan, quickly and accurately locating nodes and dependency relationships affected by incremental code, directly displaying specific influences of changes on architecture, and shortening analysis time. Architecture risks are quantified into specific scores, thereby realizing real-time and objective evaluation of changes in architecture health states caused by changes, providing clear triggering basis for subsequent decoupling operations, and avoiding subjective judgment. Hierarchical and targeted automatic decoupling is realized, appropriate decoupling actions are taken when health scores are in different intervals, thereby enabling timely processing of architecture risks and avoiding unnecessary costs caused by excessive decoupling.

[0061] Embodiment two

[0062] Figure 2 A flowchart of a code module decoupling method provided by the second embodiment of the present application, the embodiment adds a specific process of triggering decoupling of a decoupling executor of a corresponding level according to a health score on the basis of the first embodiment. The specific content of steps S210-S230 is substantially the same as that of steps S110-S130 in the first embodiment, and therefore will not be described again in the present embodiment. As shown in the figure, the method comprises the following steps. Figure 2

[0063] S210, source code is acquired, and a baseline dependency graph is constructed based on the source code.

[0064] Optionally, the baseline dependency graph is constructed based on the source code, comprising: converting the source code into a basic syntax tree based on a predefined syntax rule, and generating a cross-language unified abstract syntax tree node through semantic enhancement by a parsing tool; determining a distributed code repository where the source code is located, and parsing the distributed code repository based on the abstract syntax tree node to generate a system-level dependency network; refining dependency relationships of the system-level dependency network to generate optimized dependency relationships, wherein the dependency relationship refining comprises class-level dependency edges, cross-module data flow critical paths and circular dependency markers; and modularly storing the optimized dependency relationships to generate the baseline dependency graph.

[0065] S220, incremental code is acquired, an influence node set is generated according to the incremental code, and a change influence subgraph is generated according to the influence node set and the baseline dependency graph.

[0066] ​Optionally, the influence node set is generated according to the incremental code, and the change influence subgraph is generated according to the influence node set and the baseline dependency graph, including: capturing a key change unit in the incremental code through intelligent change capture marking; performing hybrid influence domain analysis based on the key change unit to generate the influence node set, and extracting associated edges in the baseline dependency graph according to the influence node set to generate the change influence subgraph.

[0067] S230, load a predefined architecture health model, and evaluate the change influence subgraph based on the architecture health model to determine a health score.

[0068] Optionally, the change influence subgraph is evaluated based on the architecture health model to determine the health score, including: calculating the change coupling degree, the module pollution index, and the architecture entropy increase corresponding to the change influence subgraph based on the architecture health model; and substituting the change coupling degree, the module pollution index, and the architecture entropy increase into a preset formula to determine the health score.

[0069] S240, when the health score is less than a first threshold value, grouping the intra-module classes using a functional clustering algorithm to generate a functional clustering result and a module reorganization suggestion, and performing safe migration after visual confirmation by a user.

[0070] Specifically, the first threshold value can be 40 points, and when the health score is less than 40 points, the module reorganization unit is triggered. At this time, the functional clustering algorithm is used to group the classes within the module, and the classes with similar functions are clustered into candidate subsets by analyzing the functional association and interaction frequency between the classes to generate a functional clustering result. Based on the result, a module reorganization suggestion is further generated, such as dividing the classes related to payment integration in the order module, such as payment proxy and payment verifier, to a new payment integration module, and dividing the classes related to inventory service, such as inventory calculator and inventory updater, to a new inventory service module. Then, the developer visually adjusts and confirms the attribution of the classes in the development tool, and the system performs safe migration according to the confirmation result to complete module reorganization.

[0071] S250, when the health score is greater than or equal to the first threshold value and less than a second threshold value, extracting public methods of dependent classes based on the change influence subgraph, generating an interface file, modifying the caller code to convert specific class references to interface references, and registering implementation class bindings in a container.

[0072] Specifically, the first threshold value can be 60 minutes, when the health score is greater than or equal to 40 minutes and less than 60 minutes, the interface isolation unit is triggered. The number controller identifies the direct class dependency across modules based on the change impact subgraph, such as the order service directly depending on the payment processor implementation class. Then, the public methods of the dependent class are scanned, and the corresponding interface file is automatically generated, which contains the definition of the public method. Then, the controller modifies the code of the corresponding caller, replacing the reference to the specific class with the reference to the interface. Finally, the controller also registers the binding relationship between the implementation class and the interface in the container configuration, and the non-container system realizes the binding through dynamic proxy, and completes the interface isolation.

[0073] S260, when detecting that there is a circular dependency in the change impact subgraph, immediately block the code submission.

[0074] Specifically, when detecting that there is a circular dependency in the change impact subgraph, for example, the order module depends on the inventory module, and the inventory module reversely depends on the order module to form a cycle, the fuse protection unit is triggered immediately, and the current code submission operation is blocked to prevent the circular dependency from further deteriorating the system architecture.

[0075] Optionally, the method further comprises: obtaining the refactored code, compiling the refactored code in memory through a compilation tool to generate a syntax error interception result and an error cause description; obtaining the original implementation class, capturing the input and output data of the original implementation class through a proxy tool to generate a contract file containing interface description, request parameter and response result, obtaining the new implementation class, verifying the consistency of the new implementation class behavior and the contract file, and generating a verification result; obtaining the system architecture design rules, setting the architecture calling rules based on a custom rule engine, checking whether the refactored code violates the rules, and generating a violation checking result.

[0076] Optionally, the method further comprises: obtaining the decoupling result, re-parsing the change file to generate an updated baseline graph; calculating re-evaluation indexes of the decoupled modules based on the updated baseline graph, wherein the re-evaluation indexes include coupling degree and cohesion degree; when the improvement rate of the re-evaluation indexes is greater than a preset threshold, generating a successful decoupling case and storing it.

[0077] The technical scheme of the embodiment of the application accurately divides the attribution of the classes within the module through function clustering, realizes man-machine cooperation in module reorganization in combination with user confirmation, avoids the subjectivity of splitting the module only by experience, reduces the risk of mistakenly splitting the core module, and visualizes migration to ensure the safety of the reorganization process. By automatically completing interface extraction and dependency replacement, the decoupling of the direct class dependency across modules is realized, the cost of manual coding constraints is reduced, the coupling degree between modules is reduced through dependency inversion, and the architecture flexibility is improved. By timely preventing the introduction of circular dependency into the system, the increase of architecture complexity and the increase of maintenance difficulty caused by the circular dependency are avoided, and the further degradation of the architecture is suppressed from the source.

[0078] Embodiment three

[0079] Figure 3 A structural schematic diagram of a code module decoupling device provided for embodiment three of the present application is shown. As shown, the device comprises: a baseline dependency graph construction module 310, configured to acquire source code, and construct a baseline dependency graph based on the source code; Figure 3

[0080] a change impact subgraph generation module 320, configured to acquire incremental code, generate an impact node set according to the incremental code, and generate a change impact subgraph according to the impact node set and the baseline dependency graph;

[0081] a health score determination module 330, configured to load a predefined architecture health model, and evaluate the change impact subgraph based on the architecture health model to determine a health score;

[0082] a hierarchical decoupling module 340, configured to trigger a decoupling executor of a corresponding level to perform decoupling according to the health score.

[0083] Optionally, the baseline dependency graph construction module 310 is specifically configured to: convert the source code into a basic syntax tree based on a predefined syntax rule, and perform semantic enhancement through a parsing tool to generate a cross-language unified abstract syntax tree node; determine a distributed code repository where the source code is located, parse the distributed code repository based on the abstract syntax tree node to generate a system-level dependency network; refine dependency relationships of the system-level dependency network to generate optimized dependency relationships, wherein the dependency relationship refining includes class-level dependency edges, cross-module data flow critical paths, and circular dependency markers; and modularly store the optimized dependency relationships to generate the baseline dependency graph.

[0084] Optionally, the change impact subgraph generation module 320 is specifically configured to: capture a key change unit in the incremental code through an intelligent change capture marker; perform mixed impact domain analysis based on the key change unit to generate an impact node set, and extract associated edges in the baseline dependency graph according to the impact node set to generate the change impact subgraph.

[0085] Optionally, the health score determination module 330 is specifically configured to: calculate a change coupling degree, a module pollution index, and an architecture entropy increase corresponding to the change impact subgraph based on the architecture health model; and substitute the change coupling degree, the module pollution index, and the architecture entropy increase into a preset formula to determine the health score.

[0086] ​Optionally, the hierarchical decoupling module 340 is specifically configured to: when the health score is less than the first threshold, grouping the intra-module classes using a function clustering algorithm to generate a function clustering result and a module reorganization suggestion, and performing a safe migration after user visual confirmation; when the health score is greater than or equal to the first threshold and less than the second threshold, extracting public methods of dependent classes based on the change impact subgraph, generating an interface file, modifying the caller code to convert specific class references to interface references, and registering the implementation class binding in the container; when a circular dependency is detected in the change impact subgraph, immediately blocking the code submission.

[0087] Optionally, the device further comprises a refactoring security verification module configured to: obtain the refactored code, compile the refactored code in memory through a compilation tool to generate a syntax error interception result and an error cause explanation; obtain the original implementation class, capture the input and output data of the original implementation class through a proxy tool to generate a contract file containing interface description, request parameters and response results, obtain the new implementation class, verify the consistency of the new implementation class behavior with the contract file, and generate a verification result; obtain the system architecture design rules, set the architecture call rules based on a custom rule engine, check whether the refactored code violates the rules, and generate a violation check result.

[0088] Optionally, the device further comprises a baseline graph dynamic updating module configured to: obtain the decoupling result, reparse the change file, and generate an updated baseline graph; calculate reevaluation indexes of the decoupled modules based on the updated baseline graph, wherein the reevaluation indexes include coupling degree and cohesion degree; when the improvement rate of the reevaluation indexes is greater than a preset threshold, generate a successful decoupling case and store it.

[0089] The technical scheme of the embodiment of the application provides a baseline dependency graph for subsequent analysis of code dependency relationship and tracking of change impact, clearly presents the initial dependency state between modules of the system, and eliminates the interference of different language syntax differences on analysis. Only the changed part is analyzed to avoid the inefficiency of full-scan, quickly and accurately locate the nodes and dependency relationships affected by the incremental code, intuitively display the specific impact of the change on the architecture, and shorten the analysis time. The architecture risk is quantified into a specific score to realize real-time and objective evaluation of the change-induced architecture health state change, provide clear triggering basis for subsequent decoupling operation, and avoid dependence on subjective judgment. Hierarchical and targeted automatic decoupling is realized, appropriate decoupling actions are taken when the health score is in different intervals, the architecture risk is timely processed, and unnecessary cost caused by excessive decoupling is avoided.

[0090] The code module decoupling device provided by the embodiment of the application can execute the code module decoupling method provided by any embodiment of the application, and has the corresponding function modules and beneficial effects of the execution method.

[0091] Embodiment four

[0092] Figure 4 A structural diagram of an electronic device 10 that can be used to implement embodiments of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular telephones, smartphones, wearable devices (e.g., headsets, glasses, watches, etc.), and other similar computing devices. The components shown here, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present application described and / or claimed in this document.

[0093] As shown in Figure 4 The electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., communicatively connected to the at least one processor 11, where the memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer programs stored in the read-only memory (ROM) 12 or loaded into the random access memory (RAM) 13 from the storage unit 18. Various programs and data required for the operation of the electronic device 10 can also be stored in the RAM 13. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0094] Various components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc., an output unit 17, such as various types of displays, a speaker, etc., a storage unit 18, such as a magnetic disk, an optical disk, etc., and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.

[0095] The processor 11 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs various methods and processes described above, such as a code module decoupling method.

[0096] In some embodiments, a code module decoupling method can be implemented as a computer program tangibly embodied in a computer readable storage medium, e.g., storage unit 18. In some embodiments, parts or all of the computer program can be loaded and / or installed onto electronic device 10 via, e.g., ROM 12 and / or communication unit 19. When the computer program is loaded onto RAM 13 and executed by processor 11, one or more steps of a code module decoupling method as described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform a code module decoupling method by other means, e.g., with the aid of firmware.

[0097] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a programmable logic device (PLD), a computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0098] Computer programs used to implement the methods of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the computer program, when executed by the processor, implements the functions / acts specified in the flowcharts and / or block diagrams. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine as part of a standalone software package, partially on a machine and partially on a remote machine or entirely on a remote machine or server.

[0099] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer-readable storage medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium will include one or more lines of a program of instructions in a transitory signal, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0100] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.

[0101] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), blockchain network, and the Internet.

[0102] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, and solves the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.

[0103] It should be understood that the various forms of flow shown above can be used to reorder, add or delete steps. For example, each step described in the present application can be executed in parallel, sequentially or in a different order, as long as the desired results of the technical solutions of the present application can be achieved, which is not limited herein.

[0104] The above detailed description does not constitute a limitation on the scope of protection of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. A method for decoupling code modules, characterized in that, The method comprises the following steps: acquiring source code, and constructing a baseline dependency graph based on the source code; acquiring incremental code, generating an impact node set according to the incremental code, and generating a change impact subgraph according to the impact node set and the baseline dependency graph; loading a predefined architecture health model, evaluating the change impact subgraph based on the architecture health model to determine a health score; triggering decoupling of a decoupling executor at a corresponding level according to the health score.

2. The method of claim 1, wherein, The baseline dependency graph is constructed based on the source code, comprising the following steps: converting the source code into a basic syntax tree based on a predefined syntax rule, and generating a cross-language unified abstract syntax tree node through semantic enhancement by a parsing tool; determining a distributed code repository where the source code is located, parsing the distributed code repository based on the abstract syntax tree node, and generating a system-level dependency network; refining dependency relationships of the system-level dependency network to generate optimized dependency relationships, wherein the dependency relationship refining comprises class-level dependency edges, cross-module data flow critical paths and circular dependency markers; modularly storing the optimized dependency relationships to generate a baseline dependency graph.

3. The method of claim 2, wherein, The impact node set is generated according to the incremental code, and the change impact subgraph is generated according to the impact node set and the baseline dependency graph, comprising the following steps: marking a key change unit in the incremental code through intelligent change capture; performing mixed impact domain analysis based on the key change unit to generate an impact node set, and extracting associated edges in the baseline dependency graph according to the impact node set to generate a change impact subgraph.

4. The method of claim 1, wherein, The change impact subgraph is evaluated based on the architecture health model to determine a health score, comprising the following steps: calculating a change coupling degree, a module pollution index and an architecture entropy increase corresponding to the change impact subgraph based on the architecture health model; substituting the change coupling degree, the module pollution index and the architecture entropy increase into a preset formula to determine a health score.

5. The method of claim 4, wherein, The decoupling of the decoupling executor at the corresponding level is triggered according to the health score, comprising the following steps: when the health score is less than a first threshold, grouping the classes within the module by using a function clustering algorithm to generate a function clustering result and a module reorganization suggestion, and performing safe migration after user visual confirmation; when the health score is greater than or equal to the first threshold and less than a second threshold, extracting public methods of dependent classes based on the change impact subgraph, generating an interface file, modifying the calling party code to convert specific class references to interface references, and registering implementation class bindings in a container; when it is detected that there is a circular dependency in the change impact subgraph, immediately blocking code submission.

6. The method of claim 1, wherein, The method further comprises the following steps: acquiring the refactored code, compiling the refactored code in the memory through a compilation tool to generate a syntax error interception result and an error cause explanation; acquiring an original implementation class, capturing input and output data of the original implementation class through a proxy tool to generate a contract file containing interface description, request parameters and response results, acquiring a new implementation class, verifying the consistency of the behavior of the new implementation class and the contract file, and generating a verification result; An acquisition system architecture design rule is obtained, an architecture calling rule is set based on a self-defined rule engine, it is checked whether the rule is violated after the code is reconstructed, and a rule violation checking result is generated.

7. The method of claim 5, wherein, The method further includes: Obtaining decoupling results, re-parsing the change file, and generating an updated baseline graph; Based on the updated baseline graph, re-evaluate the indicators of the decoupled modules, wherein the re-evaluation indicators include coupling degree and cohesion degree; When the improvement rate of the re-evaluation indicators is greater than a preset threshold, a successful decoupling case is generated and stored.

8. An electronic device, comprising: The electronic device includes: At least one processor; and a memory connected in communication with the at least one processor; Wherein the memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the method of any one of claims 1-7.

9. A computer storage medium, characterized in that The computer storage medium stores computer instructions for enabling the processor to implement the method of any one of claims 1-7 when executed.

10. A computer program product, characterised in that, The computer program product includes a computer program that, when executed by a processor, implements the method according to any one of claims 1-7. The computer program product includes a computer program that, when executed by a processor, implements the method according to any one of claims 1-7.

Citation Information

Cited By

  • Code architecture drift repair method and system, electronic equipment and computer storage medium

    CN121742894A