init: archlens — architecture diagram generator
Some checks failed
CI / Check / Test (push) Failing after 1m24s

Hex arch + DDD, tree-sitter parsing, Mermaid/ASCII output.
Supports Rust + Python. 92 tests. CI, diff, --check for staleness detection.
This commit is contained in:
2026-06-16 16:13:04 +02:00
commit 35f27d00b0
106 changed files with 6744 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
mod walkdir_discovery;
pub use walkdir_discovery::WalkdirDiscovery;

View File

@@ -0,0 +1,100 @@
use std::path::Path;
use ignore::WalkBuilder;
use archlens_domain::{
AnalysisConfig, DomainError, FilePath, Language, SourceFile, ports::FileDiscovery,
};
const DEFAULT_EXCLUDES: &[&str] = &[
".venv",
"venv",
"node_modules",
"__pycache__",
".git",
"target",
"bin",
"obj",
"dist",
".tox",
".eggs",
];
pub struct WalkdirDiscovery;
impl Default for WalkdirDiscovery {
fn default() -> Self {
Self::new()
}
}
impl WalkdirDiscovery {
pub fn new() -> Self {
Self
}
fn detect_language(path: &Path) -> Option<Language> {
match path.extension()?.to_str()? {
"rs" => Some(Language::Rust),
"py" => Some(Language::Python),
"cs" => Some(Language::CSharp),
_ => None,
}
}
fn is_excluded(path: &Path, root: &Path, excludes: &[String]) -> bool {
let relative = path.strip_prefix(root).unwrap_or(path);
let relative_str = relative.to_string_lossy();
for component in relative.components() {
let name = component.as_os_str().to_string_lossy();
if DEFAULT_EXCLUDES.iter().any(|e| name == *e) {
return true;
}
}
excludes
.iter()
.any(|exclude| relative_str.contains(exclude.trim_end_matches('/')))
}
}
impl FileDiscovery for WalkdirDiscovery {
fn discover(
&self,
root: &Path,
config: &AnalysisConfig,
) -> Result<Vec<SourceFile>, DomainError> {
let mut files = Vec::new();
let walker = WalkBuilder::new(root).hidden(true).git_ignore(true).build();
for entry in walker.filter_map(|e| e.ok()) {
let path = entry.path();
if !path.is_file() {
continue;
}
if Self::is_excluded(path, root, config.excludes()) {
continue;
}
if let Some(scope) = config.scope() {
let relative = path.strip_prefix(root).unwrap_or(path);
if !relative.starts_with(scope) {
continue;
}
}
if let Some(language) = Self::detect_language(path) {
let absolute = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
let file_path = FilePath::new(&absolute.to_string_lossy())
.map_err(|e| DomainError::IoError(e.to_string()))?;
files.push(SourceFile::new(file_path, language));
}
}
Ok(files)
}
}