archunit 1.0.0 → 1.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.
- checksums.yaml +4 -4
- data/API.md +213 -5
- data/CHANGELOG.md +41 -1
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +75 -0
- data/GUIDE.md +804 -0
- data/README.md +198 -562
- data/SECURITY.md +64 -0
- data/SUPPORT.md +23 -0
- data/exe/archunit +7 -0
- data/lib/archunit/cli/analysis_report.rb +62 -0
- data/lib/archunit/cli/analysis_text.rb +25 -0
- data/lib/archunit/cli/baseline_context.rb +42 -0
- data/lib/archunit/cli/baseline_document.rb +58 -0
- data/lib/archunit/cli/baseline_fingerprint.rb +36 -0
- data/lib/archunit/cli/baseline_identity.rb +85 -0
- data/lib/archunit/cli/baseline_ledger.rb +38 -0
- data/lib/archunit/cli/baseline_object.rb +15 -0
- data/lib/archunit/cli/baseline_options.rb +48 -0
- data/lib/archunit/cli/baseline_run.rb +85 -0
- data/lib/archunit/cli/baseline_schema.rb +53 -0
- data/lib/archunit/cli/baseline_text.rb +31 -0
- data/lib/archunit/cli/configuration.rb +93 -0
- data/lib/archunit/cli/options.rb +117 -0
- data/lib/archunit/cli/report.rb +121 -0
- data/lib/archunit/cli/runner.rb +108 -0
- data/lib/archunit/cli.rb +15 -0
- data/lib/archunit/common/extraction/import_kind.rb +3 -1
- data/lib/archunit/common/extraction/source_exclusions.rb +43 -0
- data/lib/archunit/common/fluentapi/check_options.rb +13 -3
- data/lib/archunit/extraction/analysis_observer.rb +24 -0
- data/lib/archunit/extraction/analysis_profile.rb +30 -0
- data/lib/archunit/extraction/analysis_snapshot.rb +51 -0
- data/lib/archunit/extraction/constant_visitor.rb +8 -0
- data/lib/archunit/extraction/dependency_context.rb +30 -0
- data/lib/archunit/extraction/enumerate_source_files.rb +17 -5
- data/lib/archunit/extraction/extract_dependencies.rb +5 -14
- data/lib/archunit/extraction/extract_graph.rb +45 -55
- data/lib/archunit/extraction/extract_imports.rb +11 -14
- data/lib/archunit/extraction/graph_assembly.rb +32 -0
- data/lib/archunit/extraction/graph_cache_key.rb +27 -0
- data/lib/archunit/extraction/import_calls.rb +93 -0
- data/lib/archunit/extraction/import_resolver.rb +11 -2
- data/lib/archunit/extraction/import_source_policy.rb +123 -0
- data/lib/archunit/extraction/import_visitor.rb +31 -46
- data/lib/archunit/extraction/load_arguments.rb +34 -0
- data/lib/archunit/extraction/local_string_tracker.rb +4 -3
- data/lib/archunit/extraction/resolve_load_paths.rb +5 -0
- data/lib/archunit/extraction/source_analysis.rb +26 -0
- data/lib/archunit/extraction/static_import_path.rb +111 -0
- data/lib/archunit/layers/fluentapi/architecture_preset.rb +49 -0
- data/lib/archunit/layers/fluentapi/preset_definitions.rb +39 -0
- data/lib/archunit/layers/fluentapi/preset_options.rb +69 -0
- data/lib/archunit/layers/fluentapi/preset_rule.rb +45 -0
- data/lib/archunit/metrics/extraction/extract_distance_info.rb +1 -1
- data/lib/archunit/metrics/extraction/extract_project_info.rb +8 -4
- data/lib/archunit/metrics/fluentapi/metric_report_builder.rb +4 -3
- data/lib/archunit/metrics/fluentapi/metrics_builder.rb +3 -3
- data/lib/archunit/metrics/reporting/metrics_export_options.rb +6 -2
- data/lib/archunit/version.rb +1 -1
- data/lib/archunit.rb +2 -0
- metadata +48 -8
data/README.md
CHANGED
|
@@ -1,674 +1,310 @@
|
|
|
1
|
-
# ArchUnitRuby
|
|
1
|
+
# ArchUnitRuby
|
|
2
2
|
|
|
3
|
-
<p align="center"
|
|
4
|
-
<img src="assets/logo-rounded.png" width="
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="assets/logo-rounded.png" width="160" alt="ArchUnitRuby">
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<a href="
|
|
9
|
-
<a href="https://
|
|
10
|
-
<a href="https://github.com/LukasNiessen/ArchUnitRuby"><img alt="GitHub stars" src="https://img.shields.io/github/stars/LukasNiessen/ArchUnitRuby.svg"></a><br>
|
|
8
|
+
<a href="https://github.com/dragonsec-ai/ArchUnitRuby/actions/workflows/ci.yml"><img alt="Build and tests" src="https://img.shields.io/github/actions/workflow/status/dragonsec-ai/ArchUnitRuby/ci.yml?branch=main&label=build%20%26%20tests"></a>
|
|
9
|
+
<a href="https://rubygems.org/gems/archunit"><img alt="RubyGems version" src="https://img.shields.io/gem/v/archunit.svg"></a>
|
|
11
10
|
<a href="https://clickgems.clickhouse.com/dashboard/archunit"><img alt="Gem downloads" src="https://img.shields.io/gem/dt/archunit.svg"></a>
|
|
12
|
-
<a href="
|
|
11
|
+
<a href="LICENSE"><img alt="MIT license" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
|
12
|
+
<img alt="Ruby 3.3 or newer" src="https://img.shields.io/badge/Ruby-3.3%2B-CC342D?logo=ruby&logoColor=white">
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
**Architecture rules for Ruby, enforced in your tests.**
|
|
16
|
+
|
|
17
|
+
Keep dependency boundaries explicit, catch cycles, enforce conventions, measure code quality,
|
|
18
|
+
and generate architecture diagrams—with readable rules in RSpec, Minitest, or plain Ruby.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
~~~ruby
|
|
21
|
+
ArchUnit.project_files.in_folder('app/api/**')
|
|
22
|
+
.should_not.depend_on_files.in_folder('app/database/**')
|
|
23
|
+
.because('Keep persistence behind the service boundary')
|
|
24
|
+
~~~
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
ArchUnitRuby analyzes source with Prism without booting your application. It is the Ruby member
|
|
27
|
+
of the [ArchUnitEverything family](#community), inspired by—but not affiliated with—ArchUnit.
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
[Quickstart](#quickstart) · [Capabilities](#capabilities) · [User guide](GUIDE.md) ·
|
|
30
|
+
[API contract](API.md) · [Documentation site](https://dragonsec-ai.github.io/ArchUnitRuby/) ·
|
|
31
|
+
[Example project](#example-project) · [Limitations](#limitations)
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
ArchUnit.project_files
|
|
28
|
-
.in_folder('app/api/**')
|
|
29
|
-
.should_not.depend_on_files
|
|
30
|
-
.in_folder('app/database/**')
|
|
31
|
-
~~~
|
|
33
|
+
<a id="availability"></a>
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
compatibility baseline. It is tested on Ruby 3.3, 3.4, and 4.0 on Linux and Ruby 4.0 on Windows.
|
|
35
|
-
The gem is named [`archunit`](https://rubygems.org/gems/archunit); check RubyGems for published-version
|
|
36
|
-
availability, since a development checkout can be ahead of the published gem.
|
|
35
|
+
## Release status
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
| Version | Capabilities |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `1.0` | Fluent file/layer/slice rules, cycles and naming, metrics, graph/diagram exports, RSpec/Minitest integrations, opt-in constant-file analysis |
|
|
40
|
+
| `1.1` | Everything in 1.0, plus CLI, analysis diagnostics, accepted-debt baselines, architecture presets, Rails helper imports, caller-owned source exclusions, and further extraction fixes |
|
|
41
|
+
|
|
42
|
+
This guide and its installation example target the **1.1 series**. Check
|
|
43
|
+
[RubyGems](https://rubygems.org/gems/archunit) for published versions; the documentation site
|
|
44
|
+
follows `main` and can be ahead of the registry during release preparation.
|
|
45
|
+
Installing 1.0.0 does not provide the CLI or other 1.1 additions. See the
|
|
46
|
+
[changelog](CHANGELOG.md) and [1.x compatibility contract](API.md#compatibility) before upgrading.
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
curated [API guide](https://lukasniessen.github.io/ArchUnitRuby/file.API.html), and a searchable,
|
|
44
|
-
source-generated reference. The same site is rebuilt and link-validated in CI before deployment
|
|
45
|
-
from `main`, so the published reference follows the repository.
|
|
48
|
+
<a id="quickstart"></a>
|
|
46
49
|
|
|
47
|
-
##
|
|
50
|
+
## Quickstart
|
|
48
51
|
|
|
49
|
-
###
|
|
52
|
+
### 1. Install
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
test dependencies once the target version is published:
|
|
54
|
+
Ruby 3.3+ is required. Add ArchUnitRuby to your test dependencies:
|
|
53
55
|
|
|
54
|
-
~~~
|
|
56
|
+
~~~ruby
|
|
55
57
|
# Gemfile
|
|
56
58
|
group :test do
|
|
57
|
-
gem 'archunit', '~> 1.
|
|
59
|
+
gem 'archunit', '~> 1.1.0'
|
|
60
|
+
gem 'rspec' # Omit this line if RSpec is already in your bundle.
|
|
58
61
|
end
|
|
59
62
|
~~~
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
~~~ bash
|
|
64
|
+
~~~sh
|
|
64
65
|
bundle install
|
|
65
66
|
~~~
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
RSpec and Minitest are optional integrations, not runtime dependencies of the gem.
|
|
69
|
+
Already using Minitest? Keep your existing setup and use `assert_passes(rule)`.
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
date, gem version, Ruby version, system, and country. Download totals count package fetches rather
|
|
71
|
-
than unique users, so repeated installs and automated clients may contribute to the total. The
|
|
72
|
-
[RubyGems API](https://rubygems.org/api/v1/gems/archunit.json) provides the
|
|
73
|
-
current raw count and ClickGems provides the historical breakdown.
|
|
71
|
+
### 2. Write your first architecture test
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
for you.
|
|
73
|
+
For this example, use two ordinary source files:
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
~~~text
|
|
76
|
+
app/
|
|
77
|
+
api/request.rb # class Request; end
|
|
78
|
+
database/store.rb # class Store; end
|
|
79
|
+
spec/
|
|
80
|
+
architecture_spec.rb
|
|
81
|
+
~~~
|
|
79
82
|
|
|
80
|
-
Create `spec/architecture_spec.rb
|
|
83
|
+
Create `spec/architecture_spec.rb`. Change the folder patterns to match your project.
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
<!-- example:quickstart-spec -->
|
|
86
|
+
~~~ruby
|
|
83
87
|
require 'archunit'
|
|
84
88
|
|
|
85
|
-
RSpec.describe '
|
|
89
|
+
RSpec.describe 'Architecture' do
|
|
86
90
|
it 'keeps the API away from the database' do
|
|
87
91
|
rule = ArchUnit.project_files.in_folder('app/api/**')
|
|
88
92
|
.should_not.depend_on_files.in_folder('app/database/**')
|
|
93
|
+
.because('Keep persistence behind the service boundary')
|
|
89
94
|
|
|
90
95
|
expect(rule).to pass
|
|
91
96
|
end
|
|
92
97
|
end
|
|
93
98
|
~~~
|
|
94
99
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
~~~ bash
|
|
100
|
+
~~~sh
|
|
98
101
|
bundle exec rspec spec/architecture_spec.rb
|
|
99
102
|
~~~
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Architecture specifications run with the rest of the test suite, so no dedicated CI integration
|
|
104
|
-
is required:
|
|
105
|
-
|
|
106
|
-
~~~ yaml
|
|
107
|
-
# GitHub Actions
|
|
108
|
-
- name: Run architecture tests
|
|
109
|
-
run: bundle exec rspec spec/architecture_spec.rb
|
|
110
|
-
~~~
|
|
111
|
-
|
|
112
|
-
## 🚐 Setup
|
|
113
|
-
|
|
114
|
-
### Explain why a rule exists
|
|
104
|
+
No special CI service is required: run architecture specifications with your normal tests.
|
|
115
105
|
|
|
116
|
-
|
|
106
|
+
### 3. See it catch a dependency
|
|
117
107
|
|
|
118
|
-
|
|
119
|
-
rule = ArchUnit.project_files.in_folder('app/api/**')
|
|
120
|
-
.should_not.depend_on_files.in_folder('app/database/**')
|
|
121
|
-
.because('Keep persistence out of the API')
|
|
108
|
+
Add this line to `app/api/request.rb` and rerun the test:
|
|
122
109
|
|
|
123
|
-
|
|
110
|
+
~~~ruby
|
|
111
|
+
require_relative '../database/store'
|
|
124
112
|
~~~
|
|
125
113
|
|
|
126
|
-
The
|
|
127
|
-
It is available as `rule.rationale`. Calling `.because(...)` returns a distinct frozen rule;
|
|
128
|
-
the original rule and direct `check` results are unchanged. Reasons must be non-blank strings.
|
|
129
|
-
Add the explanation after all selectors and modifiers.
|
|
114
|
+
The test fails with concrete file evidence:
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for a `Gemfile` or gemspec. Pass a directory or either marker file when analyzing another project:
|
|
135
|
-
|
|
136
|
-
~~~ ruby
|
|
137
|
-
ArchUnit.project_files('/workspace/my_app')
|
|
138
|
-
ArchUnit.project_files('/workspace/my_app/Gemfile')
|
|
139
|
-
~~~
|
|
140
|
-
|
|
141
|
-
Source discovery skips symlinked files and directories, including project-local aliases. This
|
|
142
|
-
avoids duplicate file identities and unintentionally parsing linked source outside the project.
|
|
143
|
-
Direct file-information extraction also checks the canonical source path against the project root.
|
|
144
|
-
|
|
145
|
-
### Project-wide exclusions
|
|
146
|
-
|
|
147
|
-
Add a `.archignore` at the detected project root to keep generated or intentionally out-of-scope
|
|
148
|
-
Ruby files out of dependency graphs and file-based metrics:
|
|
149
|
-
|
|
150
|
-
~~~ text
|
|
151
|
-
# Architecture exclusions (not a full gitignore parser)
|
|
152
|
-
/db/migrate/
|
|
153
|
-
generated/
|
|
154
|
-
**/*_generated.rb
|
|
116
|
+
~~~text
|
|
117
|
+
File dependency violation
|
|
118
|
+
File 'app/api/request.rb' depends on forbidden file 'app/database/store.rb'.
|
|
155
119
|
~~~
|
|
156
120
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
separators are normalized. Only the root file is read; nested `.archignore` files are not inherited.
|
|
121
|
+
Remove that dependency in this small fixture to return to green. In an application, refactor
|
|
122
|
+
the interaction through your intended service boundary instead of merely suppressing the test.
|
|
123
|
+
In a long-lived process, clear the graph cache after source edits; separate RSpec runs start fresh.
|
|
161
124
|
|
|
162
|
-
|
|
163
|
-
the defaults, not `.archignore`. Effective pattern changes automatically select a fresh cached graph.
|
|
164
|
-
Source-code edits still require `clear_cache: true` in a long-lived process. The file is limited to
|
|
165
|
-
1 MiB, must be a regular non-symlink file, and is decoded as UTF-8 with invalid bytes replaced.
|
|
166
|
-
Negation (`!pattern`), NUL characters, and a bare `/` are rejected with `ArchUnit::UserError`.
|
|
167
|
-
No configuration or application code is executed.
|
|
125
|
+
[Complete workflows](GUIDE.md) · [Watch the recorded demo](https://github.com/user-attachments/assets/9b7305a0-deee-454d-b99e-f8fac63d06ab)
|
|
168
126
|
|
|
169
|
-
|
|
127
|
+
<a id="capabilities"></a>
|
|
170
128
|
|
|
171
|
-
|
|
129
|
+
## What you can enforce and explore
|
|
172
130
|
|
|
173
|
-
|
|
|
131
|
+
| Capability | Public entry point | Details |
|
|
174
132
|
| --- | --- | --- |
|
|
175
|
-
|
|
|
176
|
-
|
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
String patterns are anchored globs. `*` stays inside one path segment, `**` crosses directories,
|
|
193
|
-
and `?` matches one non-separator character. Most selectors also accept regular expressions;
|
|
194
|
-
`defined_by_regex` is the explicit regex form for slices, while `in_file` takes one exact path.
|
|
195
|
-
Paths are project-relative and normalized to `/` separators.
|
|
196
|
-
|
|
197
|
-
A scope matching zero files returns `EmptyTestViolation`; it does not silently pass. Opt out only
|
|
198
|
-
when an empty result is genuinely valid:
|
|
199
|
-
|
|
200
|
-
~~~ ruby
|
|
201
|
-
rule.check(ArchUnit::CheckOptions.new(allow_empty_tests: true))
|
|
202
|
-
~~~
|
|
203
|
-
|
|
204
|
-
## 🐣 Features
|
|
205
|
-
|
|
206
|
-
### File Rules
|
|
207
|
-
|
|
208
|
-
File rules cover cycles, naming, location, internal dependencies, external modules, and custom
|
|
209
|
-
source predicates:
|
|
210
|
-
|
|
211
|
-
~~~ ruby
|
|
212
|
-
rules = [
|
|
213
|
-
ArchUnit.project_files.in_path('lib/**/*.rb').should.have_no_cycles,
|
|
214
|
-
ArchUnit.project_files.in_folder('app/services/**')
|
|
215
|
-
.should.have_name('*_service.rb'),
|
|
216
|
-
ArchUnit.project_files.in_folder('app/domain/**')
|
|
217
|
-
.should_not.depend_on_external_modules.matching('faraday')
|
|
218
|
-
]
|
|
219
|
-
|
|
220
|
-
rules.each { |rule| ArchUnit.assert_passes(rule) }
|
|
221
|
-
~~~
|
|
222
|
-
|
|
223
|
-
A custom predicate receives an immutable `FileInfo` with `path`, `name`, `extension`, `directory`,
|
|
224
|
-
complete `content`, and non-blank `lines_of_code`:
|
|
225
|
-
|
|
226
|
-
~~~ ruby
|
|
227
|
-
rule = ArchUnit.project_files.in_folder('app/services/**')
|
|
228
|
-
.should.adhere_to(
|
|
229
|
-
->(file) { file.lines_of_code < 300 },
|
|
230
|
-
'services must stay below 300 non-blank lines'
|
|
231
|
-
)
|
|
232
|
-
~~~
|
|
233
|
-
|
|
234
|
-
### Layer Dependencies
|
|
235
|
-
|
|
236
|
-
Named layers express an allowlist or blocklist over groups of files:
|
|
237
|
-
|
|
238
|
-
~~~ ruby
|
|
239
|
-
rule = ArchUnit.project_layers
|
|
240
|
-
.layer('api').defined_by('app/api/**/*.rb')
|
|
241
|
-
.layer('services').defined_by('app/services/**/*.rb')
|
|
242
|
-
.layer('database').defined_by('app/database/**/*.rb')
|
|
243
|
-
.where_layer('api').may_only_depend_on_layers('services')
|
|
244
|
-
.where_layer('services').may_only_depend_on_layers('database')
|
|
245
|
-
.where_layer('database').may_only_depend_on_layers
|
|
246
|
-
|
|
247
|
-
expect(rule).to pass
|
|
248
|
-
~~~
|
|
249
|
-
|
|
250
|
-
Dependencies within one layer are always allowed. Edges with an unassigned endpoint are ignored.
|
|
251
|
-
Calling `may_only_depend_on_layers` without targets seals a layer; `may_not_depend_on_layers`
|
|
252
|
-
requires at least one forbidden target.
|
|
253
|
-
|
|
254
|
-
### Architecture Slices and PlantUML
|
|
255
|
-
|
|
256
|
-
Slices group files by one captured path segment and preserve every concrete dependency as evidence:
|
|
257
|
-
|
|
258
|
-
~~~ ruby
|
|
259
|
-
slices = ArchUnit.project_slices.defined_by('lib/my_app/(**)/')
|
|
260
|
-
rule = slices.should_not.contain_dependency('api', 'database')
|
|
261
|
-
|
|
262
|
-
expect(rule).to pass
|
|
263
|
-
~~~
|
|
264
|
-
|
|
265
|
-
`(**)` is the slice capture. `defined_by_regex` uses the first regular-expression capture instead.
|
|
266
|
-
|
|
267
|
-
A checked-in PlantUML component diagram can also be the architecture contract:
|
|
268
|
-
|
|
269
|
-
~~~ ruby
|
|
270
|
-
rule = slices.should
|
|
271
|
-
.ignoring_external_slices
|
|
272
|
-
.adhere_to_diagram_in_file('docs/architecture.puml')
|
|
273
|
-
|
|
274
|
-
expect(rule).to pass
|
|
275
|
-
~~~
|
|
276
|
-
|
|
277
|
-
The supported subset recognizes components, directed dependencies, comments, and `@startuml` /
|
|
278
|
-
`@enduml`. Use `to_plantuml` or `export_as_plantuml(path)` to generate a diagram from the real graph.
|
|
279
|
-
|
|
280
|
-
### Dependency Graph Reports
|
|
281
|
-
|
|
282
|
-
Graph reporting builds one immutable snapshot and renders it consistently as DOT, Mermaid, D2, CSV,
|
|
283
|
-
JSON, or self-contained HTML:
|
|
284
|
-
|
|
285
|
-
~~~ ruby
|
|
286
|
-
report = ArchUnit.project_graph
|
|
287
|
-
.include_external_dependencies
|
|
288
|
-
.focus_on('app/services/**', 2)
|
|
289
|
-
.collapse_to_folder_depth(2)
|
|
290
|
-
.titled('Service dependencies')
|
|
291
|
-
|
|
292
|
-
puts report.summary.node_count
|
|
293
|
-
report.export_as_html('reports/services.html')
|
|
294
|
-
~~~
|
|
295
|
-
|
|
296
|
-
Queries include `focus_on`, `reachable_from`, and `dependents_of`. Collapse by folder depth or a
|
|
297
|
-
regular-expression replacement. Every format has an in-memory `to_<format>` and an
|
|
298
|
-
`export_as_<format>(path)` terminal.
|
|
299
|
-
|
|
300
|
-
### Code Metrics
|
|
301
|
-
|
|
302
|
-
Metric scopes select files and Ruby classes before measurement or assertion:
|
|
303
|
-
|
|
304
|
-
~~~ ruby
|
|
305
|
-
services = ArchUnit.metrics
|
|
306
|
-
.in_path('app/services/**/*.rb')
|
|
307
|
-
.for_classes_matching('*Service')
|
|
308
|
-
|
|
309
|
-
size_rule = services.count.method_count.should_be_below_or_equal(20)
|
|
310
|
-
cohesion_rule = services.lcom.lcom4.should_be(1)
|
|
311
|
-
distance_rule = services.distance.instability.should_be_below(0.8)
|
|
312
|
-
|
|
313
|
-
[size_rule, cohesion_rule, distance_rule].each { |rule| ArchUnit.assert_passes(rule) }
|
|
314
|
-
~~~
|
|
315
|
-
|
|
316
|
-
Count metrics cover class methods and fields plus file lines, statements, imports, classes, and
|
|
317
|
-
top-level functions. Cohesion includes LCOM96a, LCOM96b, LCOM1-5, and LCOM*. Dependency-derived
|
|
318
|
-
metrics include abstractness, instability, main-sequence distance, coupling factor, and normalized
|
|
319
|
-
distance. Zone guards detect the conventional zones of pain and uselessness.
|
|
320
|
-
|
|
321
|
-
Use `measure` for immutable numeric results, `custom_metric` for a calculation over `ClassInfo`, and
|
|
322
|
-
`export_as_html` for an offline metrics report:
|
|
323
|
-
|
|
324
|
-
~~~ ruby
|
|
325
|
-
services.count.export_as_html('reports/service-counts')
|
|
326
|
-
~~~
|
|
327
|
-
|
|
328
|
-
The threshold vocabulary is intentionally limited to `should_be_below`, `should_be_above`,
|
|
329
|
-
`should_be`, `should_be_below_or_equal`, `should_be_above_or_equal`, and `should_satisfy`.
|
|
133
|
+
| File boundaries, external modules, naming, locations, custom predicates | `project_files` | [File rules](API.md#file-rules) |
|
|
134
|
+
| Directed dependency cycles | `project_files.should.have_no_cycles` | [Rule recipes](GUIDE.md#recipes) |
|
|
135
|
+
| Named-layer allowlists and blocklists | `project_layers` | [Layer rules](API.md#layer-rules) |
|
|
136
|
+
| Component slices and PlantUML conformance | `project_slices` | [Slices and diagrams](API.md#slices) |
|
|
137
|
+
| Mermaid, DOT, D2, JSON, CSV, and offline HTML reports | `project_graph` | [Graph reports](API.md#graph-reports) |
|
|
138
|
+
| Counts, cohesion, coupling, distance, and custom thresholds | `metrics` | [Metrics](API.md#metrics) |
|
|
139
|
+
| Layered, hexagonal, and Rails presets | `architecture_preset` — **1.1+** | [Preset contract](API.md#presets) |
|
|
140
|
+
|
|
141
|
+
Builders are immutable and lazy: assembling a rule does not scan the project. Terminal calls
|
|
142
|
+
such as `check`, `measure`, `snapshot`, and exports perform the work.
|
|
143
|
+
`check` returns structured violations; framework integrations turn them into test failures.
|
|
144
|
+
|
|
145
|
+
| Integration | Assertion |
|
|
146
|
+
| --- | --- |
|
|
147
|
+
| RSpec | `expect(rule).to pass` |
|
|
148
|
+
| Minitest | `assert_passes(rule)` |
|
|
149
|
+
| Plain Ruby | `ArchUnit.assert_passes(rule)` |
|
|
330
150
|
|
|
331
|
-
###
|
|
151
|
+
### More than dependency boundaries
|
|
332
152
|
|
|
333
|
-
|
|
334
|
-
selector's context, including filenames for path and folder selectors:
|
|
153
|
+
A cycle rule:
|
|
335
154
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
)
|
|
155
|
+
<!-- example:cycle-rule -->
|
|
156
|
+
~~~ruby
|
|
157
|
+
rule = ArchUnit.project_files.in_path('app/**/*.rb').should.have_no_cycles
|
|
158
|
+
ArchUnit.assert_passes(rule)
|
|
341
159
|
~~~
|
|
342
160
|
|
|
343
|
-
|
|
344
|
-
`for_classes_matching`:
|
|
161
|
+
An architecture report:
|
|
345
162
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
163
|
+
<!-- example:graph-report -->
|
|
164
|
+
~~~ruby
|
|
165
|
+
report = ArchUnit.project_graph.collapse_to_folder_depth(2).titled('Application dependencies')
|
|
166
|
+
report.export_as_html('reports/architecture.html')
|
|
167
|
+
puts report.to_mermaid
|
|
351
168
|
~~~
|
|
352
169
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
### Results and Test Frameworks
|
|
170
|
+
A metric threshold:
|
|
356
171
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
violations.each { |violation| puts violation.class }
|
|
172
|
+
<!-- example:metric-rule -->
|
|
173
|
+
~~~ruby
|
|
174
|
+
rule = ArchUnit.metrics.in_path('app/services/**/*.rb')
|
|
175
|
+
.count.method_count.should_be_below_or_equal(20)
|
|
176
|
+
ArchUnit.assert_passes(rule)
|
|
363
177
|
~~~
|
|
364
178
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
~~~ ruby
|
|
368
|
-
expect(rule).to pass # RSpec
|
|
369
|
-
assert_passes(rule) # Minitest test case
|
|
370
|
-
ArchUnit.assert_passes(rule) # Framework-neutral
|
|
371
|
-
~~~
|
|
179
|
+
See the [user guide](GUIDE.md#recipes) for layer/slice policies, custom predicates, logging,
|
|
180
|
+
report queries, and complete examples.
|
|
372
181
|
|
|
373
|
-
|
|
374
|
-
violations retain the concrete dependency, file, layer, slice, or metric evidence that caused them.
|
|
182
|
+
<a id="analysis"></a>
|
|
375
183
|
|
|
376
|
-
##
|
|
184
|
+
## Choosing the analysis mode
|
|
377
185
|
|
|
378
|
-
|
|
186
|
+
The default `:imports` mode recognizes supported static `require`, `require_relative`,
|
|
187
|
+
`autoload`, and `load` calls. It does not infer the runtime behavior of Ruby.
|
|
379
188
|
|
|
380
|
-
|
|
381
|
-
logging = ArchUnit::LoggingOptions.new(
|
|
382
|
-
level: :debug,
|
|
383
|
-
output_directory: 'tmp/archunit-logs',
|
|
384
|
-
append: false
|
|
385
|
-
)
|
|
189
|
+
For autoloaded code, explicitly add the supported static constant-reference model:
|
|
386
190
|
|
|
387
|
-
|
|
191
|
+
<!-- example:expanded-options -->
|
|
192
|
+
~~~ruby
|
|
193
|
+
rule = ArchUnit.project_files.in_folder('app/api/**')
|
|
194
|
+
.should_not.depend_on_files.in_folder('app/database/**')
|
|
195
|
+
options = ArchUnit::CheckOptions.new(dependency_analysis: :imports_and_constants)
|
|
196
|
+
violations = rule.check(options)
|
|
388
197
|
~~~
|
|
389
198
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
199
|
+
Expanded analysis maps known project constants to definition files and retains evidence.
|
|
200
|
+
It is still bounded: ambiguous, inherited, or dynamic lookup can remain unresolved.
|
|
201
|
+
[Resolution details](GUIDE.md#analysis) · [Options and caching](API.md#check-options)
|
|
393
202
|
|
|
394
|
-
|
|
395
|
-
its import kind and external flag, selected files, and all metric calculations (including passing
|
|
396
|
-
values). It observes the same graph on both cold and cached checks. Custom metrics run once.
|
|
397
|
-
Check options and returned violations retain their existing behavior.
|
|
203
|
+
<a id="development-cli"></a>
|
|
398
204
|
|
|
399
|
-
|
|
400
|
-
| --- | --- |
|
|
401
|
-
| `:debug` | Graph inspection, selections, metric values, and everything below |
|
|
402
|
-
| `:info` | Check lifecycle and progress, violations, technical errors |
|
|
403
|
-
| `:warn` | Violations and technical errors |
|
|
404
|
-
| `:error` | Technical errors |
|
|
405
|
-
|
|
406
|
-
Example debug lines (timestamp prefixes omitted):
|
|
407
|
-
|
|
408
|
-
~~~ text
|
|
409
|
-
[DEBUG] inspect: discovered file: "lib/service.rb"
|
|
410
|
-
[DEBUG] inspect: dependency: "lib/service.rb" -> "json" (external=true, kinds=[:require])
|
|
411
|
-
[DEBUG] inspect: selected file: "lib/service.rb"
|
|
412
|
-
[DEBUG] log metric: method_count=3 [lib/service.rb:Service]
|
|
413
|
-
~~~
|
|
414
|
-
|
|
415
|
-
For file-only CI artifacts, use `io: nil` with `output_directory:` and archive that directory.
|
|
416
|
-
Logging sink errors still propagate. Debug details are produced lazily; checks with logging
|
|
417
|
-
disabled create no output or log files.
|
|
205
|
+
## CLI and gradual adoption — 1.1+
|
|
418
206
|
|
|
419
|
-
|
|
207
|
+
These commands require ArchUnitRuby 1.1 or newer. They are not available in 1.0.0.
|
|
420
208
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
209
|
+
~~~sh
|
|
210
|
+
bundle exec archunit init
|
|
211
|
+
# Review and customize the generated .archunit.rb before running it.
|
|
212
|
+
bundle exec archunit check
|
|
213
|
+
bundle exec archunit check --format json --dependency-analysis imports_and_constants
|
|
214
|
+
bundle exec archunit explain
|
|
427
215
|
~~~
|
|
428
216
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
## 🕵️ Technical Deep Dive
|
|
434
|
-
|
|
435
|
-
### What ArchUnitRuby Extracts
|
|
436
|
-
|
|
437
|
-
ArchUnitRuby uses Prism and statically recognizes:
|
|
438
|
-
|
|
439
|
-
| Ruby source form | Import kind |
|
|
440
|
-
| --- | --- |
|
|
441
|
-
| `require 'json'` | `:require` |
|
|
442
|
-
| `require_relative '../models/order'` | `:require_relative` |
|
|
443
|
-
| `autoload :Order, 'models/order'` | `:autoload` |
|
|
444
|
-
| `load 'config/setup.rb'` | `:load` |
|
|
445
|
-
|
|
446
|
-
Project dependencies use normalized, project-relative paths. Standard-library and gem dependencies
|
|
447
|
-
retain the module name written in source. Inline or immediately preceding ignore directives can
|
|
448
|
-
suppress known compatibility imports:
|
|
217
|
+
The CLI composes the same rules as your tests. It reports source/uncertainty diagnostics without
|
|
218
|
+
turning unknowns into a semantic-coverage percentage. `explain` lists configuration; it does not
|
|
219
|
+
prove that rules passed.
|
|
449
220
|
|
|
450
|
-
|
|
451
|
-
require 'legacy/client' # archunit: ignore legacy/client
|
|
221
|
+
For gradual adoption, explicitly record reviewed violations:
|
|
452
222
|
|
|
453
|
-
|
|
454
|
-
|
|
223
|
+
~~~sh
|
|
224
|
+
bundle exec archunit baseline --output .archunit-baseline.json
|
|
225
|
+
bundle exec archunit check --baseline .archunit-baseline.json
|
|
455
226
|
~~~
|
|
456
227
|
|
|
457
|
-
|
|
228
|
+
Every rule still runs. New violations and stale entries for fixed debt fail the check.
|
|
229
|
+
An `accepted` result is not a clean `passed` result. Review baseline changes; do not regenerate
|
|
230
|
+
them blindly in CI. Presets compose existing layer rules and retain empty-layer and overlap guards.
|
|
458
231
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
232
|
+
**Trust boundary:** `.archunit.rb` is executable Ruby, including during `explain`. For an untrusted
|
|
233
|
+
repository, use your own trusted `--config` file. The analyzer does not automatically execute
|
|
234
|
+
target source, Gemfiles/gemspecs, tests, or Rails boot; your own Bundler/configuration code still
|
|
235
|
+
has normal Ruby behavior.
|
|
463
236
|
|
|
464
|
-
|
|
465
|
-
value; aliases, mutation, unknown calls receiving the value, reflection, and unsupported control
|
|
466
|
-
flow invalidate it. Values are not carried across branches, loops, exception handlers, or captured
|
|
467
|
-
blocks. Once a closure or reflective binding can access an enclosing scope, local inference remains
|
|
468
|
-
disabled for that scope. Independent literal assignments inside a method or block can still resolve. Runtime values
|
|
469
|
-
such as `ENV.fetch('PLUGIN_PATH')`, interpolation, and method results remain unresolved. No source,
|
|
470
|
-
Gemfile, gemspec, initializer, or `const_missing` hook is executed.
|
|
237
|
+
[CLI contract](API.md#cli) · [Baseline contract](API.md#baselines) · [Presets](GUIDE.md#presets)
|
|
471
238
|
|
|
472
|
-
|
|
239
|
+
<a id="limitations"></a>
|
|
473
240
|
|
|
474
|
-
|
|
241
|
+
## Important boundaries
|
|
475
242
|
|
|
476
|
-
|
|
477
|
-
|
|
243
|
+
- Empty subject selections fail by default; they are usually a typo, not a clean architecture.
|
|
244
|
+
- Malformed included Ruby raises `SourceParseError`. Exclude identified generator templates
|
|
245
|
+
explicitly; a rule selector does not narrow whole-project source discovery.
|
|
246
|
+
- Runtime-derived imports, ambiguous constants, inherited lookup, and metaprogramming can stay
|
|
247
|
+
unresolved. Passing a policy describes the resolved static model—not complete runtime behavior.
|
|
248
|
+
- Whole-project exclusions and rule selectors serve different purposes. Source symlinks are skipped;
|
|
249
|
+
cached graphs require explicit clearing after edits in a long-lived process.
|
|
250
|
+
- Full method-call/signature protocols and semantic component selectors are **not shipped**.
|
|
251
|
+
The [semantic evaluation](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/design/semantic-boundaries.md)
|
|
252
|
+
is a decision record, not feature parity. Dense cycle enumeration can still be expensive.
|
|
478
253
|
|
|
479
|
-
|
|
480
|
-
rule = ArchUnit.project_files
|
|
481
|
-
.in_path('app/api/**')
|
|
482
|
-
.should_not.depend_on_files.in_path('app/retrieval/**')
|
|
483
|
-
violations = rule.check(options)
|
|
254
|
+
[Full analysis contract](GUIDE.md#analysis) · [Errors and troubleshooting](API.md#errors)
|
|
484
255
|
|
|
485
|
-
|
|
486
|
-
puts report.to_json
|
|
487
|
-
puts ArchUnit.project_slices.defined_by('app/(**)/').to_plantuml(options)
|
|
488
|
-
values = ArchUnit.metrics.distance.instability.measure(options)
|
|
489
|
-
~~~
|
|
256
|
+
<a id="example-project"></a>
|
|
490
257
|
|
|
491
|
-
|
|
492
|
-
same included source files, then resolves references to definition files. Files remain graph nodes.
|
|
493
|
-
It supports lexical nesting, compact namespaces, root-qualified names, and explicit superclass,
|
|
494
|
-
`include`, `prepend`, and `extend` references. Nested `module A; module B` includes `A` in lexical
|
|
495
|
-
lookup; top-level `module A::B` does not. A nearer namespace shadows a root namespace even when its
|
|
496
|
-
requested child is missing.
|
|
497
|
-
|
|
498
|
-
Ordinary `=` and conditional `||=` constant declarations are indexed, including qualified and
|
|
499
|
-
root-qualified forms. A conditional declaration records a possible definition file, not proof that
|
|
500
|
-
the assignment executes or its resulting value. Multiple candidate files stay ambiguous. Other
|
|
501
|
-
compound writes (`&&=`, operators) and multiple-assignment declarations are not inferred as new
|
|
502
|
-
definition owners; unsupported targets remain unresolved rather than inventing ownership.
|
|
503
|
-
|
|
504
|
-
References with multiple definition files (reopened classes/modules), missing definitions, and
|
|
505
|
-
dynamic definitions are omitted, never assigned to an arbitrary file. `Alias = Original` defines
|
|
506
|
-
`Alias` in its own file and records the reference to `Original`; lookup through aliases such as
|
|
507
|
-
`Alias::Child` is not followed. Inherited constant members and singleton-class lexical lookup are
|
|
508
|
-
not modeled. Unqualified root fallback is conservatively suppressed in scopes with an explicit
|
|
509
|
-
superclass, mixins, or dynamic constant operations. Use explicit `::Namespace::Constant` references
|
|
510
|
-
or import rules where those limits matter. Static analysis does not establish runtime load order
|
|
511
|
-
or whether a conditional use executes. Qualified declaration owners are stabilized before lookup;
|
|
512
|
-
if they do not stabilize within eight index passes, the project contributes imports only and its
|
|
513
|
-
constant uses are counted as unresolved.
|
|
514
|
-
|
|
515
|
-
In expanded mode, an import and a constant use between the same files produce one logical edge.
|
|
516
|
-
Its `import_kinds`
|
|
517
|
-
includes `:constant_reference`; `edge.evidence` and JSON graph exports retain the referenced name,
|
|
518
|
-
source span, and definition line for constant uses. Import evidence retains its call span. CSV,
|
|
519
|
-
HTML, and diagram reports use the same merged graph; CSV/HTML distinguish dependency kinds.
|
|
520
|
-
`# archunit: ignore` continues to suppress imports only, not constant references. Import-only mode
|
|
521
|
-
leaves `edge.evidence` empty for compatibility with existing edge-value comparisons;
|
|
522
|
-
`ArchUnit::Extraction.extract_imports` retains call locations in both modes.
|
|
523
|
-
|
|
524
|
-
For diagnostics, pass an `ArchUnit::Extraction::ExtractionProfile` to
|
|
525
|
-
`ArchUnit::Extraction.extract_graph(root, options: options, profile: profile)`. Its counters include
|
|
526
|
-
`unresolved_imports`, `unresolved_constant_references`, and `ambiguous_constant_references`; unknown
|
|
527
|
-
third-party constants do not become architecture violations. These counts describe a cold analysis;
|
|
528
|
-
a cache hit does not rerun diagnostics. Included malformed Ruby now raises
|
|
529
|
-
`ArchUnit::SourceParseError < ArchUnit::TechnicalError` in both modes and in AST metrics, rather
|
|
530
|
-
than silently returning a partial graph or zero counts. Its immutable `diagnostics` contain
|
|
531
|
-
`path`, one-based `line` and `column`, and the parser `message`; the extraction profile increments
|
|
532
|
-
`malformed_files`. Fix or explicitly exclude invalid files using the project source policy.
|
|
533
|
-
Fluent rule selectors do not limit graph discovery. Failed graph builds are not cached; after
|
|
534
|
-
editing previously cached valid source, the normal explicit `clear_cache: true` policy still applies.
|
|
535
|
-
This intentionally changes the 0.0.1 prototype's permissive behavior in the 1.0 API.
|
|
536
|
-
|
|
537
|
-
Expanded analysis uses a bounded Prism index and adds no runtime dependency. The design spike
|
|
538
|
-
considered [RubyDEX](https://github.com/Shopify/rubydex), whose semantic index is broader but adds a
|
|
539
|
-
Rust/native extension and platform packaging requirements. Reusing our existing Prism parser keeps
|
|
540
|
-
the Ruby 3.3/3.4/4.0 Windows/Linux support contract; each included source is parsed once per graph
|
|
541
|
-
build. A later semantic backend can broaden the documented lookup subset. Lookup fixtures follow
|
|
542
|
-
the [Ruby constant-scope documentation](https://docs.ruby-lang.org/en/master/syntax/modules_and_classes_rdoc.html#label-Constants).
|
|
543
|
-
|
|
544
|
-
Repositories containing multiple gems are discovered statically: every `*.gemspec` beneath the
|
|
545
|
-
project root contributes its adjacent existing `lib` directory to feature resolution. Gemspecs are
|
|
546
|
-
never evaluated. Add non-standard source roots explicitly through the per-check options bag; paths
|
|
547
|
-
are relative to the project root, must remain inside it, and use the order given after the normal
|
|
548
|
-
top-level `lib` and project-root search locations:
|
|
549
|
-
|
|
550
|
-
~~~ ruby
|
|
551
|
-
options = ArchUnit::CheckOptions.new(
|
|
552
|
-
load_paths: ['components/billing/source', 'plugins/search/lib']
|
|
553
|
-
)
|
|
258
|
+
## Example project and validation
|
|
554
259
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
260
|
+
The [Ruby RAG example](https://github.com/TristanKruse/ArchUnitRuby-TestRepo-RAG) is a small layered
|
|
261
|
+
application with intentional architecture violations. Use it for a hands-on walkthrough;
|
|
262
|
+
its tests also run against the current checkout in our CI.
|
|
558
263
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
264
|
+
The library dogfoods its own architecture. CI checks Ruby 3.3/3.4/4.0 on Linux and Ruby 4.0 on
|
|
265
|
+
Windows, gates runtime-library coverage at 98% line / 90% branch, validates docs and package
|
|
266
|
+
installation, and runs security checks. Coverage measures executed test paths, not Ruby semantic
|
|
267
|
+
completeness or a guarantee that no bugs remain.
|
|
563
268
|
|
|
564
|
-
|
|
269
|
+
Four pinned production-library canaries—Rack, Rake, RSpec Core, and RestClient—exercise passing
|
|
270
|
+
and deliberately failing policies. A broader 50-repository source audit and the separate
|
|
271
|
+
[Linux performance study](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/benchmark/study/README.md)
|
|
272
|
+
provide bounded evidence, not upstream architecture/security judgments or a universal speed claim.
|
|
565
273
|
|
|
566
|
-
|
|
567
|
-
is a small layered retrieval-augmented-generation application with two deliberate architecture
|
|
568
|
-
violations. Its test suite exercises the public APIs above against real Ruby source on Linux and
|
|
569
|
-
Windows.
|
|
274
|
+
<a id="documentation"></a>
|
|
570
275
|
|
|
571
|
-
|
|
572
|
-
modules cannot depend on one another, implementation files cannot depend on the public surface, and
|
|
573
|
-
the complete library graph must remain cycle-free.
|
|
276
|
+
## Documentation and development
|
|
574
277
|
|
|
575
|
-
|
|
278
|
+
- [User guide](GUIDE.md): recipes, project discovery, exclusions, Ruby analysis, CLI, and migration.
|
|
279
|
+
- [API contract](API.md): exact behavior, options, report formats, and errors.
|
|
280
|
+
- [Online documentation](https://dragonsec-ai.github.io/ArchUnitRuby/): getting started, guides,
|
|
281
|
+
and searchable source-generated reference; follows `main`.
|
|
282
|
+
- [Changelog](CHANGELOG.md), [contributing](CONTRIBUTING.md), [security](SECURITY.md),
|
|
283
|
+
[support](SUPPORT.md), and [release process](https://github.com/dragonsec-ai/ArchUnitRuby/blob/main/.github/RELEASING.md).
|
|
576
284
|
|
|
577
|
-
|
|
285
|
+
To work on the library:
|
|
578
286
|
|
|
579
|
-
~~~
|
|
580
|
-
git clone https://github.com/
|
|
287
|
+
~~~sh
|
|
288
|
+
git clone https://github.com/dragonsec-ai/ArchUnitRuby.git
|
|
581
289
|
cd ArchUnitRuby
|
|
582
290
|
bundle install
|
|
583
291
|
bundle exec rake
|
|
584
292
|
bundle exec rake docs
|
|
585
|
-
gem build archunit.gemspec --strict
|
|
586
293
|
~~~
|
|
587
294
|
|
|
588
|
-
|
|
589
|
-
CI additionally enforces 98% line
|
|
590
|
-
and 90% branch coverage, runs the dogfooding rules explicitly, builds the documentation, loads the
|
|
591
|
-
public API with Ruby warnings, tests optional RSpec/Minitest integrations, builds and installs the
|
|
592
|
-
gem artifact, runs the external RAG fixture, and checks Ruby 3.3, 3.4, and 4.0 across Ubuntu and
|
|
593
|
-
Windows.
|
|
594
|
-
|
|
595
|
-
Cold and warm extraction can be profiled independently with a generated multi-gem corpus. The
|
|
596
|
-
benchmark reports stage timings, resolution-cache effectiveness, Ruby heap growth, and peak RSS on
|
|
597
|
-
platforms that expose it:
|
|
598
|
-
|
|
599
|
-
~~~ bash
|
|
600
|
-
bundle exec ruby benchmark/extraction.rb
|
|
601
|
-
~~~
|
|
602
|
-
|
|
603
|
-
See the [benchmark guide](https://github.com/LukasNiessen/ArchUnitRuby/blob/main/benchmark/README.md)
|
|
604
|
-
for corpus controls, JSON output, and CI limits.
|
|
605
|
-
|
|
606
|
-
The separate [real-world canary](https://github.com/LukasNiessen/ArchUnitRuby/blob/main/benchmark/canary/README.md)
|
|
607
|
-
checks pinned Rack, Rake, and RSpec production-library sources in both dependency modes, including
|
|
608
|
-
passing and deliberately failing rules, graph baselines, and cold/warm performance. It never runs
|
|
609
|
-
those projects or installs their dependencies, and is not scheduled automatically yet.
|
|
610
|
-
|
|
611
|
-
The implementation conventions and intended dependency directions live in [`AGENTS.md`](AGENTS.md).
|
|
612
|
-
|
|
613
|
-
## 1.0 compatibility and migration
|
|
614
|
-
|
|
615
|
-
The documented entry points, fluent rule methods, options, public data/error types, and report
|
|
616
|
-
formats in the [API guide](https://lukasniessen.github.io/ArchUnitRuby/file.API.html) form the 1.x
|
|
617
|
-
compatibility baseline. Additive capabilities may be introduced in minor versions; incompatible
|
|
618
|
-
public API changes require a new major version and migration notes. Private implementation helpers
|
|
619
|
-
are not part of that contract. Correctness fixes can reveal violations that earlier versions missed;
|
|
620
|
-
review the changelog when updating.
|
|
621
|
-
|
|
622
|
-
When upgrading from 0.0.1:
|
|
623
|
-
|
|
624
|
-
- The default remains import-only. Explicitly opt into `dependency_analysis: :imports_and_constants`
|
|
625
|
-
when you want the documented static constant-reference model; it may reveal additional violations.
|
|
626
|
-
- Included malformed Ruby now raises `SourceParseError < TechnicalError`, rather than silently
|
|
627
|
-
passing or returning zero AST counts. Fix or explicitly exclude invalid source files.
|
|
628
|
-
- Project `.archignore` exclusions and skipped symlinked source entries can change the discovered
|
|
629
|
-
file set. Empty selections are still violations by default; check selectors rather than blindly
|
|
630
|
-
allowing empty tests.
|
|
631
|
-
- Cached graph results still require explicit clearing after source edits in a long-lived process.
|
|
632
|
-
|
|
633
|
-
Stable API compatibility does not mean complete Ruby interpretation or exhaustive runtime detection.
|
|
634
|
-
The supported static-analysis boundaries below remain part of the contract.
|
|
635
|
-
|
|
636
|
-
## 📅 Plans and Current Limitations
|
|
637
|
-
|
|
638
|
-
- Files are the primary vocabulary; opt-in constant analysis has the lookup limits described above.
|
|
639
|
-
- Runtime-derived import paths cannot be resolved; safely known local literal strings are supported.
|
|
640
|
-
- PlantUML support is a deliberately small component-diagram subset, not a complete UML parser.
|
|
641
|
-
- `.archignore` supports exclusion globs, not negated gitignore patterns or nested ignore files.
|
|
642
|
-
- Cycle traversal is iterative and tested on 10,000-node chains and rings. Enumerating every cycle
|
|
643
|
-
can still be expensive in densely connected graphs; narrow the selected scope when necessary.
|
|
644
|
-
- Method-call/protocol rules, a standalone CLI, presets, and adoption baselines are roadmap work,
|
|
645
|
-
not claims made by the current 1.0 API.
|
|
646
|
-
|
|
647
|
-
## 💟 Community
|
|
648
|
-
|
|
649
|
-
### Maintainers
|
|
650
|
-
|
|
651
|
-
- **[Tristan Kruse](https://github.com/TristanKruse)** — Tech Lead & Maintainer
|
|
652
|
-
- **[Lukas Niessen](https://github.com/LukasNiessen)** — Maintainer
|
|
653
|
-
|
|
654
|
-
### Contributors
|
|
655
|
-
|
|
656
|
-
See everyone who has contributed on the [GitHub contributors page](https://github.com/LukasNiessen/ArchUnitRuby/graphs/contributors).
|
|
657
|
-
|
|
658
|
-
Questions and feature ideas are welcome in [GitHub Issues](https://github.com/LukasNiessen/ArchUnitRuby/issues).
|
|
659
|
-
For usage help, responsible vulnerability reporting, and community expectations, see
|
|
660
|
-
[SUPPORT.md](SUPPORT.md), [SECURITY.md](SECURITY.md), and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
|
|
661
|
-
|
|
662
|
-
### Star History
|
|
663
|
-
|
|
664
|
-
[](https://star-history.com/#LukasNiessen/ArchUnitRuby&Date)
|
|
665
|
-
|
|
666
|
-
## 📄 License
|
|
295
|
+
<a id="community"></a>
|
|
667
296
|
|
|
668
|
-
|
|
297
|
+
## Community and license
|
|
669
298
|
|
|
670
|
-
|
|
299
|
+
Maintained by [Tristan Kruse](https://github.com/TristanKruse) and
|
|
300
|
+
[Lukas Niessen](https://github.com/LukasNiessen), with our
|
|
301
|
+
[contributors](https://github.com/dragonsec-ai/ArchUnitRuby/graphs/contributors).
|
|
671
302
|
|
|
672
|
-
|
|
303
|
+
Part of the ArchUnitEverything family alongside
|
|
304
|
+
[ArchUnitTS](https://github.com/LukasNiessen/ArchUnitTS) and
|
|
305
|
+
[ArchUnitPython](https://github.com/LukasNiessen/ArchUnitPython).
|
|
306
|
+
Questions and feature requests belong in [GitHub Issues](https://github.com/dragonsec-ai/ArchUnitRuby/issues);
|
|
307
|
+
report vulnerabilities through [SECURITY.md](SECURITY.md).
|
|
673
308
|
|
|
674
|
-
|
|
309
|
+
[MIT license](LICENSE). [Download analytics](https://clickgems.clickhouse.com/dashboard/archunit)
|
|
310
|
+
count package fetches, not unique users.
|