module ArchSpec
ArchSpec turns your application’s architecture into executable checks.
You describe components, dependencies, and boundaries in an Archspec.rb file written in the ArchSpec::DSL, then run archspec check to verify every change. ArchSpec indexes Ruby source with Rubydex, uses Prism for a handful of syntax-specific facts, and never boots the app during checks. The opt-in archspec reflect command runs facts producers, such as the built-in Rails producer, in separate processes to record what the booted framework resolved; checks read those facts as data. See ArchSpec::Producer and ArchSpec::Facts::Builder to integrate another framework.
The DSL is the public API. An Archspec.rb file is evaluated directly:
architecture :rails component :services, in: "app/services/**/*.rb" services.cannot_call :render, :redirect_to, receiver: :none
See ArchSpec::DSL::Context for the top-level DSL and ArchSpec::DSL::ComponentProxy for per-component rules. See ArchSpec::Architectures for the bundled architecture presets.
You can also build a definition in plain Ruby with ArchSpec.define.
Constants
- VERSION
Public Class Methods
Source
# File lib/archspec.rb, line 73 def define(name = nil, &block) definition = Definition.new(name) definition.extend(DSL::Context) definition.instance_eval(&block) if block definition end
Builds an architecture definition from a block of DSL calls.
ArchSpec.define do component :models, in: "app/models/**/*.rb" component :controllers, in: "app/controllers/**/*.rb" models.cannot_use :controllers end
An Archspec.rb file is not written with this wrapper. Its top level is already the DSL, so bare component and architecture calls work directly. Use define when constructing a definition from Ruby, such as in a test.
Returns the ArchSpec::Definition.
Source
# File lib/archspec/producer.rb, line 134 def self.producer(name, &block) Producer.register(name, &block) end
Registers a facts producer. See ArchSpec::Producer.