File size: 4,669 Bytes
da590a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package models

import "time"

// AnalysisRequest represents the request to analyze a repository
type AnalysisRequest struct {
	RepoURL string `json:"repo_url" binding:"required"`
	Token   string `json:"token,omitempty"`
	Options Options `json:"options,omitempty"`
}

// Options for analysis
type Options struct {
	IncludeTests     bool `json:"include_tests"`
	MaxDepth         int  `json:"max_depth"`
	ExcludeVendor    bool `json:"exclude_vendor"`
	IncludeDependencies bool `json:"include_dependencies"`
}

// AnalysisResult contains the analyzed repository structure
type AnalysisResult struct {
	ID        string    `json:"id"`
	RepoURL   string    `json:"repo_url"`
	RepoName  string    `json:"repo_name"`
	CreatedAt time.Time `json:"created_at"`
	Status    string    `json:"status"`
	Error     string    `json:"error,omitempty"`
	Structure RepositoryStructure `json:"structure"`
	Stats     Statistics         `json:"stats"`
}

// RepositoryStructure represents the file/directory structure
type RepositoryStructure struct {
	Name        string                 `json:"name"`
	Type        string                 `json:"type"` // "file" or "directory"
	Path        string                 `json:"path"`
	Language    string                 `json:"language,omitempty"`
	Size        int64                  `json:"size,omitempty"`
	Children    []RepositoryStructure  `json:"children,omitempty"`
	Dependencies []string              `json:"dependencies,omitempty"`
	Imports     []string              `json:"imports,omitempty"`
}

// Statistics about the repository
type Statistics struct {
	TotalFiles      int    `json:"total_files"`
	TotalDirectories int   `json:"total_directories"`
	Languages       map[string]int `json:"languages"`
	MainLanguage    string         `json:"main_language"`
	TotalLines      int            `json:"total_lines"`
}

// Diagram represents the generated architecture diagram
type Diagram struct {
	ID          string    `json:"id"`
	RepoID      string    `json:"repo_id"`
	CreatedAt   time.Time `json:"created_at"`
	SVG         []byte    `json:"-"`
	JSON        DiagramJSON `json:"json"`
	Version     string    `json:"version"`
}

// DiagramJSON is the JSON representation of the diagram
type DiagramJSON struct {
	Nodes    []DiagramNode    `json:"nodes"`
	Edges    []DiagramEdge    `json:"edges"`
	Settings DiagramSettings `json:"settings"`
}

// DiagramNode represents a component/node in the diagram
type DiagramNode struct {
	ID          string                 `json:"id"`
	Label       string                 `json:"label"`
	Type        string                 `json:"type"` // "package", "module", "file", "directory"
	Properties  map[string]interface{} `json:"properties,omitempty"`
	Position    Position               `json:"position,omitempty"`
	Style       NodeStyle              `json:"style,omitempty"`
}

// DiagramEdge represents a connection/relationship between nodes
type DiagramEdge struct {
	ID     string `json:"id"`
	Source string `json:"source"`
	Target string `json:"target"`
	Type   string `json:"type"` // "import", "dependency", "contains"
	Label  string `json:"label,omitempty"`
	Style  EdgeStyle `json:"style,omitempty"`
}

// DiagramSettings for rendering
type DiagramSettings struct {
	Layout       string  `json:"layout"` // "hierarchical", "circular", "force"
	Direction    string  `json:"direction"` // "TB", "LR", "RL", "BT"
	RankSep      int     `json:"rank_sep"`
	NodeSep      int     `json:"node_sep"`
	ShowLabels   bool    `json:"show_labels"`
	Cluster      bool    `json:"cluster"`
}

// Position for nodes
type Position struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

// NodeStyle for visual appearance
type NodeStyle struct {
	Shape   string `json:"shape"`
	Color   string `json:"color"`
	Border  string `json:"border"`
	Font    Font   `json:"font"`
}

// EdgeStyle for visual appearance
type EdgeStyle struct {
	Color       string `json:"color"`
	Width       int    `json:"width"`
	Style       string `json:"style"` // "solid", "dashed", "dotted"
	ArrowHead   string `json:"arrow_head"`
	LabelOffset int    `json:"label_offset"`
}

// Font settings
type Font struct {
	Name  string `json:"name"`
	Size  int    `json:"size"`
	Color string `json:"color"`
}

// AnalysisResponse for API response
type AnalysisResponse struct {
	ID     string `json:"id"`
	Status string `json:"status"`
	Message string `json:"message"`
}

// ErrorResponse for API errors
type ErrorResponse struct {
	Error string `json:"error"`
}

// WorkerTask represents a background analysis task
type WorkerTask struct {
	ID        string
	Result    *AnalysisResult
	Diagram   *Diagram
	ErrChan   chan error
	DoneChan  chan bool
}