Skip to main content

comindly_api/
graph.rs

1use crate::model::EdgeKind;
2
3/// A node as returned to callers — flat, printable, agent-friendly.
4#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
5pub struct Node {
6    pub id: String,
7    pub name: String,
8    pub kind: String,
9    pub repo: String,
10    /// `path:line` — jump straight here.
11    pub location: String,
12    pub signature: Option<String>,
13}
14
15/// A step of a flow: the node, how it was reached and from which node.
16#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
17pub struct FlowStep {
18    pub node: Node,
19    pub depth: usize,
20    pub via: String,
21    pub from: String,
22}
23
24/// A node plus how far it sits from the focus (BFS depth) and via which relation.
25#[derive(Debug, Clone, serde::Serialize)]
26pub struct Hop {
27    pub node: Node,
28    pub depth: usize,
29    pub via: EdgeKind,
30}
31
32/// The 360° view of one symbol.
33#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
34pub struct Zoom {
35    pub focus: Option<Node>,
36    pub container: Option<Node>,
37    pub members: Vec<Node>,
38    pub callers: Vec<Node>,
39    pub callees: Vec<Node>,
40    pub importers: Vec<Node>,
41    /// Contracts this symbol takes part in, with the other side of each.
42    pub contracts: Vec<ContractRole>,
43    /// When the focus is itself a contract: who provides and who consumes it.
44    pub providers: Vec<Node>,
45    pub consumers: Vec<Node>,
46}
47
48/// A symbol's role in a contract (`serves http:GET /x`) and the participants on the other side.
49#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
50pub struct ContractRole {
51    pub role: EdgeKind,
52    pub contract: Node,
53    pub counterparts: Vec<Node>,
54}
55
56/// A contract with everyone on each side.
57#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
58pub struct ContractView {
59    pub contract: Node,
60    pub providers: Vec<Node>,
61    pub consumers: Vec<Node>,
62}
63
64/// The repo-like owner of contract nodes.
65pub const CONTRACTS: &str = "_contracts";