Intelligent code analysis system and method based on graph database

By using an intelligent code analysis system based on graph databases, we have solved the problems of insufficient context discovery capabilities, inflexible analysis modes, low resource utilization, and high AI model costs in existing tools. It has achieved efficient and accurate code analysis and low-cost code quality inspection, and supports incremental and full scan modes, thereby improving analysis efficiency and accuracy.

CN120951325BActive Publication Date: 2026-01-27CHENGDU FANGLIAN CLOUD CODE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511468007.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-15
Publication Date
2026-01-27
Estimated Expiration
2045-10-15

AI Technical Summary

Technical Problem

Existing code analysis tools lack a graph database-driven intelligent context discovery mechanism, which cannot automatically identify the complete dependencies and impact scope of code changes. The analysis mode is inflexible, the resource utilization is low, the cost control of AI models is difficult, the dependency modeling dimension is single, and there is a lack of a real-time graph maintenance mechanism, resulting in one-sided analysis results, long processing time, high cost, and insufficient data timeliness.

Method used

An intelligent code analysis system based on graph databases is adopted, including a dual-mode analysis control module, a code parsing module, a graph database management module, an intelligent analysis engine module, a GitLab integration module, and a visualization module. It identifies code dependencies through graph relationships and algorithms, supports incremental and full scan modes, and realizes asynchronous processing, multi-dimensional relationship modeling, intelligent block partitioning, and dynamic invocation of AI models. It also combines GitLab events for real-time graph updates.

Benefits of technology

It achieves efficient, accurate and low-cost code analysis, reduces incremental analysis response time to the second level, supports efficient processing of large-scale code with full scanning, improves analysis efficiency by 3 times, reduces AI model call cost by 50%, improves graph synchronization efficiency by 80%, and improves analysis accuracy by 30%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120951325B_ABST
    Figure CN120951325B_ABST
Patent Text Reader

Abstract

The application discloses an intelligent code analysis system and method based on a graph database, and the system realizes accurate modeling and efficient query of code complex dependence by constructing a multi-dimensional code relation graph and utilizing a graph database. The system supports incremental analysis triggered based on a GitLab Webhook event and full-scan mode triggered manually or at a fixed time, and simultaneously integrates multiple AI models, dynamically calls lightweight or deep analysis models, and optimizes AI calling cost through intelligent context filtering and token rate control mechanism. The application significantly improves the accuracy, efficiency and real-time performance of code analysis, and the AI analysis accuracy is improved by more than 30%, the analysis time of large projects is shortened by 60%, and the AI calling cost is reduced by 50%, which is suitable for enterprise-level code quality management and control and DevOps process integration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of software engineering and artificial intelligence, and in particular to an intelligent code analysis system and method based on graph databases, for automated code quality detection, security vulnerability scanning and code review. Background Technology

[0002] Code analysis is a systematic evaluation method used to detect and optimize potential problems in software code. It automatically detects and evaluates code structure, syntax, logic, and potential errors without running the program, aiming to identify defects early and improve code quality and security. Existing code analysis tools mainly suffer from the following problems:

[0003] 1. Insufficient context discovery capability: Traditional code analysis tools only analyze the changed files themselves and lack a graph database-driven intelligent context discovery mechanism. They cannot automatically identify the complete dependencies and scope of impact of code changes, resulting in one-sided and inaccurate analysis results.

[0004] 2. Lack of flexible analysis modes: Existing tools typically only support a single full analysis mode, unable to flexibly switch between incremental analysis and full scan according to actual needs. For code changes during daily development, there is a lack of real-time incremental analysis capabilities based on Webhook events; for project initialization or periodic checks, there is a lack of efficient full scan mechanisms.

[0005] 3. Low analysis efficiency and resource utilization: For large projects, existing tools often adopt a simple full analysis approach and lack intelligent block-based strategies based on dependencies, resulting in long analysis time and high resource consumption, which cannot meet the development needs of rapid iteration.

[0006] 4. Difficulty in controlling AI model costs: Existing AI code analysis tools lack effective cost control mechanisms and intelligent context filtering strategies. Frequent calls to AI models lead to excessive costs, and the analysis depth cannot be dynamically adjusted according to code complexity.

