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 boots Rails separately to capture resolved association facts for later static checks.
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 70 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.