UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

98 lines (88 loc) 4.33 kB
/** * @file Comprehensive project integration analysis orchestrator for API consistency verification * @description Single responsibility: Coordinate multi-layer integration analysis across frontend and backend codebases * * This orchestrator performs comprehensive project-wide integration analysis by coordinating * frontend API call extraction, backend endpoint discovery, and cross-layer consistency * verification. It provides systematic detection of integration issues that could cause * runtime failures while offering quantitative assessment and actionable recommendations. * * Design rationale: * - Orchestrated analysis ensures comprehensive coverage of all integration touchpoints * - File type classification enables targeted analysis of frontend and backend components * - Cross-layer matching identifies inconsistencies between API definitions and usage * - Integration scoring provides quantitative assessment for quality tracking * - Strategic recommendations prioritize fixes based on impact and implementation effort * * Analysis coordination strategy: * - Project file discovery with intelligent frontend/backend classification * - Parallel endpoint extraction and API call analysis for performance optimization * - Comprehensive integration issue detection covering all mismatch categories * - Quantitative scoring that reflects integration quality and consistency * - Actionable recommendation generation for systematic integration improvements */ const fs = require('fs'); const path = require('path'); const { extractBackendEndpoints } = require('../backendEndpointExtractor'); const { extractFrontendCalls } = require('../frontendApiCallExtractor'); const getAllProjectFiles = require('./fileUtils/getAllProjectFiles'); const isBackendFile = require('./fileUtils/isBackendFile'); const isFrontendFile = require('./fileUtils/isFrontendFile'); const analyzeIntegrationIssues = require('./integration/analyzeIntegrationIssues'); const calculateIntegrationScore = require('./integration/calculateIntegrationScore'); const generateIntegrationRecommendations = require('./integration/generateIntegrationRecommendations'); /** * Analyze frontend-backend integration across a project * @param {string} projectPath - Project directory path * @param {Object} options - Analysis options * @returns {Object} Integration analysis results */ async function analyzeProjectIntegration(projectPath, options = {}) { try { const files = await getAllProjectFiles(projectPath); const backendEndpoints = []; const frontendCalls = []; // Optimize file processing with early returns and reduced I/O for (const file of files) { try { const isBackend = isBackendFile(file); const isFrontend = isFrontendFile(file); // Skip if neither frontend nor backend if (!isBackend && !isFrontend) continue; const content = await fs.promises.readFile(file, 'utf8'); if (isBackend) { // extractBackendEndpoints expects array of file paths const endpoints = await extractBackendEndpoints([file]); backendEndpoints.push(...endpoints); } if (isFrontend) { // extractFrontendCalls expects array of file paths and is async const calls = await extractFrontendCalls([file]); frontendCalls.push(...calls); } } catch (error) { // Skip files that can't be read } } const issues = analyzeIntegrationIssues(frontendCalls, backendEndpoints); return { summary: { totalFiles: files.length, integrationIssues: issues.length, missingEndpoints: issues.filter(i => i.type === 'missing_endpoint').length, unusedEndpoints: issues.filter(i => i.type === 'unused_endpoint').length, integrationScore: calculateIntegrationScore(frontendCalls, backendEndpoints, issues) }, frontendCalls, backendEndpoints, endpoints: backendEndpoints, calls: frontendCalls, issues, recommendations: generateIntegrationRecommendations(issues) }; } catch (error) { console.error(`Frontend-Backend integration analysis failed: ${error.message}`); throw error; } } module.exports = analyzeProjectIntegration;