private ArchitectureModel aggregateResults()

in doc-architect/doc-architect-cli/src/main/java/com/docarchitect/cli/ScanCommand.java [367:421]


    private ArchitectureModel aggregateResults(Map<String, ScanResult> scanResults, ScanContext context) {
        log.debug("Aggregating scan results into ArchitectureModel");

        List<Component> allComponents = new ArrayList<>();
        List<Dependency> allDependencies = new ArrayList<>();
        List<ApiEndpoint> allApiEndpoints = new ArrayList<>();
        List<MessageFlow> allMessageFlows = new ArrayList<>();
        List<DataEntity> allDataEntities = new ArrayList<>();
        List<Relationship> allRelationships = new ArrayList<>();

        for (ScanResult result : scanResults.values()) {
            if (result.success()) {
                allComponents.addAll(result.components());
                allDependencies.addAll(result.dependencies());
                allApiEndpoints.addAll(result.apiEndpoints());
                allMessageFlows.addAll(result.messageFlows());
                allDataEntities.addAll(result.dataEntities());
                allRelationships.addAll(result.relationships());
            }
        }

        // Deduplicate components, dependencies, etc. by unique keys
        allComponents = deduplicateByKey(allComponents, Component::id);
        allDependencies = deduplicateByKey(allDependencies, d -> d.groupId() + ":" + d.artifactId() + ":" + d.version());
        allApiEndpoints = deduplicateByKey(allApiEndpoints, e -> e.componentId() + ":" + e.method() + ":" + e.path());
        allMessageFlows = deduplicateByKey(allMessageFlows, m -> m.topic() + ":" + m.publisherComponentId() + ":" + m.subscriberComponentId());
        allDataEntities = deduplicateByKey(allDataEntities, e -> e.componentId() + ":" + e.name());
        allRelationships = deduplicateByKey(allRelationships, r -> r.sourceId() + ":" + r.targetId() + ":" + r.type());

        // Calculate quality metrics
        com.docarchitect.core.model.ScanQualityReport qualityReport =
            com.docarchitect.core.util.QualityMetricsCalculator.calculateQualityReport(scanResults, context);

        // Collect per-scanner statistics
        Map<String, com.docarchitect.core.scanner.ScanStatistics> scannerStats = scanResults.entrySet().stream()
            .filter(e -> e.getValue().statistics() != null)
            .collect(java.util.stream.Collectors.toMap(
                Map.Entry::getKey,
                e -> e.getValue().statistics()
            ));

        return new ArchitectureModel(
            projectPath.getFileName() != null ? projectPath.getFileName().toString() : "project",
            "1.0.0",
            List.of(projectPath.toAbsolutePath().toString()),
            allComponents,
            allDependencies,
            allRelationships,
            allApiEndpoints,
            allMessageFlows,
            allDataEntities,
            qualityReport,
            scannerStats
        );
    }