architecture.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Architecture diagram AST structures based on architectureTypes.ts
  2. package ast
  3. // ArchitectureDiagram represents an architecture diagram
  4. type ArchitectureDiagram struct {
  5. Services []*ArchitectureService `json:"services"`
  6. Groups []*ArchitectureGroup `json:"groups"`
  7. Edges []*ArchitectureEdge `json:"edges"`
  8. Title *string `json:"title,omitempty"`
  9. Config map[string]any `json:"config,omitempty"`
  10. }
  11. type ArchitectureService struct {
  12. ID string `json:"id"`
  13. Icon *string `json:"icon,omitempty"`
  14. IconText *string `json:"iconText,omitempty"`
  15. Title *string `json:"title,omitempty"`
  16. In *string `json:"in,omitempty"` // Group ID
  17. Width *int `json:"width,omitempty"`
  18. Height *int `json:"height,omitempty"`
  19. }
  20. type ArchitectureGroup struct {
  21. ID string `json:"id"`
  22. Icon *string `json:"icon,omitempty"`
  23. Title *string `json:"title,omitempty"`
  24. In *string `json:"in,omitempty"` // Parent group ID
  25. }
  26. type ArchitectureEdge struct {
  27. LhsID string `json:"lhsId"`
  28. LhsDir ArchitectureDirection `json:"lhsDir"`
  29. LhsInto *bool `json:"lhsInto,omitempty"`
  30. LhsGroup *bool `json:"lhsGroup,omitempty"`
  31. RhsID string `json:"rhsId"`
  32. RhsDir ArchitectureDirection `json:"rhsDir"`
  33. RhsInto *bool `json:"rhsInto,omitempty"`
  34. RhsGroup *bool `json:"rhsGroup,omitempty"`
  35. Title *string `json:"title,omitempty"`
  36. }
  37. type ArchitectureDirection string
  38. const (
  39. ArchitectureDirectionLeft ArchitectureDirection = "L"
  40. ArchitectureDirectionRight ArchitectureDirection = "R"
  41. ArchitectureDirectionTop ArchitectureDirection = "T"
  42. ArchitectureDirectionBottom ArchitectureDirection = "B"
  43. )
  44. // Type returns the diagram type
  45. func (a *ArchitectureDiagram) Type() DiagramType {
  46. return DiagramTypeArchitecture
  47. }
  48. // Validate checks if the architecture diagram is valid
  49. func (a *ArchitectureDiagram) Validate() error {
  50. // Basic validation - ensure all edges reference valid services/groups
  51. serviceMap := make(map[string]bool)
  52. groupMap := make(map[string]bool)
  53. for _, service := range a.Services {
  54. serviceMap[service.ID] = true
  55. }
  56. for _, group := range a.Groups {
  57. groupMap[group.ID] = true
  58. }
  59. for _, edge := range a.Edges {
  60. if !serviceMap[edge.LhsID] && !groupMap[edge.LhsID] {
  61. return NewValidationError("edge references non-existent service/group: " + edge.LhsID)
  62. }
  63. if !serviceMap[edge.RhsID] && !groupMap[edge.RhsID] {
  64. return NewValidationError("edge references non-existent service/group: " + edge.RhsID)
  65. }
  66. }
  67. return nil
  68. }
  69. // NewArchitectureDiagram creates a new architecture diagram
  70. func NewArchitectureDiagram() *ArchitectureDiagram {
  71. return &ArchitectureDiagram{
  72. Services: make([]*ArchitectureService, 0),
  73. Groups: make([]*ArchitectureGroup, 0),
  74. Edges: make([]*ArchitectureEdge, 0),
  75. Config: make(map[string]any),
  76. }
  77. }