pub struct BoundaryConfig {
pub preset: Option<BoundaryPreset>,
pub zones: Vec<BoundaryZone>,
pub rules: Vec<BoundaryRule>,
}Expand description
Architecture boundary configuration.
Defines zones (directory groupings) and rules (which zones may import from which). Optionally uses a built-in preset as a starting point.
§Examples
use fallow_config::BoundaryConfig;
let json = r#"{
"zones": [
{ "name": "ui", "patterns": ["src/components/**"] },
{ "name": "db", "patterns": ["src/db/**"] }
],
"rules": [
{ "from": "ui", "allow": ["db"] }
]
}"#;
let config: BoundaryConfig = serde_json::from_str(json).unwrap();
assert_eq!(config.zones.len(), 2);
assert_eq!(config.rules.len(), 1);Using a preset:
use fallow_config::BoundaryConfig;
let json = r#"{ "preset": "layered" }"#;
let mut config: BoundaryConfig = serde_json::from_str(json).unwrap();
config.expand("src");
assert_eq!(config.zones.len(), 4);
assert_eq!(config.rules.len(), 4);Fields§
§preset: Option<BoundaryPreset>Built-in architecture preset. When set, expands into default zones and rules.
User-defined zones and rules merge on top: zones with the same name replace
the preset zone; rules with the same from replace the preset rule.
Preset patterns use {rootDir}/{zone}/** where rootDir is auto-detected
from tsconfig.json (falls back to src).
Note: preset patterns are flat (src/<zone>/**). For monorepos with
per-package source directories, define zones explicitly instead.
zones: Vec<BoundaryZone>Named zones mapping directory patterns to architectural layers.
rules: Vec<BoundaryRule>Import rules between zones. A zone with a rule entry can only import from the listed zones (plus itself). A zone without a rule entry is unrestricted.
Implementations§
Source§impl BoundaryConfig
impl BoundaryConfig
Sourcepub fn expand(&mut self, source_root: &str)
pub fn expand(&mut self, source_root: &str)
Expand the preset (if set) into zones and rules, merging user overrides on top.
source_root is the directory prefix for preset zone patterns (e.g., "src").
After expansion, self.preset is cleared and all zones/rules are explicit.
Merge semantics:
- User zones with the same name as a preset zone replace the preset zone entirely.
- User rules with the same
fromas a preset rule replace the preset rule. - User zones/rules with new names add to the preset set.
Sourcepub fn expand_auto_discover(&mut self, project_root: &Path) -> Vec<LogicalGroup>
pub fn expand_auto_discover(&mut self, project_root: &Path) -> Vec<LogicalGroup>
Expand auto-discovered boundary groups into concrete child zones.
A zone with autoDiscover: ["src/features"] discovers the immediate
child directories below src/features and emits child zones named
zone_name/child. Rules that reference the logical parent are expanded
to all discovered children. If the parent also has explicit patterns,
it is kept after the children as a fallback so child directories remain
isolated by first-match classification. The parent fallback rule
automatically allows its discovered children so top-level barrels can
re-export child modules without relaxing sibling isolation on the child
rules.
Returns one LogicalGroup per pre-expansion zone that carried a
non-empty autoDiscover, in user-declaration order. The caller (the
resolution pipeline) stashes the result onto
ResolvedBoundaryConfig::logical_groups for fallow list --boundaries --format json to render. Discarding the return is fine
for callers that only need the expansion side effect (classification);
the data is regenerated on the next run.
Duplicate parent zone name behavior: when two BoundaryZone
declarations share a name and both carry autoDiscover, their
discovered children merge into a single LogicalGroup whose
auto_discover concatenates both source path lists in declaration
order. This mirrors the existing rule-side merge behavior (both rules
expand to the same union of child names). A tracing::warn! surfaces
the duplicate at config-load time so the user can deduplicate the
source; the merged behavior is a soft default rather than a hard
rejection so existing configs continue to load.
Source§impl BoundaryConfig
impl BoundaryConfig
Sourcepub fn preset_name(&self) -> Option<&str>
pub fn preset_name(&self) -> Option<&str>
Return the preset name if one is configured but not yet expanded.
Sourcepub fn validate_root_prefixes(&self) -> Vec<RedundantRootPrefix>
pub fn validate_root_prefixes(&self) -> Vec<RedundantRootPrefix>
Validate that no zone’s pattern redundantly includes its root
prefix. Patterns are resolved relative to the zone root, so prefixing
the pattern with the same root double-prefixes the path and never
matches.
The rendered diagnostic carries the legacy
FALLOW-BOUNDARY-ROOT-REDUNDANT-PREFIX tag via
ZoneValidationError’s Display impl, so CI logs grepping for the
old text continue to work.
Sourcepub fn validate_zone_references(&self) -> Vec<UnknownZoneRef>
pub fn validate_zone_references(&self) -> Vec<UnknownZoneRef>
Validate that all zone names referenced in rules are defined in zones.
Walks every zone-reference surface on BoundaryRule: from, allow,
and allow_type_only. An unknown zone in allow_type_only silently
behaves as “not allowed” at runtime, so it MUST surface here for parity
with the existing allow-side diagnostic.
Sourcepub fn resolve(&self) -> ResolvedBoundaryConfig
pub fn resolve(&self) -> ResolvedBoundaryConfig
Resolve into compiled form with pre-built glob matchers.
User patterns were validated at config load time
(see FallowConfig::validate_user_globs).
Trait Implementations§
Source§impl Clone for BoundaryConfig
impl Clone for BoundaryConfig
Source§fn clone(&self) -> BoundaryConfig
fn clone(&self) -> BoundaryConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoundaryConfig
impl Debug for BoundaryConfig
Source§impl Default for BoundaryConfig
impl Default for BoundaryConfig
Source§fn default() -> BoundaryConfig
fn default() -> BoundaryConfig
Source§impl<'de> Deserialize<'de> for BoundaryConfig
impl<'de> Deserialize<'de> for BoundaryConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for BoundaryConfig
impl JsonSchema for BoundaryConfig
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more