[0007] 5. Single-dimensional dependency modeling: Traditional tools cannot build multi-dimensional code relationship graphs and lack the ability to model multi-level relationships at the file, class, method, and field levels, making it difficult to conduct in-depth impact analysis and business relevance calculation.

[0008] 6. Lack of real-time graph maintenance mechanism: Existing tools cannot achieve incremental graph updates based on Git events, and lack efficient graph synchronization and maintenance strategies, resulting in insufficient timeliness and accuracy of code relationship data. Summary of the Invention

[0009] To address the aforementioned technical problems, this invention provides an intelligent code analysis system and method based on a graph database.

[0010] This invention is achieved using the following technical solution:

[0011] Firstly, the intelligent code analysis system based on graph databases includes the following modules:

[0012] Dual-mode analysis control module: Unified scheduling and management of incremental analysis mode and full scan mode, using Spring Boot asynchronous processing mechanism to achieve concurrent execution and resource isolation of the two modes;

[0013] Code parsing module: Parses Java code, extracts code entities and their relationships, constructs an abstract syntax tree and converts it into graph database nodes; supports both incremental and batch parsing modes, and optimizes parsing strategies for different analysis scenarios;

[0014] The graph database management module constructs multi-dimensional code relationship graphs at the file, class, method, and field levels, enabling the creation, deletion, modification, and querying of nodes and dynamic maintenance of relationships. It identifies call chains, inheritance relationships, and field references through graph relationships and algorithms, constructs multi-level dependencies between code entities, supports complex relationship queries using the Cypher query language, and implements an incremental graph update mechanism based on Git events.

[0015] Intelligent Analysis Engine Module: Intelligent code file segmentation, segmentation results support intelligent context discovery based on graph relationships and weight algorithms, automatically expand direct and indirect dependencies of the code, select lightweight or deep AI models according to the analysis mode, and perform intelligent context filtering and cost control based on token budget; integrates multiple AI models, and realizes code quality detection, security vulnerability scanning and design pattern recognition functions through AI model services;

[0016] GitLab Integration Module: Receives and parses Git events through GitLab services and Webhook event analysis services, enabling automatic triggering of incremental code analysis and graph updates;

[0017] Visualization module: Provides a web interface to display analysis results, supporting graph visualization, report generation, and real-time monitoring.

[0018] Specifically, the incremental analysis mode automatically triggers code change analysis by listening to GitLab Webhook events; the full scan mode provides manual triggering and scheduled functions through API interfaces or management interfaces, supporting both security scanning and comprehensive analysis; the incremental analysis mode and the full scan mode are executed concurrently through an asynchronous task queue to avoid resource conflicts.

[0019] Specifically, the intelligent analysis engine module supports a dynamic invocation strategy based on analysis patterns, employing a lightweight model for incremental analysis and a deep analysis model for full scan.

[0020] Specifically, the visualization module includes the following sub-modules:

[0021] Full scan management submodule: Performs a comprehensive code quality and security scan on the project, supports manual triggering and batch scanning, and provides detailed scan reports and history records;

[0022] Scheduled Scan Configuration Submodule: Configures automatic scheduled scans for the project, supporting weekly full scans and daily security scans, and sets scan priorities and project scope;

[0023] Code graph visualization submodule: Displays code structure and dependencies in a graphical way, supports drag-and-drop, viewing and clicking to highlight changes to code, its affected paths and dependent modules;

[0024] Project Management Submodule: Manage scanned projects, view project health status and quality trends, configure project background files, and monitor changes in project quality;

[0025] System monitoring submodule: Monitors system running status, views the scan task queue, and analyzes system performance metrics;

[0026] Settings Center submodule: Configure system parameters and AI model parameters, manage user permissions, set general prompt words, and customize scanning rules and quality standards.

[0027] On the other hand, the intelligent code analysis method based on graph databases includes the following steps:

[0028] Step S1: Receive code analysis request, parse the parameters of the request, and determine whether the analysis mode is incremental analysis mode or full scan mode;

[0029] Step S2: Incremental analysis mode listens for and parses GitLab Webhook events through the GitLab integration module to obtain code change information; full scan mode pulls the full code of the project branch through GitLab, parses the code, and updates or builds a multi-dimensional relationship graph based on the graph database management module.

