archunit 0.0.1 → 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 +498 -0
- data/CHANGELOG.md +85 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +75 -0
- data/GUIDE.md +804 -0
- data/README.md +224 -289
- data/SECURITY.md +64 -0
- data/SUPPORT.md +23 -0
- data/assets/logo-rounded.png +0 -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/dependency_evidence.rb +44 -0
- data/lib/archunit/common/extraction/edge.rb +7 -2
- data/lib/archunit/common/extraction/import_kind.rb +4 -1
- data/lib/archunit/common/extraction/parse_diagnostic.rb +23 -0
- data/lib/archunit/common/extraction/source_exclusions.rb +43 -0
- data/lib/archunit/common/fluentapi/check_options.rb +53 -2
- data/lib/archunit/common/fluentapi/checkable.rb +25 -1
- data/lib/archunit/common/logging/check_logger.rb +8 -0
- data/lib/archunit/common/logging/inspection.rb +59 -0
- data/lib/archunit/common/logging/logging_options.rb +5 -0
- data/lib/archunit/common/pattern.rb +18 -8
- data/lib/archunit/common/projection/cycles/johnson_cycles.rb +35 -19
- data/lib/archunit/common/projection/cycles/tarjan_scc.rb +30 -10
- data/lib/archunit/error/source_parse_error.rb +38 -0
- 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/arch_ignore.rb +91 -0
- data/lib/archunit/extraction/conservative_local_flow.rb +100 -0
- data/lib/archunit/extraction/constant_index.rb +110 -0
- data/lib/archunit/extraction/constant_visitor.rb +137 -0
- data/lib/archunit/extraction/dependency_context.rb +30 -0
- data/lib/archunit/extraction/discover_gemspec_load_paths.rb +96 -0
- data/lib/archunit/extraction/enumerate_source_files.rb +36 -9
- data/lib/archunit/extraction/extract_dependencies.rb +74 -15
- data/lib/archunit/extraction/extract_graph.rb +74 -40
- data/lib/archunit/extraction/extract_imports.rb +57 -124
- data/lib/archunit/extraction/extraction_profile.rb +105 -0
- 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 +65 -0
- data/lib/archunit/extraction/import_source_policy.rb +123 -0
- data/lib/archunit/extraction/import_visitor.rb +89 -0
- data/lib/archunit/extraction/load_arguments.rb +34 -0
- data/lib/archunit/extraction/local_string_tracker.rb +81 -0
- data/lib/archunit/extraction/resolve_import.rb +5 -3
- data/lib/archunit/extraction/resolve_load_paths.rb +98 -0
- data/lib/archunit/extraction/resolved_import.rb +5 -2
- data/lib/archunit/extraction/source_analysis.rb +26 -0
- data/lib/archunit/extraction/static_import_path.rb +111 -0
- data/lib/archunit/extraction/validate_extraction_paths.rb +37 -0
- data/lib/archunit/files/extraction/extract_file_info.rb +14 -5
- data/lib/archunit/files/extraction/file_info.rb +1 -2
- data/lib/archunit/files/fluentapi/depend_on_external_module_condition.rb +2 -0
- data/lib/archunit/files/fluentapi/depend_on_external_module_condition_builder.rb +2 -0
- data/lib/archunit/files/fluentapi/depend_on_file_condition.rb +6 -0
- data/lib/archunit/files/fluentapi/depend_on_file_condition_builder.rb +6 -0
- data/lib/archunit/files/fluentapi/file_condition_builder.rb +12 -0
- data/lib/archunit/files/fluentapi/file_rule_support.rb +8 -1
- data/lib/archunit/files/fluentapi/files.rb +6 -0
- data/lib/archunit/files/fluentapi/match_pattern_file_condition_builder.rb +14 -0
- data/lib/archunit/files/fluentapi/positive_match_pattern_file_condition_builder.rb +2 -0
- data/lib/archunit/graph/fluentapi/graph.rb +5 -0
- data/lib/archunit/graph/fluentapi/project_graph_builder.rb +44 -0
- data/lib/archunit/graph/projection/aggregate_edges.rb +4 -2
- data/lib/archunit/graph/projection/graph_query_options.rb +1 -2
- data/lib/archunit/graph/projection/graph_report_edge.rb +12 -2
- data/lib/archunit/graph/rendering/json_renderer.rb +3 -1
- data/lib/archunit/layers/fluentapi/architecture_preset.rb +49 -0
- data/lib/archunit/layers/fluentapi/layer_definition_builder.rb +4 -0
- data/lib/archunit/layers/fluentapi/layer_dependency_rule_builder.rb +4 -0
- data/lib/archunit/layers/fluentapi/layered_architecture.rb +5 -0
- data/lib/archunit/layers/fluentapi/layers.rb +5 -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 +2 -3
- data/lib/archunit/metrics/extraction/extract_project_info.rb +14 -10
- data/lib/archunit/metrics/extraction/metric_info.rb +2 -4
- data/lib/archunit/metrics/extraction/source_metrics_visitor.rb +2 -4
- data/lib/archunit/metrics/fluentapi/custom_metric_builder.rb +2 -0
- data/lib/archunit/metrics/fluentapi/custom_metric_condition.rb +4 -1
- data/lib/archunit/metrics/fluentapi/logged_metric.rb +23 -0
- data/lib/archunit/metrics/fluentapi/metric_predicate_condition.rb +4 -1
- data/lib/archunit/metrics/fluentapi/metric_report_builder.rb +6 -3
- data/lib/archunit/metrics/fluentapi/metric_selection.rb +18 -2
- data/lib/archunit/metrics/fluentapi/metric_threshold_condition.rb +2 -1
- data/lib/archunit/metrics/fluentapi/metrics.rb +5 -0
- data/lib/archunit/metrics/fluentapi/metrics_builder.rb +18 -3
- data/lib/archunit/metrics/reporting/metrics_export_options.rb +6 -2
- data/lib/archunit/slices/fluentapi/diagram_slice_condition.rb +1 -0
- data/lib/archunit/slices/fluentapi/forbidden_slice_dependency_condition.rb +1 -0
- data/lib/archunit/slices/fluentapi/negative_slice_condition_builder.rb +2 -0
- data/lib/archunit/slices/fluentapi/positive_slice_condition_builder.rb +8 -0
- data/lib/archunit/slices/fluentapi/slice_scope_builder.rb +12 -0
- data/lib/archunit/slices/fluentapi/slices.rb +5 -0
- data/lib/archunit/testing/assert_passes.rb +4 -0
- data/lib/archunit/testing/result_factory.rb +16 -4
- data/lib/archunit/testing/rspec_adapter.rb +1 -2
- data/lib/archunit/testing.rb +7 -3
- data/lib/archunit/version.rb +1 -1
- data/lib/archunit.rb +11 -0
- metadata +67 -9
data/README.md
CHANGED
|
@@ -1,375 +1,310 @@
|
|
|
1
1
|
# ArchUnitRuby
|
|
2
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
|
-
[
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="assets/logo-rounded.png" width="160" alt="ArchUnitRuby">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
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>
|
|
10
|
+
<a href="https://clickgems.clickhouse.com/dashboard/archunit"><img alt="Gem downloads" src="https://img.shields.io/gem/dt/archunit.svg"></a>
|
|
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
|
+
</p>
|
|
14
|
+
|
|
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.
|
|
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
|
+
~~~
|
|
25
|
+
|
|
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.
|
|
28
|
+
|
|
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)
|
|
32
|
+
|
|
33
|
+
<a id="availability"></a>
|
|
34
|
+
|
|
35
|
+
## Release status
|
|
36
|
+
|
|
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.
|
|
30
47
|
|
|
31
|
-
|
|
48
|
+
<a id="quickstart"></a>
|
|
32
49
|
|
|
33
|
-
|
|
34
|
-
searchable, source-generated API reference for every public module, class, and method. The same
|
|
35
|
-
site is rebuilt in CI and deployed from `main`, so the published reference follows the repository.
|
|
50
|
+
## Quickstart
|
|
36
51
|
|
|
37
|
-
|
|
52
|
+
### 1. Install
|
|
38
53
|
|
|
39
|
-
|
|
54
|
+
Ruby 3.3+ is required. Add ArchUnitRuby to your test dependencies:
|
|
40
55
|
|
|
41
|
-
|
|
56
|
+
~~~ruby
|
|
42
57
|
# Gemfile
|
|
43
58
|
group :test do
|
|
44
|
-
gem 'archunit', '~>
|
|
59
|
+
gem 'archunit', '~> 1.1.0'
|
|
60
|
+
gem 'rspec' # Omit this line if RSpec is already in your bundle.
|
|
45
61
|
end
|
|
46
|
-
|
|
62
|
+
~~~
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```bash
|
|
64
|
+
~~~sh
|
|
51
65
|
bundle install
|
|
52
|
-
|
|
66
|
+
~~~
|
|
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)`.
|
|
53
70
|
|
|
54
|
-
|
|
71
|
+
### 2. Write your first architecture test
|
|
55
72
|
|
|
56
|
-
|
|
57
|
-
for you.
|
|
73
|
+
For this example, use two ordinary source files:
|
|
58
74
|
|
|
59
|
-
|
|
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
|
+
~~~
|
|
60
82
|
|
|
61
|
-
Create `spec/architecture_spec.rb
|
|
83
|
+
Create `spec/architecture_spec.rb`. Change the folder patterns to match your project.
|
|
62
84
|
|
|
63
|
-
|
|
85
|
+
<!-- example:quickstart-spec -->
|
|
86
|
+
~~~ruby
|
|
64
87
|
require 'archunit'
|
|
65
88
|
|
|
66
|
-
RSpec.describe '
|
|
89
|
+
RSpec.describe 'Architecture' do
|
|
67
90
|
it 'keeps the API away from the database' do
|
|
68
91
|
rule = ArchUnit.project_files.in_folder('app/api/**')
|
|
69
92
|
.should_not.depend_on_files.in_folder('app/database/**')
|
|
93
|
+
.because('Keep persistence behind the service boundary')
|
|
70
94
|
|
|
71
95
|
expect(rule).to pass
|
|
72
96
|
end
|
|
73
97
|
end
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Run it like any other specification:
|
|
98
|
+
~~~
|
|
77
99
|
|
|
78
|
-
|
|
100
|
+
~~~sh
|
|
79
101
|
bundle exec rspec spec/architecture_spec.rb
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
The project locator is optional. With no argument, ArchUnitRuby searches from the current directory
|
|
83
|
-
for a `Gemfile` or gemspec. Pass a directory or either marker file when analyzing another project:
|
|
84
|
-
|
|
85
|
-
```ruby
|
|
86
|
-
ArchUnit.project_files('/workspace/my_app')
|
|
87
|
-
ArchUnit.project_files('/workspace/my_app/Gemfile')
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## The fluent grammar
|
|
91
|
-
|
|
92
|
-
Every rule is built left to right from the same small grammar:
|
|
93
|
-
|
|
94
|
-
| Stage | Purpose | Examples |
|
|
95
|
-
| --- | --- | --- |
|
|
96
|
-
| Entry | Choose the architectural vocabulary | `project_files`, `project_layers`, `project_slices`, `project_graph`, `metrics` |
|
|
97
|
-
| Scope | Select subjects; repeated scopes use AND | `in_folder`, `in_path`, `with_name`, `for_classes_matching` |
|
|
98
|
-
| Mood | Choose the expected direction | `should`, `should_not` |
|
|
99
|
-
| Predicate | State the policy | `have_no_cycles`, `depend_on_files`, `adhere_to_diagram` |
|
|
100
|
-
| Object | Select the target of a relational rule | `in_folder`, `matching`, a layer or slice name |
|
|
101
|
-
| Terminal | Execute or render | `check`, `to_json`, `export_as_html`, `measure` |
|
|
102
|
-
|
|
103
|
-
Building a rule is lazy and does not scan the filesystem. `check`, `measure`, snapshot/report
|
|
104
|
-
terminals, and export terminals perform the work. Builders are immutable, so a scope can be reused:
|
|
105
|
-
|
|
106
|
-
```ruby
|
|
107
|
-
services = ArchUnit.project_files.in_folder('app/services/**')
|
|
102
|
+
~~~
|
|
108
103
|
|
|
109
|
-
|
|
110
|
-
database_rule = services.should_not.depend_on_files.in_folder('app/database/**')
|
|
111
|
-
```
|
|
104
|
+
No special CI service is required: run architecture specifications with your normal tests.
|
|
112
105
|
|
|
113
|
-
|
|
114
|
-
and `?` matches one non-separator character. Most selectors also accept regular expressions;
|
|
115
|
-
`defined_by_regex` is the explicit regex form for slices, while `in_file` takes one exact path.
|
|
116
|
-
Paths are project-relative and normalized to `/` separators.
|
|
106
|
+
### 3. See it catch a dependency
|
|
117
107
|
|
|
118
|
-
|
|
119
|
-
when an empty result is genuinely valid:
|
|
108
|
+
Add this line to `app/api/request.rb` and rerun the test:
|
|
120
109
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
~~~ruby
|
|
111
|
+
require_relative '../database/store'
|
|
112
|
+
~~~
|
|
124
113
|
|
|
125
|
-
|
|
114
|
+
The test fails with concrete file evidence:
|
|
126
115
|
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
~~~text
|
|
117
|
+
File dependency violation
|
|
118
|
+
File 'app/api/request.rb' depends on forbidden file 'app/database/store.rb'.
|
|
119
|
+
~~~
|
|
129
120
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
ArchUnit.project_files.in_folder('app/services/**')
|
|
134
|
-
.should.have_name('*_service.rb'),
|
|
135
|
-
ArchUnit.project_files.in_folder('app/domain/**')
|
|
136
|
-
.should_not.depend_on_external_modules.matching('faraday')
|
|
137
|
-
]
|
|
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.
|
|
138
124
|
|
|
139
|
-
|
|
140
|
-
```
|
|
125
|
+
[Complete workflows](GUIDE.md) · [Watch the recorded demo](https://github.com/user-attachments/assets/9b7305a0-deee-454d-b99e-f8fac63d06ab)
|
|
141
126
|
|
|
142
|
-
|
|
143
|
-
complete `content`, and non-blank `lines_of_code`:
|
|
127
|
+
<a id="capabilities"></a>
|
|
144
128
|
|
|
145
|
-
|
|
146
|
-
rule = ArchUnit.project_files.in_folder('app/services/**')
|
|
147
|
-
.should.adhere_to(
|
|
148
|
-
->(file) { file.lines_of_code < 300 },
|
|
149
|
-
'services must stay below 300 non-blank lines'
|
|
150
|
-
)
|
|
151
|
-
```
|
|
129
|
+
## What you can enforce and explore
|
|
152
130
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
## Slices and PlantUML
|
|
174
|
-
|
|
175
|
-
Slices group files by one captured path segment and preserve every concrete dependency as evidence:
|
|
176
|
-
|
|
177
|
-
```ruby
|
|
178
|
-
slices = ArchUnit.project_slices.defined_by('lib/my_app/(**)/')
|
|
179
|
-
rule = slices.should_not.contain_dependency('api', 'database')
|
|
180
|
-
|
|
181
|
-
expect(rule).to pass
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
`(**)` is the slice capture. `defined_by_regex` uses the first regular-expression capture instead.
|
|
185
|
-
|
|
186
|
-
A checked-in PlantUML component diagram can also be the architecture contract:
|
|
187
|
-
|
|
188
|
-
```ruby
|
|
189
|
-
rule = slices.should
|
|
190
|
-
.ignoring_external_slices
|
|
191
|
-
.adhere_to_diagram_in_file('docs/architecture.puml')
|
|
192
|
-
|
|
193
|
-
expect(rule).to pass
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
The supported subset recognizes components, directed dependencies, comments, and `@startuml` /
|
|
197
|
-
`@enduml`. Use `to_plantuml` or `export_as_plantuml(path)` to generate a diagram from the real graph.
|
|
198
|
-
|
|
199
|
-
## Dependency graph reports
|
|
200
|
-
|
|
201
|
-
Graph reporting builds one immutable snapshot and renders it consistently as DOT, Mermaid, D2, CSV,
|
|
202
|
-
JSON, or self-contained HTML:
|
|
203
|
-
|
|
204
|
-
```ruby
|
|
205
|
-
report = ArchUnit.project_graph
|
|
206
|
-
.include_external_dependencies
|
|
207
|
-
.focus_on('app/services/**', 2)
|
|
208
|
-
.collapse_to_folder_depth(2)
|
|
209
|
-
.titled('Service dependencies')
|
|
210
|
-
|
|
211
|
-
puts report.summary.node_count
|
|
212
|
-
report.export_as_html('reports/services.html')
|
|
213
|
-
```
|
|
131
|
+
| Capability | Public entry point | Details |
|
|
132
|
+
| --- | --- | --- |
|
|
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)` |
|
|
214
150
|
|
|
215
|
-
|
|
216
|
-
regular-expression replacement. Every format has an in-memory `to_<format>` and an
|
|
217
|
-
`export_as_<format>(path)` terminal.
|
|
151
|
+
### More than dependency boundaries
|
|
218
152
|
|
|
219
|
-
|
|
153
|
+
A cycle rule:
|
|
220
154
|
|
|
221
|
-
|
|
155
|
+
<!-- example:cycle-rule -->
|
|
156
|
+
~~~ruby
|
|
157
|
+
rule = ArchUnit.project_files.in_path('app/**/*.rb').should.have_no_cycles
|
|
158
|
+
ArchUnit.assert_passes(rule)
|
|
159
|
+
~~~
|
|
222
160
|
|
|
223
|
-
|
|
224
|
-
services = ArchUnit.metrics
|
|
225
|
-
.in_path('app/services/**/*.rb')
|
|
226
|
-
.for_classes_matching('*Service')
|
|
161
|
+
An architecture report:
|
|
227
162
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
168
|
+
~~~
|
|
231
169
|
|
|
232
|
-
|
|
233
|
-
```
|
|
170
|
+
A metric threshold:
|
|
234
171
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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)
|
|
177
|
+
~~~
|
|
239
178
|
|
|
240
|
-
|
|
241
|
-
|
|
179
|
+
See the [user guide](GUIDE.md#recipes) for layer/slice policies, custom predicates, logging,
|
|
180
|
+
report queries, and complete examples.
|
|
242
181
|
|
|
243
|
-
|
|
244
|
-
services.count.export_as_html('reports/service-counts')
|
|
245
|
-
```
|
|
182
|
+
<a id="analysis"></a>
|
|
246
183
|
|
|
247
|
-
|
|
248
|
-
`should_be`, `should_be_below_or_equal`, `should_be_above_or_equal`, and `should_satisfy`.
|
|
184
|
+
## Choosing the analysis mode
|
|
249
185
|
|
|
250
|
-
|
|
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.
|
|
251
188
|
|
|
252
|
-
|
|
253
|
-
selector's context, including filenames for path and folder selectors:
|
|
189
|
+
For autoloaded code, explicitly add the supported static constant-reference model:
|
|
254
190
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
)
|
|
260
|
-
|
|
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)
|
|
197
|
+
~~~
|
|
261
198
|
|
|
262
|
-
|
|
263
|
-
|
|
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)
|
|
264
202
|
|
|
265
|
-
|
|
266
|
-
scope = ArchUnit.metrics.in_path(
|
|
267
|
-
'app/**/*.rb',
|
|
268
|
-
except: { in_folder: 'app/generated', with_name: '*_spec.rb' }
|
|
269
|
-
)
|
|
270
|
-
```
|
|
203
|
+
<a id="development-cli"></a>
|
|
271
204
|
|
|
272
|
-
##
|
|
205
|
+
## CLI and gradual adoption — 1.1+
|
|
273
206
|
|
|
274
|
-
|
|
275
|
-
exception:
|
|
207
|
+
These commands require ArchUnitRuby 1.1 or newer. They are not available in 1.0.0.
|
|
276
208
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
|
215
|
+
~~~
|
|
281
216
|
|
|
282
|
-
|
|
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.
|
|
283
220
|
|
|
284
|
-
|
|
285
|
-
expect(rule).to pass # RSpec
|
|
286
|
-
assert_passes(rule) # Minitest test case
|
|
287
|
-
ArchUnit.assert_passes(rule) # Framework-neutral
|
|
288
|
-
```
|
|
221
|
+
For gradual adoption, explicitly record reviewed violations:
|
|
289
222
|
|
|
290
|
-
|
|
291
|
-
|
|
223
|
+
~~~sh
|
|
224
|
+
bundle exec archunit baseline --output .archunit-baseline.json
|
|
225
|
+
bundle exec archunit check --baseline .archunit-baseline.json
|
|
226
|
+
~~~
|
|
292
227
|
|
|
293
|
-
|
|
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.
|
|
294
231
|
|
|
295
|
-
|
|
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.
|
|
296
236
|
|
|
297
|
-
|
|
298
|
-
logging = ArchUnit::LoggingOptions.new(
|
|
299
|
-
level: :debug,
|
|
300
|
-
output_directory: 'tmp/archunit-logs',
|
|
301
|
-
append: false
|
|
302
|
-
)
|
|
237
|
+
[CLI contract](API.md#cli) · [Baseline contract](API.md#baselines) · [Presets](GUIDE.md#presets)
|
|
303
238
|
|
|
304
|
-
|
|
305
|
-
```
|
|
239
|
+
<a id="limitations"></a>
|
|
306
240
|
|
|
307
|
-
|
|
308
|
-
violations, and metric evidence. `io:` defaults to `$stderr`, accepts any writable stream, and may be
|
|
309
|
-
`nil`. File output creates missing directories and writes timestamped `archunit-*.log` files.
|
|
241
|
+
## Important boundaries
|
|
310
242
|
|
|
311
|
-
|
|
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.
|
|
312
253
|
|
|
313
|
-
|
|
254
|
+
[Full analysis contract](GUIDE.md#analysis) · [Errors and troubleshooting](API.md#errors)
|
|
314
255
|
|
|
315
|
-
|
|
316
|
-
| --- | --- |
|
|
317
|
-
| `require 'json'` | `:require` |
|
|
318
|
-
| `require_relative '../models/order'` | `:require_relative` |
|
|
319
|
-
| `autoload :Order, 'models/order'` | `:autoload` |
|
|
320
|
-
| `load 'config/setup.rb'` | `:load` |
|
|
256
|
+
<a id="example-project"></a>
|
|
321
257
|
|
|
322
|
-
|
|
323
|
-
retain the module name written in source. Inline or immediately preceding ignore directives can
|
|
324
|
-
suppress known compatibility imports:
|
|
258
|
+
## Example project and validation
|
|
325
259
|
|
|
326
|
-
|
|
327
|
-
|
|
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.
|
|
328
263
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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.
|
|
332
268
|
|
|
333
|
-
|
|
334
|
-
|
|
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.
|
|
335
273
|
|
|
336
|
-
|
|
274
|
+
<a id="documentation"></a>
|
|
337
275
|
|
|
338
|
-
|
|
339
|
-
is a small layered retrieval-augmented-generation application with two deliberate architecture
|
|
340
|
-
violations. Its test suite exercises the public APIs above against real Ruby source on Linux and
|
|
341
|
-
Windows.
|
|
276
|
+
## Documentation and development
|
|
342
277
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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).
|
|
346
284
|
|
|
347
|
-
|
|
285
|
+
To work on the library:
|
|
348
286
|
|
|
349
|
-
|
|
350
|
-
git clone https://github.com/
|
|
287
|
+
~~~sh
|
|
288
|
+
git clone https://github.com/dragonsec-ai/ArchUnitRuby.git
|
|
351
289
|
cd ArchUnitRuby
|
|
352
290
|
bundle install
|
|
353
291
|
bundle exec rake
|
|
354
292
|
bundle exec rake docs
|
|
355
|
-
|
|
356
|
-
```
|
|
293
|
+
~~~
|
|
357
294
|
|
|
358
|
-
|
|
359
|
-
and 90% branch coverage, runs the dogfooding rules explicitly, builds the documentation, loads the
|
|
360
|
-
public API with Ruby warnings, tests optional RSpec/Minitest integrations, builds and installs the
|
|
361
|
-
gem artifact, runs the external RAG fixture, and checks Ruby 3.3, 3.4, and 4.0 across Ubuntu and
|
|
362
|
-
Windows.
|
|
295
|
+
<a id="community"></a>
|
|
363
296
|
|
|
364
|
-
|
|
297
|
+
## Community and license
|
|
365
298
|
|
|
366
|
-
|
|
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).
|
|
367
302
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
## License
|
|
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).
|
|
374
308
|
|
|
375
|
-
[MIT](LICENSE)
|
|
309
|
+
[MIT license](LICENSE). [Download analytics](https://clickgems.clickhouse.com/dashboard/archunit)
|
|
310
|
+
count package fetches, not unique users.
|