pub mod builder;
pub mod relationships;
pub use builder::GraphBuilder;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphData {
pub nodes: Vec<GraphNode>,
pub edges: Vec<GraphEdge>,
pub clusters: Vec<GraphCluster>,
}
impl GraphData {
pub fn new() -> Self {
Self {
nodes: Vec::new(),
edges: Vec::new(),
clusters: Vec::new(),
}
}
pub fn add_node(&mut self, node: GraphNode) {
self.nodes.push(node);
}
pub fn add_edge(&mut self, edge: GraphEdge) {
self.edges.push(edge);
}
pub fn add_cluster(&mut self, cluster: GraphCluster) {
self.clusters.push(cluster);
}
pub fn find_node(&self, id: &str) -> Option<&GraphNode> {
self.nodes.iter().find(|n| n.id == id)
}
pub fn edges_for_node(&self, node_id: &str) -> Vec<&GraphEdge> {
self.edges.iter().filter(|e| e.from == node_id || e.to == node_id).collect()
}
}
impl Default for GraphData {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphNode {
pub id: String,
pub label: String,
pub node_type: NodeType,
pub protocol: Option<Protocol>,
pub current_state: Option<String>,
#[serde(default)]
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum NodeType {
Endpoint,
Service,
Workspace,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Protocol {
Http,
Grpc,
Websocket,
Graphql,
Mqtt,
Smtp,
Kafka,
Amqp,
Ftp,
}
impl From<&str> for Protocol {
fn from(s: &str) -> Self {
match s.to_lowercase().as_str() {
"http" => Protocol::Http,
"grpc" => Protocol::Grpc,
"websocket" => Protocol::Websocket,
"graphql" => Protocol::Graphql,
"mqtt" => Protocol::Mqtt,
"smtp" => Protocol::Smtp,
"kafka" => Protocol::Kafka,
"amqp" => Protocol::Amqp,
"ftp" => Protocol::Ftp,
_ => Protocol::Http, }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphEdge {
pub from: String,
pub to: String,
pub edge_type: EdgeType,
pub label: Option<String>,
#[serde(default)]
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum EdgeType {
Dependency,
StateTransition,
ServiceCall,
DataFlow,
Contains,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphCluster {
pub id: String,
pub label: String,
pub cluster_type: ClusterType,
pub node_ids: Vec<String>,
#[serde(default)]
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum ClusterType {
Workspace,
Service,
Chain,
}