Help us shape the future of Go! Take the 2026 Go Developer Survey

graph

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package graph provides an intermediate graph representation for rendering system-spec to various diagram formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	// ID is the unique edge identifier
	ID string `json:"id"`

	// Source node ID
	Source string `json:"source"`

	// Target node ID
	Target string `json:"target"`

	// Label for display
	Label string `json:"label,omitempty"`

	// Kind categorizes the edge
	Kind EdgeKind `json:"kind"`

	// Protocol (http, grpc, tcp, sql, amqp, redis, etc.)
	Protocol string `json:"protocol,omitempty"`

	// Port number
	Port int `json:"port,omitempty"`

	// Metadata contains additional key-value data
	Metadata map[string]string `json:"metadata,omitempty"`
}

Edge represents a directed edge between nodes.

type EdgeKind

type EdgeKind string

EdgeKind categorizes edges for rendering and styling.

const (
	EdgeKindConnection EdgeKind = "connection" // service to service
	EdgeKindDatabase   EdgeKind = "database"   // service to database
	EdgeKindQueue      EdgeKind = "queue"      // service to queue
	EdgeKindStorage    EdgeKind = "storage"    // service to storage
	EdgeKindDeploys    EdgeKind = "deploys"    // helm/terraform to service
)

type Graph

type Graph struct {
	// Nodes in the graph
	Nodes []Node `json:"nodes"`

	// Edges connecting nodes
	Edges []Edge `json:"edges"`
}

Graph is the intermediate representation for rendering. It decouples the spec structure from renderer output formats.

func FromSystem

func FromSystem(s *spec.System) *Graph

FromSystem converts a System spec to a Graph for rendering.

func NewGraph

func NewGraph() *Graph

NewGraph creates an empty graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(e Edge)

AddEdge adds an edge to the graph.

func (*Graph) AddNode

func (g *Graph) AddNode(n Node)

AddNode adds a node to the graph.

func (*Graph) EdgesFrom

func (g *Graph) EdgesFrom(nodeID string) []Edge

EdgesFrom returns all edges originating from the given node ID.

func (*Graph) EdgesTo

func (g *Graph) EdgesTo(nodeID string) []Edge

EdgesTo returns all edges pointing to the given node ID.

func (*Graph) NodeByID

func (g *Graph) NodeByID(id string) *Node

NodeByID finds a node by ID, returns nil if not found.

type Node

type Node struct {
	// ID is the unique node identifier
	ID string `json:"id"`

	// Label is the display name
	Label string `json:"label"`

	// Kind categorizes the node for styling
	Kind NodeKind `json:"kind"`

	// Group for clustering (e.g., VPC name, namespace)
	Group string `json:"group,omitempty"`

	// Metadata contains additional key-value data for renderers
	Metadata map[string]string `json:"metadata,omitempty"`
}

Node represents a vertex in the graph.

type NodeKind

type NodeKind string

NodeKind categorizes nodes for rendering and styling.

const (
	NodeKindService   NodeKind = "service"
	NodeKindDatabase  NodeKind = "database"
	NodeKindQueue     NodeKind = "queue"
	NodeKindTopic     NodeKind = "topic"
	NodeKindStorage   NodeKind = "storage"
	NodeKindCDN       NodeKind = "cdn"
	NodeKindWorker    NodeKind = "worker"
	NodeKindAIModel   NodeKind = "ai_model"
	NodeKindVPC       NodeKind = "vpc"
	NodeKindSubnet    NodeKind = "subnet"
	NodeKindExternal  NodeKind = "external"
	NodeKindHelm      NodeKind = "helm"
	NodeKindTerraform NodeKind = "terraform"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL