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}
35
36#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
37pub enum Language {
38    TypeScript,
39    JavaScript,
40    Python,
41    Rust,
42    Go,
43    Java,
44}
45
46/// A directed relationship between two symbols.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct Relationship {
49    pub from: SymbolId,
50    pub to: SymbolId,
51    pub kind: RelationshipKind,
52    pub alias: Option<String>,
53    pub properties_accessed: Vec<String>,
54    pub context: String,
55    pub file: String,
56    pub line: u32,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
60pub enum RelationshipKind {
61    Imports,
62    Calls,
63    Extends,
64    Implements,
65    UsesType,
66    AccessesProperty,
67    ReExports,
68    Instantiates,
69}
70
71/// The complete IR output from one file parse.
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct FileIR {
74    pub file: String,
75    pub language: Language,
76    pub symbols: Vec<Symbol>,
77    pub relationships: Vec<Relationship>,
78    pub parse_errors: Vec<String>,
79}
80
81/// The complete IR output from a full repo or incremental update.
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct RepoIR {
84    pub root: String,
85    pub files: Vec<FileIR>,
86    pub language_stats: std::collections::HashMap<String, usize>,
87}