archsight 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +24 -0
  3. data/CODE_OF_CONDUCT.md +10 -0
  4. data/CONTRIBUTING.md +186 -0
  5. data/Dockerfile +39 -0
  6. data/LICENSE.txt +201 -0
  7. data/README.md +170 -0
  8. data/SECURITY.md +27 -0
  9. data/exe/archsight +9 -0
  10. data/lib/archsight/annotations/aggregators.rb +109 -0
  11. data/lib/archsight/annotations/annotation.rb +168 -0
  12. data/lib/archsight/annotations/architecture_annotations.rb +59 -0
  13. data/lib/archsight/annotations/backup_annotations.rb +21 -0
  14. data/lib/archsight/annotations/computed.rb +264 -0
  15. data/lib/archsight/annotations/email_recipient.rb +35 -0
  16. data/lib/archsight/annotations/generated_annotations.rb +17 -0
  17. data/lib/archsight/annotations/git_annotations.rb +21 -0
  18. data/lib/archsight/annotations/relation_resolver.rb +160 -0
  19. data/lib/archsight/cli.rb +120 -0
  20. data/lib/archsight/configuration.rb +36 -0
  21. data/lib/archsight/database.rb +183 -0
  22. data/lib/archsight/documentation.rb +171 -0
  23. data/lib/archsight/graph.rb +113 -0
  24. data/lib/archsight/helpers.rb +210 -0
  25. data/lib/archsight/linter.rb +77 -0
  26. data/lib/archsight/mcp/analyze_resource_tool.rb +222 -0
  27. data/lib/archsight/mcp/base.rb +48 -0
  28. data/lib/archsight/mcp/query_tool.rb +113 -0
  29. data/lib/archsight/mcp/resource_doc_tool.rb +87 -0
  30. data/lib/archsight/mcp.rb +6 -0
  31. data/lib/archsight/query/ast.rb +279 -0
  32. data/lib/archsight/query/errors.rb +39 -0
  33. data/lib/archsight/query/evaluator.rb +707 -0
  34. data/lib/archsight/query/lexer.rb +289 -0
  35. data/lib/archsight/query/parser.rb +506 -0
  36. data/lib/archsight/query.rb +68 -0
  37. data/lib/archsight/renderer.rb +134 -0
  38. data/lib/archsight/resources/application_component.rb +346 -0
  39. data/lib/archsight/resources/application_interface.rb +54 -0
  40. data/lib/archsight/resources/application_service.rb +222 -0
  41. data/lib/archsight/resources/base.rb +300 -0
  42. data/lib/archsight/resources/business_actor.rb +195 -0
  43. data/lib/archsight/resources/business_constraint.rb +32 -0
  44. data/lib/archsight/resources/business_process.rb +37 -0
  45. data/lib/archsight/resources/business_product.rb +206 -0
  46. data/lib/archsight/resources/business_requirement.rb +56 -0
  47. data/lib/archsight/resources/compliance_evidence.rb +42 -0
  48. data/lib/archsight/resources/data_object.rb +49 -0
  49. data/lib/archsight/resources/motivation_goal.rb +37 -0
  50. data/lib/archsight/resources/motivation_outcome.rb +33 -0
  51. data/lib/archsight/resources/motivation_stakeholder.rb +38 -0
  52. data/lib/archsight/resources/strategy_capability.rb +38 -0
  53. data/lib/archsight/resources/technology_artifact.rb +154 -0
  54. data/lib/archsight/resources/technology_interface.rb +34 -0
  55. data/lib/archsight/resources/technology_node.rb +42 -0
  56. data/lib/archsight/resources/technology_service.rb +35 -0
  57. data/lib/archsight/resources/technology_system_software.rb +37 -0
  58. data/lib/archsight/resources/view.rb +51 -0
  59. data/lib/archsight/resources.rb +49 -0
  60. data/lib/archsight/template.rb +49 -0
  61. data/lib/archsight/version.rb +5 -0
  62. data/lib/archsight/web/application.rb +290 -0
  63. data/lib/archsight/web/doc/archimate.md +215 -0
  64. data/lib/archsight/web/doc/computed_annotations.md +316 -0
  65. data/lib/archsight/web/doc/icons.md +303 -0
  66. data/lib/archsight/web/doc/index.md.erb +74 -0
  67. data/lib/archsight/web/doc/modeling.md +200 -0
  68. data/lib/archsight/web/doc/search.md +227 -0
  69. data/lib/archsight/web/doc/togaf.md +255 -0
  70. data/lib/archsight/web/doc/tool.md +90 -0
  71. data/lib/archsight/web/public/css/artifact.css +985 -0
  72. data/lib/archsight/web/public/css/base.css +201 -0
  73. data/lib/archsight/web/public/css/graph.css +106 -0
  74. data/lib/archsight/web/public/css/highlight.min.css +10 -0
  75. data/lib/archsight/web/public/css/iconoir.css +22 -0
  76. data/lib/archsight/web/public/css/instance.css +329 -0
  77. data/lib/archsight/web/public/css/layout.css +421 -0
  78. data/lib/archsight/web/public/css/mermaid-layers.css +188 -0
  79. data/lib/archsight/web/public/css/pico.min.css +4 -0
  80. data/lib/archsight/web/public/favicon.ico +0 -0
  81. data/lib/archsight/web/public/img/archimate.png +0 -0
  82. data/lib/archsight/web/public/img/togaf-high-level.png +0 -0
  83. data/lib/archsight/web/public/js/graph-zoom.js +18 -0
  84. data/lib/archsight/web/public/js/highlight.min.js +3899 -0
  85. data/lib/archsight/web/public/js/htmx.min.js +1 -0
  86. data/lib/archsight/web/public/js/mermaid-init.js +88 -0
  87. data/lib/archsight/web/public/js/mermaid.min.js +2811 -0
  88. data/lib/archsight/web/public/js/sparkline.js +42 -0
  89. data/lib/archsight/web/public/js/svg-pan-zoom.min.js +3 -0
  90. data/lib/archsight/web/public/js/svg-zoom-controls.js +93 -0
  91. data/lib/archsight/web/views/index.haml +12 -0
  92. data/lib/archsight/web/views/partials/artifact/_activity.haml +55 -0
  93. data/lib/archsight/web/views/partials/artifact/_agentic.haml +25 -0
  94. data/lib/archsight/web/views/partials/artifact/_deployment.haml +29 -0
  95. data/lib/archsight/web/views/partials/artifact/_git_info.haml +16 -0
  96. data/lib/archsight/web/views/partials/artifact/_language_stats.haml +53 -0
  97. data/lib/archsight/web/views/partials/artifact/_links.haml +24 -0
  98. data/lib/archsight/web/views/partials/artifact/_project_estimate.haml +26 -0
  99. data/lib/archsight/web/views/partials/artifact/_repositories.haml +55 -0
  100. data/lib/archsight/web/views/partials/artifact/_team.haml +83 -0
  101. data/lib/archsight/web/views/partials/artifact/_workflow.haml +69 -0
  102. data/lib/archsight/web/views/partials/components/_activity.haml +37 -0
  103. data/lib/archsight/web/views/partials/components/_git.haml +17 -0
  104. data/lib/archsight/web/views/partials/components/_jira.haml +18 -0
  105. data/lib/archsight/web/views/partials/components/_languages.haml +29 -0
  106. data/lib/archsight/web/views/partials/components/_owner.haml +15 -0
  107. data/lib/archsight/web/views/partials/components/_repositories.haml +37 -0
  108. data/lib/archsight/web/views/partials/components/_status.haml +23 -0
  109. data/lib/archsight/web/views/partials/instance/_detail.haml +99 -0
  110. data/lib/archsight/web/views/partials/instance/_graph.haml +6 -0
  111. data/lib/archsight/web/views/partials/instance/_list.haml +84 -0
  112. data/lib/archsight/web/views/partials/instance/_relations.haml +43 -0
  113. data/lib/archsight/web/views/partials/instance/_requirements.haml +41 -0
  114. data/lib/archsight/web/views/partials/instance/_view_detail.haml +57 -0
  115. data/lib/archsight/web/views/partials/layout/_content.haml +40 -0
  116. data/lib/archsight/web/views/partials/layout/_error.haml +22 -0
  117. data/lib/archsight/web/views/partials/layout/_head.haml +24 -0
  118. data/lib/archsight/web/views/partials/layout/_navigation.haml +20 -0
  119. data/lib/archsight/web/views/partials/layout/_sidebar.haml +27 -0
  120. data/lib/archsight/web/views/search.haml +53 -0
  121. data/lib/archsight.rb +17 -0
  122. metadata +311 -0
