| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // Architecture diagram AST structures based on architectureTypes.ts
- package ast
- // ArchitectureDiagram represents an architecture diagram
- type ArchitectureDiagram struct {
- Services []*ArchitectureService `json:"services"`
- Groups []*ArchitectureGroup `json:"groups"`
- Edges []*ArchitectureEdge `json:"edges"`
- Title *string `json:"title,omitempty"`
- Config map[string]any `json:"config,omitempty"`
- }
- type ArchitectureService struct {
- ID string `json:"id"`
- Icon *string `json:"icon,omitempty"`
- IconText *string `json:"iconText,omitempty"`
- Title *string `json:"title,omitempty"`
- In *string `json:"in,omitempty"` // Group ID
- Width *int `json:"width,omitempty"`
- Height *int `json:"height,omitempty"`
- }
- type ArchitectureGroup struct {
- ID string `json:"id"`
- Icon *string `json:"icon,omitempty"`
- Title *string `json:"title,omitempty"`
- In *string `json:"in,omitempty"` // Parent group ID
- }
- type ArchitectureEdge struct {
- LhsID string `json:"lhsId"`
- LhsDir ArchitectureDirection `json:"lhsDir"`
- LhsInto *bool `json:"lhsInto,omitempty"`
- LhsGroup *bool `json:"lhsGroup,omitempty"`
- RhsID string `json:"rhsId"`
- RhsDir ArchitectureDirection `json:"rhsDir"`
- RhsInto *bool `json:"rhsInto,omitempty"`
- RhsGroup *bool `json:"rhsGroup,omitempty"`
- Title *string `json:"title,omitempty"`
- }
- type ArchitectureDirection string
- const (
- ArchitectureDirectionLeft ArchitectureDirection = "L"
- ArchitectureDirectionRight ArchitectureDirection = "R"
- ArchitectureDirectionTop ArchitectureDirection = "T"
- ArchitectureDirectionBottom ArchitectureDirection = "B"
- )
- // Type returns the diagram type
- func (a *ArchitectureDiagram) Type() DiagramType {
- return DiagramTypeArchitecture
- }
- // Validate checks if the architecture diagram is valid
- func (a *ArchitectureDiagram) Validate() error {
- // Basic validation - ensure all edges reference valid services/groups
- serviceMap := make(map[string]bool)
- groupMap := make(map[string]bool)
- for _, service := range a.Services {
- serviceMap[service.ID] = true
- }
- for _, group := range a.Groups {
- groupMap[group.ID] = true
- }
- for _, edge := range a.Edges {
- if !serviceMap[edge.LhsID] && !groupMap[edge.LhsID] {
- return NewValidationError("edge references non-existent service/group: " + edge.LhsID)
- }
- if !serviceMap[edge.RhsID] && !groupMap[edge.RhsID] {
- return NewValidationError("edge references non-existent service/group: " + edge.RhsID)
- }
- }
- return nil
- }
- // NewArchitectureDiagram creates a new architecture diagram
- func NewArchitectureDiagram() *ArchitectureDiagram {
- return &ArchitectureDiagram{
- Services: make([]*ArchitectureService, 0),
- Groups: make([]*ArchitectureGroup, 0),
- Edges: make([]*ArchitectureEdge, 0),
- Config: make(map[string]any),
- }
- }
|