[0030] Step S3: Intelligent selection of block segmentation strategy. Based on the constructed multi-dimensional relationship graph of the project, the project code is intelligently segmented into multiple code blocks with related dependencies through graph dependency relationships and weight algorithms.

[0031] Step S4: Intelligent context enhancement and filtering, loading the complete context or changing code based on graph dependencies and weight algorithms, analysis configuration and AI model quotas;

[0032] Step S5: Set up a rate limiting mechanism and perform a rate check based on the rate limit of the AI ​​service token; if the check fails, call the sliding window algorithm to limit the rate and calculate the waiting time until the rate check passes before calling the model.

[0033] Step S6: Dynamically select incremental analysis mode and full scan mode, and call the lightweight model and deep analysis model respectively to judge the results;

[0034] Step S7: If the result judgment is successful, the result is parsed into JSON. If the parsing is successful, the result is cached. If the result judgment or parsing fails, an exception or rate limiting prompt is returned. Finally, the analysis result is returned.

[0035] Specifically, step S2 further includes code parsing and code graph construction, which specifically includes:

[0036] The code is parsed and analyzed using the Abstract Syntax Tree (AST).

[0037] Based on the call relationship, extract the relationship and construct a multi-dimensional relationship;

[0038] Stores graphs and drives graph databases;

[0039] Index optimization enables high-performance graph queries.

[0040] Specifically, step S3, which involves dividing the code into blocks, includes:

[0041] Enter the code file;

[0042] Token budget calculation: Based on the AI ​​model quota, calculate the available tokens, estimate the required token amount, dynamically adjust the analysis depth, and achieve cost control goals.

[0043] File filtering preprocessing excludes test files and resource files, filters binary and non-code files, identifies file change types, and reduces the scope of unnecessary analysis;

[0044] Choose a partitioning strategy, analyze code complexity, assess dependency density, determine the scope of impact of changes, and intelligently decide on the partitioning method;

[0045] For files that do not consider code dependencies, simple file splitting, or simple code changes, traditional chunking strategies are used to obtain traditional chunks based on fixed size or syntax structure.

[0046] For files that need to dynamically calculate block size based on dependencies, maintain context integrity, prioritize the inclusion of relevant code entities, and perform complex code change analysis, graph-based intelligent block segmentation is adopted, which obtains graph intelligent block segmentation based on the Neo4j graph database relational model.

[0047] Output the block results.

[0048] Specifically, the graph-based intelligent segmentation includes the following steps:

[0049] Multi-dimensional relationship graph construction: Based on the Neo4j graph database, multi-level relationships at the file, class, method, and field levels are constructed, and dependencies including call chains, inheritance relationships, and reference relationships are extracted to build a complete code relationship graph;

[0050] The intelligent graph clustering algorithm is applied to initially group code entities according to the dependency strength between code entities, identify code modules with high cohesion and low coupling, and generate a preliminary code segmentation scheme.

[0051] Clustering optimization, based on code complexity, assesses the scope of impact of changes and business relevance, adjusts and merges small blocks, and maintains contextual integrity;

[0052] The available token budget is calculated based on the AI ​​model quota, and the block size is dynamically adjusted to adapt to token restrictions, prioritizing the preservation of critical code paths and high-risk areas.

[0053] Output code chunks suitable for AI analysis. Each chunk contains a complete context and relevant dependencies, and the chunk size meets the Token budget requirements.

[0054] The beneficial effects of this invention are as follows: It supports both incremental analysis and full scan modes, with incremental analysis response time reduced to the second level and full scan supporting efficient processing of over 100,000 lines of code, meeting the analysis needs of different scenarios; it automatically discovers complete context dependencies through a graph database, improving AI analysis accuracy by over 30% and effectively reducing false positives and false negatives; based on a real-time triggering mechanism using Webhook events, analysis starts immediately after code submission, with an average response time of less than 10 seconds; the intelligent block-based strategy reduces analysis time for large projects by 60%, and the asynchronous processing mechanism supports concurrent analysis, improving overall processing efficiency by more than 3 times; the cost of AI model calls is reduced by 50%, achieving precise cost control through intelligent context filtering and dynamic calling strategies; the incremental graph update mechanism improves graph synchronization efficiency by 80%, ensuring the real-time nature and accuracy of code relationship data; it supports multiple programming languages ​​and project sizes, seamlessly integrates with GitLab, and supports enterprise-level deployment and OAuth2 authentication. Attached Figure Description

