use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum DiagramType {
Flowchart,
Sequence,
Class,
State,
ER,
Pie,
GitGraph,
Block,
Treemap,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum NodeShape {
Rectangle, Rounded, Diamond, Stadium, Subroutine, Circle, DoubleCircle, Hexagon, Cylinder, Asymmetric, Parallelogram, Trapezoid, }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum EdgeStyle {
Solid, Dotted, Thick, Bidirectional, CircleEnd, CrossEnd, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Node {
pub id: String,
pub label: String,
pub shape: NodeShape,
pub style: Option<String>,
pub class: Option<String>,
pub members: Vec<ClassMember>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClassMember {
pub name: String,
pub member_type: MemberType,
pub visibility: Visibility,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MemberType {
Field,
Method,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Visibility {
Public, Private, Protected, Package, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Edge {
pub from: String,
pub to: String,
pub label: Option<String>,
pub style: EdgeStyle,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Diagram {
pub diagram_type: DiagramType,
pub direction: String, pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
pub relationships: Vec<Relationship>,
pub participants: Vec<String>,
pub entities: Vec<Entity>,
}
impl Default for Diagram {
fn default() -> Self {
Self {
diagram_type: DiagramType::Flowchart,
direction: "LR".to_string(),
nodes: Vec::new(),
edges: Vec::new(),
relationships: Vec::new(),
participants: Vec::new(),
entities: Vec::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entity {
pub name: String,
pub attributes: Vec<EntityAttribute>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EntityAttribute {
pub name: String,
pub attr_type: String,
pub is_primary_key: bool,
pub is_foreign_key: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Relationship {
pub from: String,
pub to: String,
pub rel_type: String, }
impl Node {
pub fn new(id: impl Into<String>, label: impl Into<String>) -> Self {
Self {
id: id.into(),
label: label.into(),
shape: NodeShape::Rectangle,
style: None,
class: None,
members: Vec::new(),
}
}
}
impl Edge {
pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self {
Self {
from: from.into(),
to: to.into(),
label: None,
style: EdgeStyle::Solid,
}
}
}