Skip to main content

archidoc_types/
module_doc.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4use crate::annotation::{HealthStatus, PatternStatus};
5
6/// C4 architecture level for a module.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum C4Level {
10    Container,
11    Component,
12    Unknown,
13}
14
15impl fmt::Display for C4Level {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            Self::Container => write!(f, "container"),
19            Self::Component => write!(f, "component"),
20            Self::Unknown => write!(f, "unknown"),
21        }
22    }
23}
24
25impl C4Level {
26    pub fn parse(s: &str) -> Self {
27        match s.trim().to_lowercase().as_str() {
28            "container" => Self::Container,
29            "component" => Self::Component,
30            _ => Self::Unknown,
31        }
32    }
33}
34
35/// A runtime dependency between modules.
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub struct Relationship {
38    pub target: String,
39    pub label: String,
40    pub protocol: String,
41}
42
43/// A file entry from the module's file table.
44#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
45pub struct FileEntry {
46    pub name: String,
47    pub pattern: String,
48    pub pattern_status: PatternStatus,
49    pub purpose: String,
50    pub health: HealthStatus,
51}
52
53/// A parsed module documentation unit.
54///
55/// This is the core data structure — the JSON IR contract between
56/// language adapters and the core generator.
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58pub struct ModuleDoc {
59    pub module_path: String,
60    pub content: String,
61    pub source_file: String,
62    pub c4_level: C4Level,
63    pub pattern: String,
64    pub pattern_status: PatternStatus,
65    pub description: String,
66    pub parent_container: Option<String>,
67    pub relationships: Vec<Relationship>,
68    pub files: Vec<FileEntry>,
69}