[0055] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.

[0056] Figure 1 This is an architecture diagram of an intelligent code analysis system based on a graph database, as described in an embodiment of the present invention.

[0057] Figure 2 This is a schematic diagram of a graph database relational model in an embodiment of the present invention;

[0058] Figure 3 This is a flowchart of code graph construction in an embodiment of the present invention;

[0059] Figure 4 This is a flowchart illustrating the overall code block division process in an embodiment of the present invention.

[0060] Figure 5 This is a flowchart of the graph-based intelligent block segmentation process in an embodiment of the present invention;

[0061] Figure 6 This is a flowchart illustrating the AI ​​model invocation process in an embodiment of the present invention.

[0062] Figure 7 This is a schematic diagram illustrating AI analysis enhancement in an embodiment of the present invention.

[0063] Figure 8 This is a schematic diagram of the intelligent code analysis process based on a graph database in an embodiment of the present invention. Detailed Implementation

[0064] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0065] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0066] The following is in conjunction with the appendix Figures 1-8 The following describes some embodiments of the present invention in detail. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0067] This invention proposes an intelligent code analysis system based on graph databases. In a preferred embodiment, the system includes the following modules:

[0068] The dual-mode analysis control module enables unified scheduling and management of incremental analysis and full scan. Incremental analysis mode automatically triggers code change analysis by listening to GitLab Webhook events; full scan mode provides manual triggering and scheduled operation through a front-end functional page, supporting both security scanning and comprehensive analysis. It employs Spring Boot's asynchronous processing mechanism to achieve concurrent execution and resource isolation for both modes.

[0069] Code parsing module: Employs JavaParser to parse Java code, extracting code entities such as classes, methods, and fields, along with their relationships, constructing an abstract syntax tree, and converting it into graph database nodes. It supports both incremental and batch parsing modes, with optimized parsing strategies for different analysis scenarios.

[0070] The graph database management module, based on Neo4j 5.15+, constructs a multi-dimensional code relationship graph, enabling CRUD operations on nodes and dynamic maintenance of relationships. It builds multi-level node relationships (files, classes, methods, fields, packages, etc.) through a multi-dimensional graph service, supporting complex relationship queries using the Cypher query language. It implements an incremental graph update mechanism based on Git events to ensure the real-time nature of graph data.

[0071] Intelligent Analysis Engine: Integrates multiple AI models (Qwen3-Coder, Kimi-K2, Claude, etc.) to achieve functions such as code quality inspection, security vulnerability scanning, and design pattern recognition through AI model services. It supports dynamic invocation strategies based on analysis patterns; incremental analysis uses lightweight models, while full scanning uses deep analysis models. It also implements intelligent context filtering and cost control mechanisms.

[0072] GitLab Integration Module: Receives and parses Git events through GitLab services and Webhook event analysis services, enabling automatic triggering of incremental code analysis and graph updates. Supports multiple triggering methods such as Push events and Merge Request events, and provides OAuth2 authentication and permission management functions.

[0073] Visualization module: Provides a web interface for displaying analysis results, supporting graph visualization, report generation, and real-time monitoring. It offers differentiated result displays for different analysis modes; incremental analysis focuses on showcasing the impact of changes, while full scans provide comprehensive quality reports.

[0074] In this embodiment, the visualization module includes:

[0075] Full scan management: Performs a comprehensive code quality and security scan on the project, supports manual triggering and batch scanning, and provides detailed scan reports and history records;

[0076] Scheduled Scan Configuration: Configure automatic scheduled scans for the project, supporting weekly full scans and daily security scans, with flexible settings for scan priority and project scope;

[0077] Code graph visualization: Visualizes code structure and dependencies to help understand project architecture and identify potential design problems and optimization opportunities;

[0078] Project Management: Manage scanned projects, view project health status and quality trends, configure project background files, and monitor changes in project quality;

[0079] System monitoring: Monitor system operation status, view scan task queue, analyze system performance indicators, and ensure stable service operation;