@@ -0,0 +1,215 @@
1
+ # ArchiMate 3.2 Reference
2
+
3
+ ## Overview
4
+
5
+ ArchiMate is an open and independent enterprise architecture modeling language developed by The Open Group. It provides a uniform representation for diagrams that describe enterprise architectures across multiple layers.
6
+
7
+ ![ArchiMate](/img/archimate.png)
8
+
9
+ ## Relationship Types
10
+
11
+ ### Structural Relationships
12
+
13
+ | Relationship | Description |
14
+ |--------------|-------------|
15
+ | **Composition** | Represents that an element consists of one or more other concepts. Strong ownership. |
16
+ | **Aggregation** | Represents that an element combines one or more other concepts. Weaker ownership. |
17
+ | **Assignment** | Represents the allocation of responsibility, performance of behavior, storage, or execution. |
18
+ | **Realization** | Represents that an element plays a critical role in the creation, achievement, sustenance, or operation of a more abstract element. |
19
+
20
+ ### Dependency Relationships
21
+
22
+ | Relationship | Description |
23
+ |--------------|-------------|
24
+ | **Serving** | Represents that an element provides its functionality to another element. |
25
+ | **Access** | Represents the ability of behavior and active structure elements to observe or act upon passive structure elements. |
26
+ | **Influence** | Represents that an element affects the implementation or achievement of some motivation element. Can be marked with +/- |
27
+ | **Association** | Represents an unspecified relationship, or one that is not represented by another ArchiMate relationship. |
28
+
29
+ ### Dynamic Relationships
30
+
31
+ | Relationship | Description |
32
+ |--------------|-------------|
33
+ | **Triggering** | Represents a temporal or causal relationship between elements. |
34
+ | **Flow** | Represents transfer from one element to another. |
35
+
36
+ ### Other Relationships
37
+
38
+ | Relationship | Description |
39
+ |--------------|-------------|
40
+ | **Specialization** | Represents that an element is a particular kind of another element. |
41
+
42
+ ### Relationship Connectors
43
+
44
+ | Connector | Description |
45
+ |-----------|-------------|
46
+ | **Junction (And)** | Used to connect relationships of the same type with AND logic. |
47
+ | **Junction (Or)** | Used to connect relationships of the same type with OR logic. |
48
+
49
+ ## Motivation Elements
50
+
51
+ | Element | Definition |
52
+ |---------|------------|
53
+ | **Stakeholder** | The role of an individual, team, or organization (or classes thereof) that represents their interests in the effects of the architecture. |
54
+ | **Driver** | An external or internal condition that motivates an organization to define its goals and implement the changes necessary to achieve them. |
55
+ | **Assessment** | The result of an analysis of the state of affairs of the enterprise with respect to some driver. |
56
+ | **Goal** | A high-level statement of intent, direction, or desired end state for an organization and its stakeholders. |
57
+ | **Outcome** | An end result, effect, or consequence of a certain state of affairs. |
58
+ | **Principle** | A statement of intent defining a general property that applies to any system in a certain context in the architecture. |
59
+ | **Requirement** | A statement of need defining a property that applies to a specific system as described by the architecture. |
60
+ | **Constraint** | A limitation on aspects of the architecture, its implementation process, or its realization. |
61
+ | **Meaning** | The knowledge or expertise present in, or the interpretation given to, a concept in a particular context. |
62
+ | **Value** | The relative worth, utility, or importance of a concept. |
63
+
64
+ ## Strategy Layer Elements
65
+
66
+ | Element | Definition |
67
+ |---------|------------|
68
+ | **Resource** | An asset owned or controlled by an individual or organization. |
69
+ | **Capability** | An ability that an active structure element, such as an organization, person, or system, possesses. |
70
+ | **Value Stream** | A sequence of activities that create an overall result for a customer, stakeholder, or end user. |
71
+ | **Course of Action** | An approach or plan for configuring some capabilities and resources of the enterprise, undertaken to achieve a goal. |
72
+
73
+ ## Business Layer Elements
74
+
75
+ ### Active Structure Elements
76
+
77
+ | Element | Definition |
78
+ |---------|------------|
79
+ | **Business Actor** | A business entity that is capable of performing behavior. |
80
+ | **Business Role** | The responsibility for performing specific behavior, to which an actor can be assigned, or the part an actor plays in a particular action or event. |
81
+ | **Business Collaboration** | An aggregate of two or more business internal active structure elements that work together to perform collective behavior. |
82
+ | **Business Interface** | A point of access where a business service is made available to the environment. |
83
+
84
+ ### Behavior Elements
85
+
86
+ | Element | Definition |
87
+ |---------|------------|
88
+ | **Business Process** | A sequence of business behaviors that achieves a specific result such as a defined set of products or business services. |
89
+ | **Business Function** | A collection of business behavior based on a chosen set of criteria (typically required business resources and/or competencies), closely aligned to an organization. |
90
+ | **Business Interaction** | A unit of collective business behavior performed by (a collaboration of) two or more business actors, business roles, or business collaborations. |
91
+ | **Business Event** | A business-related state change. |
92
+ | **Business Service** | Explicitly defined behavior that a business role, business actor, or business collaboration exposes to its environment. |
93
+
94
+ ### Passive Structure Elements
95
+
96
+ | Element | Definition |
97
+ |---------|------------|
98
+ | **Business Object** | A concept used within a particular business domain. |
99
+ | **Contract** | A formal or informal specification of an agreement between a provider and a consumer that specifies rights and obligations. |
100
+ | **Representation** | A perceptible form of the information carried by a business object. |
101
+ | **Product** | A coherent collection of services and/or passive structure elements, accompanied by a contract, offered to customers. |
102
+
103
+ ## Application Layer Elements
104
+
105
+ ### Active Structure Elements
106
+
107
+ | Element | Definition |
108
+ |---------|------------|
109
+ | **Application Component** | An encapsulation of application functionality aligned to implementation structure, which is modular and replaceable. |
110
+ | **Application Collaboration** | An aggregate of two or more application internal active structure elements that work together to perform collective behavior. |
111
+ | **Application Interface** | A point of access where application services are made available to a user, another application component, or a node. |
112
+
113
+ ### Behavior Elements
114
+
115
+ | Element | Definition |
116
+ |---------|------------|
117
+ | **Application Function** | Automated behavior that can be performed by an application component. |
118
+ | **Application Interaction** | A unit of collective application behavior performed by (a collaboration of) two or more application components. |
119
+ | **Application Process** | A sequence of application behaviors that achieves a specific result. |
120
+ | **Application Event** | An application state change. |
121
+ | **Application Service** | An explicitly defined exposed application behavior. |
122
+
123
+ ### Passive Structure Elements
124
+
125
+ | Element | Definition |
126
+ |---------|------------|
127
+ | **Data Object** | Data structured for automated processing. |
128
+
129
+ ## Technology Layer Elements
130
+
131
+ ### Active Structure Elements
132
+
133
+ | Element | Definition |
134
+ |---------|------------|
135
+ | **Node** | A computational or physical resource that hosts, manipulates, or interacts with other computational or physical resources. |
136
+ | **Device** | A physical IT resource upon which system software and artifacts may be stored or deployed for execution. |
137
+ | **System Software** | Software that provides or contributes to an environment for storing, executing, and using software or data deployed within it. |
138
+ | **Technology Collaboration** | An aggregate of two or more technology internal active structure elements that work together to perform collective behavior. |
139
+ | **Technology Interface** | A point of access where technology services offered by a technology internal active structure element can be accessed. |
140
+ | **Path** | A link between two or more technology internal active structure elements, through which these elements can exchange data, energy, or material. |
141
+ | **Communication Network** | A set of structures and behaviors that connects devices or system software for transmission, routing, and reception of data. |
142
+
143
+ ### Behavior Elements
144
+
145
+ | Element | Definition |
146
+ |---------|------------|
147
+ | **Technology Function** | A collection of technology behavior that can be performed by a technology internal active structure element. |
148
+ | **Technology Process** | A sequence of technology behaviors that achieves a specific result. |
149
+ | **Technology Interaction** | A unit of collective technology behavior performed by (a collaboration of) two or more technology internal active structure elements. |
150
+ | **Technology Event** | A technology state change. |
151
+ | **Technology Service** | An explicitly defined exposed technology behavior. |
152
+
153
+ ### Passive Structure Elements
154
+
155
+ | Element | Definition |
156
+ |---------|------------|
157
+ | **Artifact** | A piece of data that is used or produced in a software development process, or by deployment and operation of an IT system. |
158
+
159
+ ## Physical Elements
160
+
161
+ | Element | Definition |
162
+ |---------|------------|
163
+ | **Equipment** | One or more physical machines, tools, or instruments that can create, use, store, move, or transform materials. |
164
+ | **Facility** | A physical structure or environment. |
165
+ | **Distribution Network** | A physical network used to transport materials or energy. |
166
+ | **Material** | Tangible physical matter or energy. |
167
+
168
+ ## Implementation and Migration Layer Elements
169
+
170
+ | Element | Definition |
171
+ |---------|------------|
172
+ | **Work Package** | A series of actions identified and designed to achieve specific results within specified time and resource constraints. |
173
+ | **Deliverable** | A precisely defined result of a work package. |
174
+ | **Implementation Event** | A state change related to implementation or migration. |
175
+ | **Plateau** | A relatively stable state of the architecture that exists during a limited period of time. |
176
+ | **Gap** | A statement of difference between two plateaus. |
177
+
178
+ ## Composite Elements
179
+
180
+ | Element | Definition |
181
+ |---------|------------|
182
+ | **Grouping** | Aggregates or composes concepts that belong together based on some common characteristic. |
183
+ | **Location** | A conceptual or physical place or position where concepts are located (structure elements) or performed (behavior elements). |
184
+
185
+ ## ArchiMate Layers
186
+
187
+ ArchiMate organizes elements into distinct layers:
188
+
189
+ 1. **Motivation Layer** - Why: stakeholders, drivers, goals, requirements
190
+ 2. **Strategy Layer** - What: capabilities, resources, value streams, courses of action
191
+ 3. **Business Layer** - What: business processes, actors, services, objects
192
+ 4. **Application Layer** - How: application components, services, data objects
193
+ 5. **Technology Layer** - How: infrastructure, nodes, devices, networks
194
+ 6. **Physical Layer** - Where: facilities, equipment, materials, distribution networks
195
+ 7. **Implementation & Migration Layer** - When: work packages, plateaus, gaps
196
+
197
+ ## Key Concepts
198
+
199
+ ### Active vs Passive Structure
200
+
201
+ - **Active Structure**: Elements that can perform behavior (actors, roles, components, nodes)
202
+ - **Passive Structure**: Elements that are acted upon (objects, artifacts, data)
203
+
204
+ ### Internal vs External Behavior
205
+
206
+ - **Internal Behavior**: Functions, processes, interactions
207
+ - **External Behavior**: Services (exposed functionality)
208
+
209
+ ### Events
210
+
211
+ State changes that trigger or are triggered by behavior (business events, application events, technology events)
212
+
213
+ ## References
214
+
215
+ - ArchiMate® 3.2 Specification Copyright © 2022 The Open Group
@@ -0,0 +1,316 @@
1
+ # Computed Annotations
2
+
3
+ Computed annotations are dynamic values calculated from related resources at database load time. Unlike regular annotations that are stored in YAML files, computed annotations are derived from the data of related resources in the resource graph.
4
+
5
+ ## Overview
6
+
7
+ Computed annotations allow you to:
8
+
9
+ - **Aggregate data** from related resources (sum, count, average, etc.)
10
+ - **Collect information** across the resource tree (unique languages, all tags, etc.)
11
+ - **Compute derived metrics** (risk scores, costs, coverage percentages)
12
+
13
+ They are computed after all resources are loaded and relations are resolved, making the full resource graph available for computation.
14
+
15
+ ## Defining Computed Annotations
16
+
17
+ Computed annotations are defined in resource classes using the `computed_annotation` DSL:
18
+
19
+ ```ruby
20
+ class ApplicationComponent < Base
21
+ computed_annotation 'computed/artifact_count',
22
+ title: 'Artifact Count',
23
+ description: 'Number of related technology artifacts' do
24
+ count(outgoing_transitive(:TechnologyArtifact))
25
+ end
26
+ end
27
+ ```
28
+
29
+ ### DSL Options
30
+
31
+ Computed annotations support all the same options as regular annotations:
32
+
33
+ | Option | Type | Default | Description |
34
+ |--------|------|---------|-------------|
35
+ | `key` | String | required | The annotation key (first argument) |
36
+ | `description` | String | nil | Human-readable description |
37
+ | `title` | String | nil | Display title for UI |
38
+ | `filter` | Symbol | nil | Filter type (`:word`, `:list`) |
39
+ | `format` | Symbol | nil | Rendering format (`:markdown`, `:tag_word`, `:tag_list`) |
40
+ | `enum` | Array | nil | Allowed values |
41
+ | `sidebar` | Boolean | false | Show in sidebar |
42
+ | `type` | Class | nil | Type for value coercion (Integer, Float, String) |
43
+ | `list` | Boolean | false | Whether values are lists |
44
+ | `&block` | Block | required | The computation logic |
45
+
46
+ ### Value Handling
47
+
48
+ - **Nil values**: Not stored (annotation key won't exist)
49
+ - **Empty arrays**: Not stored (annotation key won't exist)
50
+ - **Arrays**: Converted to comma-separated strings for storage
51
+ - **Other values**: Stored as-is (with optional type coercion)
52
+
53
+ ### Example Definitions
54
+
55
+ ```ruby
56
+ # Count related resources
57
+ computed_annotation 'computed/artifact_count',
58
+ title: 'Artifact Count',
59
+ description: 'Number of related technology artifacts' do
60
+ count(outgoing_transitive(:TechnologyArtifact))
61
+ end
62
+
63
+ # Sum numeric values with type coercion
64
+ computed_annotation 'computed/total_cost',
65
+ title: 'Total Cost',
66
+ description: 'Total estimated cost',
67
+ type: Integer do
68
+ sum(outgoing_transitive(:TechnologyArtifact), 'scc/estimatedCost')
69
+ end
70
+
71
+ # Find primary language (by LOC)
72
+ computed_annotation 'computed/primary_language',
73
+ title: 'Primary Language',
74
+ description: 'Programming language with most lines of code',
75
+ filter: :word do
76
+ artifacts = outgoing_transitive(:TechnologyArtifact)
77
+ loc_by_language = Hash.new(0)
78
+ artifacts.each do |artifact|
79
+ artifact.annotations.each do |key, value|
80
+ if key =~ %r{^scc/language/(.+)/loc$}
81
+ loc_by_language[Regexp.last_match(1)] += value.to_i
82
+ end
83
+ end
84
+ end
85
+ loc_by_language.max_by { |_, loc| loc }&.first
86
+ end
87
+
88
+ # Collect unique values (stored as comma-separated string)
89
+ computed_annotation 'computed/languages',
90
+ title: 'Languages',
91
+ description: 'All programming languages used',
92
+ filter: :list,
93
+ list: true do
94
+ collect(outgoing_transitive(:TechnologyArtifact), 'scc/languages')
95
+ end
96
+ ```
97
+
98
+ ## Relation Traversal Methods
99
+
100
+ Inside the computation block, you have access to relation traversal methods:
101
+
102
+ | Method | Query Equivalent | Description |
103
+ |--------|------------------|-------------|
104
+ | `outgoing(Kind)` | `-> Kind` | Direct outgoing relations to specified kind |
105
+ | `outgoing_transitive(Kind)` | `~> Kind` | All transitively reachable resources of kind |
106
+ | `incoming(Kind)` | `<- Kind` | Direct incoming relations from specified kind |
107
+ | `incoming_transitive(Kind)` | `<~ Kind` | All resources that transitively reference this one |
108
+
109
+ ### Filter Parameter
110
+
111
+ All relation methods accept either:
112
+ - **Symbol**: Simple kind filter (e.g., `:TechnologyArtifact`)
113
+ - **String**: Full query selector using the query language (e.g., `'TechnologyArtifact: activity/status == "active"'`)
114
+
115
+ ### Examples
116
+
117
+ ```ruby
118
+ # Direct relations only
119
+ outgoing(:TechnologyArtifact) # Resources directly related
120
+
121
+ # Transitive relations (follows relation chains)
122
+ outgoing_transitive(:TechnologyArtifact) # All reachable artifacts
123
+
124
+ # Incoming relations
125
+ incoming(:ApplicationService) # Services that reference this component
126
+
127
+ # With depth limit
128
+ outgoing_transitive(:TechnologyArtifact, max_depth: 5)
129
+
130
+ # Query selector - filter by annotation value
131
+ outgoing_transitive('TechnologyArtifact: activity/status == "active"')
132
+
133
+ # Query selector - filter by numeric comparison
134
+ outgoing('TechnologyArtifact: scc/estimatedCost > 10000')
135
+
136
+ # Query selector - filter by name pattern
137
+ outgoing_transitive('TechnologyArtifact: name =~ "repo-go"')
138
+
139
+ # Query selector - kind filter only
140
+ incoming_transitive('ApplicationService:')
141
+ ```
142
+
143
+ ## Aggregation Functions
144
+
145
+ The following aggregation functions are available:
146
+
147
+ ### Numeric Aggregations
148
+
149
+ | Function | Description | Returns |
150
+ |----------|-------------|---------|
151
+ | `sum(instances, key)` | Sum of numeric annotation values | Float or nil |
152
+ | `avg(instances, key)` | Average of numeric values | Float or nil |
153
+ | `min(instances, key)` | Minimum numeric value | Float or nil |
154
+ | `max(instances, key)` | Maximum numeric value | Float or nil |
155
+
156
+ ### Counting
157
+
158
+ | Function | Description | Returns |
159
+ |----------|-------------|---------|
160
+ | `count(instances)` | Count of instances | Integer |
161
+ | `count(instances, key)` | Count of non-nil annotation values | Integer |
162
+
163
+ ### Collection
164
+
165
+ | Function | Description | Returns |
166
+ |----------|-------------|---------|
167
+ | `collect(instances, key)` | Unique sorted values | Array |
168
+ | `first(instances, key)` | First non-nil value | Any or nil |
169
+ | `most_common(instances, key)` | Most frequent value (mode) | Any or nil |
170
+
171
+ ### Usage Examples
172
+
173
+ ```ruby
174
+ # Sum estimated costs
175
+ sum(outgoing_transitive(:TechnologyArtifact), 'scc/estimatedCost')
176
+
177
+ # Count artifacts with specific status
178
+ count(outgoing_transitive(:TechnologyArtifact), 'activity/status')
179
+
180
+ # Average lines of code
181
+ avg(outgoing_transitive(:TechnologyArtifact), 'scc/loc')
182
+
183
+ # Get all unique languages
184
+ collect(outgoing_transitive(:TechnologyArtifact), 'scc/languages')
185
+
186
+ # Find primary language
187
+ most_common(outgoing_transitive(:TechnologyArtifact), 'scc/languages')
188
+ ```
189
+
190
+ ## Accessing Other Annotations
191
+
192
+ Inside the computation block, you can access:
193
+
194
+ ### Regular Annotations
195
+
196
+ ```ruby
197
+ computed_annotation 'computed/risk_adjusted_cost' do
198
+ base_cost = sum(outgoing_transitive(:TechnologyArtifact), 'scc/estimatedCost')
199
+ risk_factor = annotation('risk/factor')&.to_f || 1.0
200
+ base_cost * risk_factor if base_cost
201
+ end
202
+ ```
203
+
204
+ ### Other Computed Annotations
205
+
206
+ ```ruby
207
+ computed_annotation 'computed/cost_per_artifact' do
208
+ total = computed('computed/total_cost')
209
+ count = computed('computed/artifact_count')
210
+ total / count if total && count && count > 0
211
+ end
212
+ ```
213
+
214
+ ## Execution Order
215
+
216
+ 1. Database loads all YAML resources
217
+ 2. Relations are verified and resolved
218
+ 3. Computed annotations are calculated for all instances
219
+ 4. Values are cached for performance
220
+
221
+ Computed annotations that depend on other computed annotations are resolved automatically through lazy evaluation with cycle detection.
222
+
223
+ ## Querying Computed Values
224
+
225
+ Computed annotations are written to the instance's annotation hash, making them queryable like regular annotations:
226
+
227
+ ```ruby
228
+ # Using the query language
229
+ db.query('ApplicationComponent: computed/artifact_count > 10')
230
+
231
+ # Direct access
232
+ instance.annotations['computed/artifact_count']
233
+
234
+ # Via the dedicated method
235
+ instance.computed_annotation_value('computed/artifact_count')
236
+ ```
237
+
238
+ ## Best Practices
239
+
240
+ ### Naming Convention
241
+
242
+ Use the `computed/` prefix for computed annotation keys to distinguish them from stored annotations:
243
+
244
+ ```ruby
245
+ computed_annotation 'computed/total_cost' do
246
+ # ...
247
+ end
248
+ ```
249
+
250
+ ### Performance Considerations
251
+
252
+ - Computed values are cached after first calculation
253
+ - Avoid deep transitive traversals when possible (use `max_depth`)
254
+ - Consider the number of related resources when designing aggregations
255
+
256
+ ### Error Handling
257
+
258
+ - Aggregation functions handle nil values gracefully
259
+ - Empty result sets return nil for most aggregations
260
+ - Circular dependencies are detected and raise an error
261
+
262
+ ## Complete Example
263
+
264
+ ```ruby
265
+ class ApplicationComponent < Base
266
+ # Count related artifacts
267
+ computed_annotation 'computed/artifact_count',
268
+ title: 'Artifact Count',
269
+ description: 'Number of related technology artifacts' do
270
+ count(outgoing_transitive(:TechnologyArtifact))
271
+ end
272
+
273
+ # Sum costs with type coercion
274
+ computed_annotation 'computed/total_cost',
275
+ title: 'Total Cost',
276
+ description: 'Total estimated cost from related artifacts',
277
+ type: Integer do
278
+ sum(outgoing_transitive(:TechnologyArtifact), 'scc/estimatedCost')
279
+ end
280
+
281
+ # Find primary language by LOC
282
+ computed_annotation 'computed/primary_language',
283
+ title: 'Primary Language',
284
+ description: 'Programming language with most lines of code',
285
+ filter: :word do
286
+ artifacts = outgoing_transitive(:TechnologyArtifact)
287
+ loc_by_language = Hash.new(0)
288
+ artifacts.each do |artifact|
289
+ artifact.annotations.each do |key, value|
290
+ if key =~ %r{^scc/language/(.+)/loc$}
291
+ loc_by_language[Regexp.last_match(1)] += value.to_i
292
+ end
293
+ end
294
+ end
295
+ loc_by_language.max_by { |_, loc| loc }&.first
296
+ end
297
+
298
+ # Collect all languages (stored as comma-separated string)
299
+ computed_annotation 'computed/languages',
300
+ title: 'Languages',
301
+ description: 'All programming languages used across related artifacts',
302
+ filter: :list,
303
+ list: true do
304
+ collect(outgoing_transitive(:TechnologyArtifact), 'scc/languages')
305
+ end
306
+
307
+ # Derived computation using other computed values
308
+ computed_annotation 'computed/avg_cost_per_artifact',
309
+ title: 'Avg Cost per Artifact',
310
+ description: 'Average cost per artifact' do
311
+ total = computed('computed/total_cost')
312
+ count = computed('computed/artifact_count')
313
+ (total.to_f / count).round(2) if total && count && count > 0
314
+ end
315
+ end
316
+ ```