Skip to main content

ctx/analytics/
mod.rs

1//! Analytics module using DuckDB for complex graph queries.
2//!
3//! This module is gated behind the `duckdb` feature flag. When disabled,
4//! a stub implementation is provided so the crate can still compile and
5//! run on platforms where DuckDB's bundled C++ library cannot build
6//! (e.g. Windows MSVC).
7
8use serde::{Deserialize, Serialize};
9
10// ============================================================================
11// Data structures (always available)
12// ============================================================================
13
14/// A node in a call graph.
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct CallGraphNode {
17    pub name: String,
18    pub file_path: String,
19    pub kind: String,
20    pub depth: i32,
21}
22
23/// A node in impact analysis.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct ImpactNode {
26    pub name: String,
27    pub file_path: String,
28    pub kind: String,
29    pub distance: i32,
30}
31
32/// Complexity analysis result for a function.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct ComplexityResult {
35    pub name: String,
36    pub file_path: String,
37    pub line: u32,
38    pub fan_out: i64,
39    pub fan_in: i64,
40    pub complexity_score: i64,
41    pub severity: String,
42}
43
44/// Module dependency information.
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[allow(dead_code)]
47pub struct ModuleDep {
48    pub source_module: String,
49    pub target_module: String,
50    pub imported_names: Vec<String>,
51}
52
53/// File statistics.
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct FileStats {
56    pub file_path: String,
57    pub symbol_count: i64,
58    pub functions: i64,
59    pub structs: i64,
60    pub enums: i64,
61    pub public_symbols: i64,
62}
63
64// ============================================================================
65// Platform-specific Analytics engine
66// ============================================================================
67
68#[cfg(feature = "duckdb")]
69mod duckdb_impl;
70
71#[cfg(not(feature = "duckdb"))]
72mod stub;
73
74#[cfg(feature = "duckdb")]
75pub use duckdb_impl::Analytics;
76
77#[cfg(feature = "duckdb")]
78pub use duckdb_impl::{SqlColumn, SqlResult};
79
80#[cfg(not(feature = "duckdb"))]
81pub use stub::Analytics;