[0080] Settings Center: Configure system parameters and AI model parameters, manage user permissions, set general prompts such as company guidelines and risk level assessment standards, and customize scanning rules and quality standards.

[0081] In one embodiment, the system architecture is as follows: Figure 1 As shown, it includes:

[0082] Web interface layer: Configuration visualization submodule, including full scan management, scheduled scan configuration, code graph visualization, project management, system monitoring and settings center;

[0083] GitLab login integration: The process is as follows: GitLab OAuth2, user authentication, permission verification, and session management.

[0084] Webhook event flow: The flow is as follows: Push / MR event, incremental code analysis, change impact assessment, automatic issue feedback / MR comment;

[0085] Full scan process: The process consists of manual scan triggering, complete project analysis, code quality assessment, and security vulnerability detection.

[0086] Shared core components include a basic service layer and a data service layer. The basic service layer includes Git cloning service, code parsing engine, AI analysis engine, intelligent sharding processing, graph enhancement context and statistical analysis. The data service layer includes graph building service (graph update), Neo4j graph library (relationship storage), full scan record, AI call record, code problem record and analysis result service (logic processing).

[0087] This invention also proposes a corresponding intelligent code analysis method based on graph databases, such as... Figure 8 As shown, it includes the following steps:

[0088] Step S1: Receive code analysis request, parse the parameters of the request, and determine whether the analysis mode is incremental analysis mode or full scan mode;

[0089] Step S2: Incremental analysis mode listens for and parses GitLab Webhook events through the GitLab integration module to obtain code change information. Full scan mode pulls the full code of the project branch through GitLab, parses the code, and updates or builds a multi-dimensional relationship graph based on the graph database management module.

[0090] Step S3: Intelligent selection of block segmentation strategy. Based on the constructed multi-dimensional relationship graph of the project, the project code is intelligently segmented into multiple code blocks with related dependencies through graph dependency relationships and weight algorithms.

[0091] Step S4: Intelligent context enhancement and filtering, loading the complete context or changing code based on graph dependencies and weight algorithms, analysis configuration and AI model quotas;

[0092] Step S5: Set up a rate limiting mechanism and perform a rate check based on the rate limit of the AI ​​service token; if the check fails, call the sliding window algorithm to limit the rate and calculate the waiting time until the rate check passes before calling the model.

[0093] Step S6: Dynamically select incremental analysis mode and full scan mode, and call the lightweight model and deep analysis model respectively to judge the results;

[0094] Step S7: If the result judgment is successful, the result is parsed into JSON. If the parsing is successful, the result is cached. If the result judgment or parsing fails, an exception or rate limiting prompt is returned. Finally, the analysis result is returned.

[0095] In this embodiment, step S2 further includes code parsing and code graph construction, wherein code parsing and code graph construction are as follows: Figure 3 As shown, it specifically includes:

[0096] The code is parsed and analyzed using JavaParser and Abstract Syntax Tree (AST).

[0097] Based on the call relationship, extract the relationship and construct a multi-dimensional relationship;

[0098] Based on the Neo4j graph database, it stores graphs and drives the graph database.

[0099] Index optimization enables high-performance graph queries.

[0100] In this embodiment, step S3 divides the code into blocks, as shown in the main flow. Figure 4 As shown, it specifically includes:

[0101] Enter the code file;

[0102] Token budget calculation: Based on the AI ​​model quota, calculate the available tokens, estimate the required token amount, dynamically adjust the analysis depth, and achieve cost control goals.

[0103] File filtering preprocessing excludes test files and resource files, filters binary and non-code files, identifies file change types, and reduces the scope of unnecessary analysis;

[0104] Choose a partitioning strategy, analyze code complexity, assess dependency density, determine the scope of impact of changes, and intelligently decide on the partitioning method;

[0105] For files that do not consider code dependencies, simple file splitting, or simple code changes, traditional chunking strategies are used to obtain traditional chunks based on fixed size or syntax structure.

[0106] For files that require dynamic calculation of chunk size based on dependencies, maintenance of contextual integrity, priority inclusion of related code entities, and analysis of complex code changes, graph-based intelligent chunking is adopted. Graph intelligent chunking is obtained based on the Neo4j graph database relational model, as shown in the graph database relational model. Figure 2 As shown;

[0107] Output the block results.

[0108] In this embodiment, intelligent segmentation based on the graph is as follows: Figure 5 As shown, the specific steps include:

[0109] Multi-dimensional relationship graph construction (graph database-driven context discovery) is based on the Neo4j graph database to build multi-level relationships at the file, class, method, and field levels. It extracts dependencies including call chains, inheritance relationships, and reference relationships to build a complete code relationship graph, providing a data foundation for intelligent block segmentation.

[0110] The intelligent graph clustering algorithm (intelligent block segmentation based on dependency relationship) is applied to initially group code entities according to the dependency strength between them, identify code modules with high cohesion and low coupling, and generate a preliminary code block segmentation scheme.

[0111] Clustering optimization (context integrity assurance): Based on code complexity, assess the scope of impact of changes and business relevance, adjust and merge small blocks, and maintain context integrity;

[0112] Token-restricted applications (AI call cost optimization): Calculate the available token budget based on the AI ​​model quota, dynamically adjust the block size to adapt to token restrictions, prioritize the retention of critical code paths and high-risk areas, and achieve a balance between cost control and analysis quality.

[0113] Output code chunks suitable for AI analysis. Each chunk contains a complete context and relevant dependencies. The chunk size meets the Token budget requirements, providing high-quality input data for AI models.

[0114] In this embodiment, the AI ​​analysis enhancement process is as follows: Figure 7 As shown, it includes, in sequence:

[0115] Graph database-driven graph query;

[0116] Intelligent context discovery and filtering, constructing context;

[0117] Based on preset content such as project type, background, and company regulations, prompt words are dynamically generated in combination with the current context.

[0118] Select a dynamic model for AI analysis, optimize the results, and evaluate the credibility of the results.

[0119] The technical effects of the various technical principles adopted in each part of this solution are as follows:

[0120] Dual-mode intelligent code analysis architecture: Implements incremental analysis mode based on Webhook event triggering, supports real-time response to events such as GitLab Push and Merge Request, provides full scan mode with manual triggering and scheduled scheduling, supports project initialization and periodic quality checks, adopts asynchronous processing mechanism to achieve seamless switching and concurrent execution of the two modes, and supports flexible configuration of two scan types: security scan and comprehensive analysis.

[0121] A graph database-driven intelligent context discovery mechanism: Utilizing the Neo4j graph database to model multi-dimensional relationships between code entities, it automatically discovers direct and indirect dependencies of modified files through graph traversal algorithms. This enables precise queries of various dependencies such as call chains, inheritance relationships, and field references. It also supports intelligent context expansion, automatically loading the complete content of relevant code entities.

[0122] Dependency-based intelligent code chunking strategy: dynamically calculates chunk size based on code complexity and dependencies, realizes aggregated chunking of related code, maintains context integrity, supports configurable chunking parameters and intelligent threshold adjustment, optimizes batch processing performance for full scan, and supports efficient analysis of large-scale projects;

[0123] Multi-dimensional code relationship graph construction: Construct multi-level relationship graphs at the file level, class level, method level, and field level, realize business relevance calculation and PageRank algorithm optimization, support design pattern recognition and complexity measurement, and provide graph visualization and relationship query interface;

[0124] AI model call cost optimization mechanism: Implements token-based rate limiting and cost control, employs intelligent context filtering and source code tagging filtering to reduce unnecessary AI calls, supports dynamic switching and load balancing of multiple AI models, and dynamically adjusts AI call strategies based on analysis patterns. AI calls, such as... Figure 6 As shown;

[0125] Real-time map maintenance and synchronization strategy: Implement incremental map updates based on Git events (Push, Merge Request), support map synchronization for operations such as file deletion, renaming, and moving, adopt an asynchronous processing mechanism to improve update efficiency and system responsiveness, and implement map data consistency checks and automatic repair mechanisms.

