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,13 @@
[package]
name = "archlens-file-writer"
version = "0.1.0"
edition = "2024"
publish = false
[dependencies]
archlens-domain.workspace = true
thiserror.workspace = true
tracing.workspace = true
[dev-dependencies]
tempfile.workspace = true

View File

@@ -0,0 +1,52 @@
use std::fs;
use std::path::PathBuf;
use archlens_domain::{DomainError, RenderOutput, ports::OutputWriter};
pub struct FileOutputWriter {
output_path: OutputPath,
}
enum OutputPath {
Directory(PathBuf),
File(PathBuf),
}
impl FileOutputWriter {
pub fn new(output_dir: PathBuf) -> Self {
Self {
output_path: OutputPath::Directory(output_dir),
}
}
pub fn single_file(path: PathBuf) -> Self {
Self {
output_path: OutputPath::File(path),
}
}
}
impl OutputWriter for FileOutputWriter {
fn write(&self, output: &RenderOutput) -> Result<(), DomainError> {
match &self.output_path {
OutputPath::File(path) => {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).map_err(|e| DomainError::IoError(e.to_string()))?;
}
let content = output.files().first().map(|f| f.content()).unwrap_or("");
fs::write(path, content).map_err(|e| DomainError::IoError(e.to_string()))?;
}
OutputPath::Directory(dir) => {
fs::create_dir_all(dir).map_err(|e| DomainError::IoError(e.to_string()))?;
for file in output.files() {
let path = dir.join(file.name());
fs::write(&path, file.content())
.map_err(|e| DomainError::IoError(e.to_string()))?;
}
}
}
Ok(())
}
}

View File

@@ -0,0 +1,3 @@
mod file_output_writer;
pub use file_output_writer::FileOutputWriter;

View File

@@ -0,0 +1,35 @@
use std::fs;
use archlens_domain::{RenderOutput, RenderedFile, ports::OutputWriter};
use archlens_file_writer::FileOutputWriter;
#[test]
fn writes_single_file_to_directory() {
let dir = tempfile::tempdir().unwrap();
let writer = FileOutputWriter::new(dir.path().to_path_buf());
let file = RenderedFile::new("arch.mmd", "classDiagram").unwrap();
let output = RenderOutput::single(file);
writer.write(&output).unwrap();
let content = fs::read_to_string(dir.path().join("arch.mmd")).unwrap();
assert_eq!(content, "classDiagram");
}
#[test]
fn writes_multiple_files_to_directory() {
let dir = tempfile::tempdir().unwrap();
let writer = FileOutputWriter::new(dir.path().to_path_buf());
let files = vec![
RenderedFile::new("overview.mmd", "graph TD").unwrap(),
RenderedFile::new("orders.mmd", "classDiagram").unwrap(),
];
let output = RenderOutput::new(files);
writer.write(&output).unwrap();
assert!(dir.path().join("overview.mmd").exists());
assert!(dir.path().join("orders.mmd").exists());
}