Skip to main content

gitcortex_core/
schema.rs

1use serde::{Deserialize, Serialize};
2
3/// Every named, referenceable syntactic entity becomes a node of one of these kinds.
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum NodeKind {
7    Folder,
8    File,
9    Module,
10    Struct,
11    Enum,
12    Trait,
13    TypeAlias,
14    Function,
15    Method,
16    Constant,
17    Macro,
18}
19
20impl std::fmt::Display for NodeKind {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        let s = match self {
23            NodeKind::Folder => "folder",
24            NodeKind::File => "file",
25            NodeKind::Module => "module",
26            NodeKind::Struct => "struct",
27            NodeKind::Enum => "enum",
28            NodeKind::Trait => "trait",
29            NodeKind::TypeAlias => "type_alias",
30            NodeKind::Function => "function",
31            NodeKind::Method => "method",
32            NodeKind::Constant => "constant",
33            NodeKind::Macro => "macro",
34        };
35        f.write_str(s)
36    }
37}
38
39/// Directed relationship between two nodes.
40#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
41#[serde(rename_all = "snake_case")]
42pub enum EdgeKind {
43    /// Parent–child containment: File→Module, Module→Struct, Struct→Method.
44    Contains,
45    /// Resolved call site: Function→Function or Method→Method.
46    Calls,
47    /// `impl Trait for Struct` — Struct→Trait.
48    Implements,
49    /// A type appears as a parameter or return type: fn→Struct/Trait.
50    Uses,
51    /// `use path::to::Thing` import.
52    Imports,
53}
54
55impl std::fmt::Display for EdgeKind {
56    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57        let s = match self {
58            EdgeKind::Contains => "contains",
59            EdgeKind::Calls => "calls",
60            EdgeKind::Implements => "implements",
61            EdgeKind::Uses => "uses",
62            EdgeKind::Imports => "imports",
63        };
64        f.write_str(s)
65    }
66}
67
68/// Symbol visibility in the source language.
69#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
70#[serde(rename_all = "snake_case")]
71pub enum Visibility {
72    #[default]
73    Private,
74    PubCrate,
75    Pub,
76}
77
78impl std::fmt::Display for Visibility {
79    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80        match self {
81            Visibility::Pub => f.write_str("pub"),
82            Visibility::PubCrate => f.write_str("pub_crate"),
83            Visibility::Private => f.write_str("private"),
84        }
85    }
86}
87
88// ── LLD labels ──────────────────────────────────────────────────────────────
89
90/// Which SOLID principle a node may be violating (populated in pass 2).
91#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
92#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
93pub enum SolidHint {
94    /// Too many responsibilities in one type.
95    Srp,
96    /// Logic closed for extension but open for modification.
97    Ocp,
98    /// Subtype breaks contract of supertype.
99    Lsp,
100    /// Interface has too many unrelated methods.
101    Isp,
102    /// Depends on concrete type instead of abstraction.
103    Dip,
104}
105
106/// Common design patterns detectable syntactically.
107#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
108#[serde(rename_all = "snake_case")]
109pub enum DesignPattern {
110    Builder,
111    Factory,
112    Observer,
113    Strategy,
114    Decorator,
115    Singleton,
116    Repository,
117}
118
119/// Code quality smells detectable without full type resolution.
120#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
121#[serde(rename_all = "snake_case")]
122pub enum CodeSmell {
123    /// Struct with too many methods or dependencies.
124    GodStruct,
125    /// Function body too long.
126    LongMethod,
127    /// Nesting depth exceeds threshold.
128    DeepNesting,
129    /// Trait with too many methods.
130    FatInterface,
131}