[0126] This solution proposes a code analysis architecture that flexibly switches between incremental analysis and full scan modes, automatically selecting the optimal analysis strategy based on different scenario requirements to achieve a balance between efficiency and quality. Real-time incremental analysis based on Webhooks employs a Git event-based real-time code analysis triggering mechanism, providing immediate responses to code commits with an average response time of less than 10 seconds. Intelligent code context discovery driven by a graph database applies graph database technology to code dependency modeling and context discovery, automatically identifying the complete dependency context of changed code, improving analysis accuracy by 30%. Intelligent code chunking based on dependencies uses a dynamic chunking strategy based on code complexity and dependencies, maintaining context integrity while improving analysis efficiency by 60%. Multi-dimensional... This solution features code relationship graph construction, employing multi-level and multi-dimensional code relationship modeling and graph construction methods to support complex code analysis and impact assessment. It also optimizes AI model invocation costs through intelligent context filtering and dynamic invocation strategies based on analysis patterns, reducing costs by 50% while maintaining analysis quality. Real-time graph maintenance and synchronization, based on Git events, improves graph synchronization efficiency by 80%, ensuring data timeliness and accuracy. Furthermore, this solution enables enterprise-level code quality management, providing intelligent code review for large software projects, integrating CI / CD pipelines, achieving automated quality inspection, AI-based intelligent security scanning and risk assessment, and identifying and quantifying technical debt through graph analysis.

[0127] For the foregoing embodiments, in order to simplify the description, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to this application.

[0128] The above embodiments describe the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Modifications and variations made by those skilled in the art without departing from the spirit and scope of the invention should be within the protection scope of the appended claims.

Claims

1. An intelligent code analysis system based on graph databases, characterized in that, Includes the following modules: Dual-mode analysis control module: Unified scheduling and management of incremental analysis mode and full scan mode, using Spring Boot asynchronous processing mechanism to achieve concurrent execution and resource isolation of the two modes; Code parsing module: Parses Java code, extracts code entities and their relationships, constructs an abstract syntax tree and converts it into graph database nodes; supports both incremental and batch parsing modes, and optimizes parsing strategies for different analysis scenarios; The graph database management module constructs multi-dimensional code relationship graphs at the file, class, method, and field levels, enabling the creation, deletion, modification, and querying of nodes and dynamic maintenance of relationships. It identifies call chains, inheritance relationships, and field references through graph relationships and algorithms, constructs multi-level dependencies between code entities, supports complex relationship queries using the Cypher query language, and implements an incremental graph update mechanism based on Git events. Intelligent Analysis Engine Module: Intelligent code file segmentation, specifically graph-based intelligent segmentation includes: Multi-dimensional relationship graph construction: Based on the Neo4j graph database, multi-level relationships at the file, class, method, and field levels are constructed, and dependencies including call chains, inheritance relationships, and reference relationships are extracted to build a complete code relationship graph; The intelligent graph clustering algorithm is applied to initially group code entities according to the dependency strength between code entities, identify code modules with high cohesion and low coupling, and generate a preliminary code segmentation scheme. Clustering optimization, based on code complexity, assesses the scope of impact of changes and business relevance, adjusts and merges small blocks, and maintains contextual integrity; The available token budget is calculated based on the AI ​​model quota, and the block size is dynamically adjusted to adapt to token restrictions, prioritizing the preservation of critical code paths and high-risk areas. Output code chunks suitable for AI analysis. Each chunk contains a complete context and relevant dependencies. The chunk size meets the Token budget requirements. The segmented results support intelligent context discovery based on graph relationships and weighting algorithms, automatically expand the direct and indirect dependencies of the code, select lightweight or deep AI models according to the analysis mode, and perform intelligent context filtering and cost control based on token budget; integrate multiple AI models, and realize code quality detection, security vulnerability scanning and design pattern recognition functions through AI model services; GitLab Integration Module: Receives and parses Git events through GitLab services and Webhook event analysis services, enabling automatic triggering of incremental code analysis and graph updates; Visualization module: Provides a web interface to display analysis results, supporting graph visualization, report generation, and real-time monitoring.

2. The intelligent code analysis system based on graph database as described in claim 1, characterized in that, The incremental analysis mode automatically triggers code change analysis by listening to GitLab Webhook events; the full scan mode provides manual triggering and scheduled functions through API interface or management interface, supporting both security scanning and comprehensive analysis; the incremental analysis mode and the full scan mode are executed concurrently through an asynchronous task queue to avoid resource conflicts.

