sqry_core/graph/mod.rs
1//! Unified graph architecture for cross-language code analysis
2//!
3//! This module implements the core data structures and algorithms for sqry's
4//! unified graph architecture, enabling cross-language queries, visualization,
5//! and advanced analysis.
6//!
7//! # Architecture
8//!
9//! The graph architecture consists of:
10//! - **Nodes**: Code entities (functions, classes, modules)
11//! - **Edges**: Relationships (calls, imports, HTTP, FFI)
12//! - **Indices**: Fast lookup structures for queries
13//! - **Builders**: Language-specific graph construction
14//!
15//! # Memory Optimization
16//!
17//! Per AGENTS.md:149-151, strings are interned via `Arc<str>` to reduce memory
18//! usage in symbol-heavy data structures (saves 10-50 MB for typical repos).
19//!
20//! # Concurrency
21//!
22//! The graph uses interior mutability (DashMap) to allow concurrent graph
23//! building while maintaining a shared reference (&CodeGraph).
24//!
25//! # Example
26//!
27//! ```rust
28//! use sqry_core::graph::node::{NodeId, Language};
29//!
30//! // Create node identifiers with string interning
31//! let node_id = NodeId::new(Language::Cpp, "main.cpp", "main");
32//! assert_eq!(node_id.to_string(), "cpp:main.cpp:main");
33//!
34//! // Node name extraction works across languages
35//! let cpp_id = NodeId::new(Language::Cpp, "utils.cpp", "std::vector::push_back");
36//! assert_eq!(cpp_id.symbol_name(), "push_back");
37//!
38//! let py_id = NodeId::new(Language::Python, "api.py", "User.authenticate");
39//! assert_eq!(py_id.symbol_name(), "authenticate");
40//! ```
41
42pub mod body_hash;
43pub mod builder;
44pub mod call_sites;
45pub mod edge;
46pub mod error;
47pub mod local_scopes;
48pub mod node;
49pub mod path_resolver;
50
51/// Unified graph architecture with Arena+CSR storage.
52///
53/// This module provides the new high-performance graph implementation
54/// with generational indices, two-tier edge storage, and MVCC concurrency.
55///
56/// See `docs/development/graph-architecture-reconcile-*/` for design docs.
57pub mod unified;
58
59/// Graph comparison and diff functionality.
60///
61/// This module provides tools for comparing two CodeGraph instances to detect
62/// symbol changes between different versions of code (e.g., git refs).
63pub mod diff;
64
65// ============================================================================
66// Primary Exports (Unified Graph - )
67// ============================================================================
68
69/// The unified code graph with Arena+CSR storage.
70///
71/// This is the primary graph type for new code. It provides:
72/// - Generational indices for safe node/edge references
73/// - Two-tier edge storage (inline for common, external for metadata-heavy)
74/// - MVCC concurrency via snapshots
75///
76/// For concurrent building, use [`ConcurrentCodeGraph`] which wraps this type
77/// with interior mutability.
78pub use unified::concurrent::CodeGraph;
79
80/// Thread-safe wrapper for concurrent graph building.
81pub use unified::ConcurrentCodeGraph;
82
83/// Immutable graph snapshot for queries.
84pub use unified::GraphSnapshot;
85
86// ============================================================================
87// Core Type Exports
88// ============================================================================
89
90pub use body_hash::{BodyHash128, HASH_SEED_0, HASH_SEED_1};
91pub use builder::GraphBuilder;
92pub use call_sites::{CallSite, CallSiteExtras, CallSiteMetadata};
93pub use edge::{CodeEdge, DetectionMethod, EdgeId, EdgeKind, EdgeMetadata, FFIType, TableWriteOp};
94pub use error::{GraphBuilderError, GraphResult};
95pub use node::{CodeNode, Language, NodeId, NodeKind, Position, Span};
96pub use path_resolver::{normalize_path, resolve_import_path, resolve_python_import};