refactor: move scattered business logic into domain
Some checks failed
CI / Check / Test (push) Failing after 44s
Architecture Docs / Generate diagrams (push) Successful in 3m21s

- CodeGraph::merge_project_edges() replaces presentation-layer function
- Language::is_test_file() centralises test file detection (was in walkdir)
- AnalysisConfig::is_standard_excluded() centralises default dir exclusions (was in walkdir)
- normalize_cargo_package() / normalize_python_package() in domain replace duplicated normalisers in each adapter
- walkdir, cargo-workspace, python-project updated to call domain methods
This commit is contained in:
2026-06-17 10:58:42 +02:00
parent 428faa957c
commit e26151b4a1
10 changed files with 262 additions and 87 deletions

View File

@@ -9,7 +9,7 @@ use archlens_ascii::AsciiRenderer;
use archlens_cargo_workspace::CargoWorkspaceAnalyzer;
use archlens_d2::D2Renderer;
use archlens_domain::{
BoundaryRule, CodeGraph, DiagramLevel, ModuleName, check_boundary_rules,
BoundaryRule, CodeGraph, DiagramLevel, check_boundary_rules,
ports::{ConfigLoader, OutputWriter, ProjectAnalyzer},
};
use archlens_file_writer::FileOutputWriter;
@@ -154,7 +154,7 @@ fn build_graph(args: &Cli, level: DiagramLevel) -> Result<CodeGraph> {
PythonProjectAnalyzer::new().analyze(&args.path).ok()
};
if let Some(pg) = project_graph {
merge_project_deps_as_module_edges(&mut graph, &pg);
graph.merge_project_edges(&pg);
}
}
@@ -265,49 +265,6 @@ fn write_single(
Ok(())
}
fn merge_project_deps_as_module_edges(
graph: &mut archlens_domain::CodeGraph,
project_graph: &archlens_domain::CodeGraph,
) {
use std::collections::HashMap;
let mut crate_to_module: HashMap<String, String> = HashMap::new();
for element in project_graph.elements() {
let module = if let Some(m) = element.module() {
m.as_str().to_string()
} else {
let path = element.file_path().as_str();
let dir = path.split('/').rev().nth(1).unwrap_or(element.name());
ModuleName::capitalize(dir)
};
crate_to_module.insert(element.name().to_string(), module);
}
let graph_modules: std::collections::HashSet<String> = graph
.modules()
.iter()
.map(|m| m.as_str().to_string())
.collect();
for rel in project_graph.relationships() {
let src_module = crate_to_module.get(rel.source());
let tgt_module = crate_to_module.get(rel.target());
if let (Some(src_cap), Some(tgt_cap)) = (src_module, tgt_module)
&& src_cap != tgt_cap
&& graph_modules.contains(src_cap)
&& graph_modules.contains(tgt_cap)
&& let Ok(edge) = archlens_domain::Relationship::new(
src_cap,
tgt_cap,
archlens_domain::RelationshipKind::Composition,
)
{
graph.add_relationship(edge);
}
}
}
fn run_diff(args: &Cli, existing_path: &std::path::Path) -> Result<()> {
init_tracing(args.verbose);