3. The intelligent code analysis system based on graph database as described in claim 1, characterized in that, The intelligent analysis engine module supports dynamic invocation strategies based on analysis patterns, employing a lightweight model for incremental analysis and a deep analysis model for full scans.

4. The intelligent code analysis system based on graph database as described in claim 1, characterized in that, The visualization module includes the following sub-modules: Full scan management submodule: Performs a comprehensive code quality and security scan on the project, supports manual triggering and batch scanning, and provides detailed scan reports and history records; Scheduled Scan Configuration Submodule: Configures automatic scheduled scans for the project, supporting weekly full scans and daily security scans, and sets scan priorities and project scope; Code graph visualization submodule: Displays code structure and dependencies in a graphical way, supports drag-and-drop, viewing and clicking to highlight changes to code, its affected paths and dependent modules; Project Management Submodule: Manage scanned projects, view project health status and quality trends, configure project background files, and monitor changes in project quality; System monitoring submodule: Monitors system running status, views the scan task queue, and analyzes system performance metrics; Settings Center submodule: Configure system parameters and AI model parameters, manage user permissions, set general prompt words, and customize scanning rules and quality standards.

5. A graph database-based intelligent code analysis method, implemented based on the graph database-based intelligent code analysis system according to any one of claims 1 to 4, characterized in that, Includes the following steps: Step S1: Receive code analysis request, parse the parameters of the request, and determine whether the analysis mode is incremental analysis mode or full scan mode; Step S2: Incremental analysis mode listens for and parses GitLab Webhook events through the GitLab integration module to obtain code change information; full scan mode pulls the full code of the project branch through GitLab, parses the code, and updates or builds a multi-dimensional relationship graph based on the graph database management module. Step S3: Intelligent selection of block segmentation strategy. Based on the constructed multi-dimensional relationship graph of the project, the project code is intelligently segmented into multiple code blocks with related dependencies through graph dependency relationships and weight algorithms. Step S4: Intelligent context enhancement and filtering, loading the complete context or changing code based on graph dependencies and weight algorithms, analysis configuration and AI model quotas; Step S5: Set up a rate limiting mechanism and perform a rate check based on the rate limit of the AI ​​service token; if the check fails, call the sliding window algorithm to limit the rate and calculate the waiting time until the rate check passes before calling the model. Step S6: Dynamically select incremental analysis mode and full scan mode, and call the lightweight model and deep analysis model respectively to judge the results; Step S7: If the result judgment is successful, then parse the result into JSON. If the parsing is successful, then cache the result. If the result judgment or result parsing fails, an exception or rate limiting prompt will be returned; finally, the analysis result will be returned.

6. The intelligent code analysis method based on graph database as described in claim 5, characterized in that, Step S2 further includes code parsing and code graph construction, which specifically includes: The code is parsed and analyzed using the Abstract Syntax Tree (AST). Based on the call relationship, extract the relationship and construct a multi-dimensional relationship; Stores graphs and drives graph databases; Index optimization enables high-performance graph queries.

7. The intelligent code analysis method based on graph database as described in claim 5, characterized in that, Step S3, which involves dividing the code into blocks, specifically includes: Enter the code file; Token budget calculation: Based on the AI ​​model quota, calculate the available tokens, estimate the required token amount, dynamically adjust the analysis depth, and achieve cost control goals. File filtering preprocessing excludes test files and resource files, filters binary and non-code files, identifies file change types, and reduces the scope of unnecessary analysis; Choose a partitioning strategy, analyze code complexity, assess dependency density, determine the scope of impact of changes, and intelligently decide on the partitioning method; For files that do not consider code dependencies, simple file splitting, or simple code changes, traditional chunking strategies are used to obtain traditional chunks based on fixed size or syntax structure. For files that need to dynamically calculate block size based on dependencies, maintain context integrity, prioritize the inclusion of relevant code entities, and perform complex code change analysis, graph-based intelligent block segmentation is adopted, which obtains graph intelligent block segmentation based on the Neo4j graph database relational model. Output the block results.

Citation Information

Patent Citations

  • Vulnerability code graph construction and code vulnerability detection method based on knowledge graph

    CN114692155A

  • Intelligent programming auxiliary method and system based on multi-mode AI language model

    CN120315685A