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}
46
47/// A directed relationship between two symbols.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct Relationship {
50    pub from: SymbolId,
51    pub to: SymbolId,
52    pub kind: RelationshipKind,
53    pub alias: Option<String>,
54    pub properties_accessed: Vec<String>,
55    pub context: String,
56    pub file: String,
57    pub line: u32,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
61pub enum RelationshipKind {
62    Imports,
63    Calls,
64    Extends,
65    Implements,
66    UsesType,
67    AccessesProperty,
68    ReExports,
69    Instantiates,
70}
71
72// diagnostics
73
74#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
75pub enum DiagnosticLevel {
76    /// Actual tree-sitter parse failures
77    Error,
78    /// Local relative import target not found, symbol not resolved
79    Warning,
80    /// Skipped minified file, .d.ts excluded, etc.
81    Info,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
85pub enum DiagnosticCategory {
86    /// Tree-sitter parse errors
87    Parse,
88    /// Unresolved imports, symbols, types
89    Resolution,
90    /// Skipped minified or bundled files
91    Skip,
92    /// Excluded by file policy rules
93    Policy,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct Diagnostic {
98    pub level: DiagnosticLevel,
99    pub category: DiagnosticCategory,
100    pub message: String,
101    pub file: Option<String>,
102    pub line: Option<u32>,
103}
104
105// re-export tracking (for barrel chain resolution)
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct ReExportEntry {
109    /// Name being re-exported (e.g. "renderBlockquote")
110    pub exported_name: String,
111    /// Module specifier (e.g. "./blockquote")
112    pub source_module: String,
113}
114
115/// The complete IR output from one file parse.
116#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct FileIR {
118    pub file: String,
119    pub language: Language,
120    pub symbols: Vec<Symbol>,
121    pub relationships: Vec<Relationship>,
122    pub diagnostics: Vec<Diagnostic>,
123    pub re_exports: Vec<ReExportEntry>,
124}
125
126/// The complete IR output from a full repo or incremental update.
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct RepoIR {
129    pub root: String,
130    pub files: Vec<FileIR>,
131    pub language_stats: std::collections::HashMap<String, usize>,
132}