Skip to main content

graphyn_core/
ir.rs

1use serde::{Deserialize, Serialize};
2
3/// Unique identifier for a symbol across the entire codebase.
4/// Format: "relative/file/path.ts::SymbolName::kind"
5/// Example: "src/models/user.ts::UserPayload::class"
6/// Example: "src/models/user.ts::UserPayload::userId::property"
7pub type SymbolId = String;
8
9/// A symbol — any named entity in source code.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Symbol {
12    pub id: SymbolId,
13    pub name: String,
14    pub kind: SymbolKind,
15    pub language: Language,
16    pub file: String,
17    pub line_start: u32,
18    pub line_end: u32,
19    pub signature: Option<String>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
23pub enum SymbolKind {
24    Class,
25    Interface,
26    TypeAlias,
27    Function,
28    Method,
29    Property,
30    Variable,
31    Module,
32    Enum,
33    EnumVariant,
34    ExternalPackage,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
38pub enum Language {
39    TypeScript,
40    JavaScript,
41    Python,
42    Rust,
43    Go,
44    Java,
45    C,
46    Cpp,
47}
48
49/// A directed relationship between two symbols.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct Relationship {
52    pub from: SymbolId,
53    pub to: SymbolId,
54    pub kind: RelationshipKind,
55    pub alias: Option<String>,
56    pub properties_accessed: Vec<String>,
57    pub context: String,
58    pub file: String,
59    pub line: u32,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
63pub enum RelationshipKind {
64    Imports,
65    Calls,
66    Extends,
67    Implements,
68    UsesType,
69    AccessesProperty,
70    ReExports,
71    Instantiates,
72}
73
74// diagnostics
75
76#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
77pub enum DiagnosticLevel {
78    /// Actual tree-sitter parse failures
79    Error,
80    /// Local relative import target not found, symbol not resolved
81    Warning,
82    /// Skipped minified file, .d.ts excluded, etc.
83    Info,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
87pub enum DiagnosticCategory {
88    /// Tree-sitter parse errors
89    Parse,
90    /// Unresolved imports, symbols, types
91    Resolution,
92    /// Skipped minified or bundled files
93    Skip,
94    /// Excluded by file policy rules
95    Policy,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct Diagnostic {
100    pub level: DiagnosticLevel,
101    pub category: DiagnosticCategory,
102    pub message: String,
103    pub file: Option<String>,
104    pub line: Option<u32>,
105}
106
107// re-export tracking (for barrel chain resolution)
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct ReExportEntry {
111    /// Name being re-exported (e.g. "renderBlockquote")
112    pub exported_name: String,
113    /// Module specifier (e.g. "./blockquote")
114    pub source_module: String,
115}
116
117/// The complete IR output from one file parse.
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct FileIR {
120    pub file: String,
121    pub language: Language,
122    pub symbols: Vec<Symbol>,
123    pub relationships: Vec<Relationship>,
124    pub diagnostics: Vec<Diagnostic>,
125    pub re_exports: Vec<ReExportEntry>,
126}
127
128/// The complete IR output from a full repo or incremental update.
129#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct RepoIR {
131    pub root: String,
132    pub files: Vec<FileIR>,
133    pub language_stats: std::collections::HashMap<String, usize>,
134}