Layer boundary enforcement for architectural constraints
| Tier | foundation |
| Role | unclassified (baselined) |
| Path | crates/foundation/layers |
| Edition | 2021 |
| Targets | foundation_layers |
| Public items | 20 across 0 modules |
| Tests | 26 |
What it is for
Layer boundary enforcement for architectural constraints.
This crate provides types and traits for enforcing architectural layers at compile time and runtime. It helps maintain clean separation between:
- Foundation (Layer 0): Core types, no dependencies
- Infrastructure (Layer 1): Database, caching, external services
- Domain (Layer 2): Business logic and entities
- Application (Layer 3): Use cases, orchestration
- Presentation (Layer 4): HTTP, CLI, UI
Capabilities
crate root
Layer boundary enforcement for architectural constraints.
| Item |
|---|
fn validate_dependencies(source : Layer, dependencies : & Dependency) -> Result <()> |
Component
Layer boundary enforcement for architectural constraints.
| Item |
|---|
pub struct Component |
Component :: fn new(name : impl Into <String>, layer : Layer) -> Self |
Component :: fn with_dependency(mut self, dep : Dependency) -> Self |
Component :: fn validate(& self) -> Result <()> |
Dependency
Layer boundary enforcement for architectural constraints.
| Item |
|---|
pub struct Dependency |
Dependency :: fn new(name : impl Into <String>, layer : Layer, path : impl Into <String>) -> Self |
Layer
Layer boundary enforcement for architectural constraints.
| Item |
|---|
pub enum Layer |
Layer :: const fn level(& self) -> u8 |
Layer :: const fn can_depend_on(& self, target : Layer) -> bool |
Layer :: fn validate_dependency(& self, target : Layer) -> Result <()> |
Layer :: const fn name(& self) -> & 'static str |
Layer :: const fn description(& self) -> & 'static str |
Layer :: const fn all() -> Layer; 5 |
Layer :: fn allowed_dependencies(& self) -> Vec <Layer> |
Layer :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
Layer :: fn from_str(s : & str) -> Result <Self> |
LayerError
Layer boundary enforcement for architectural constraints.
| Item |
|---|
pub enum LayerError |
Layered
Layer boundary enforcement for architectural constraints.
| Item |
|---|
pub trait Layered |
Result
Layer boundary enforcement for architectural constraints.
| Item |
|---|
pub type Result<T>: std::result::Result <T, LayerError> |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum LayerError | Errors that can occur with layer violations. |
pub type Result<T>: std::result::Result <T, LayerError> | Result type for layer operations. |
pub enum Layer | Architectural layer in the application. |
Layer :: const fn level(& self) -> u8 | Returns the numeric level of the layer. |
Layer :: const fn can_depend_on(& self, target : Layer) -> bool | Returns true if this layer can depend on the target layer |
Layer :: fn validate_dependency(& self, target : Layer) -> Result <()> | Validates that this layer can depend on the target layer |
Layer :: const fn name(& self) -> & 'static str | Returns the layer name. |
Layer :: const fn description(& self) -> & 'static str | Returns a description of what belongs in this layer. |
Layer :: const fn all() -> Layer; 5 | Returns all layers. |
Layer :: fn allowed_dependencies(& self) -> Vec <Layer> | Returns layers that this layer can depend on. |
Layer :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
Layer :: fn from_str(s : & str) -> Result <Self> | — |
pub trait Layered | Trait for types that belong to a specific layer. |
pub struct Dependency | A dependency declaration with layer information. |
Dependency :: fn new(name : impl Into <String>, layer : Layer, path : impl Into <String>) -> Self | Creates a new dependency. |
fn validate_dependencies(source : Layer, dependencies : & Dependency) -> Result <()> | Validates a list of dependencies against a source layer |
pub struct Component | A component with layer information. |
Component :: fn new(name : impl Into <String>, layer : Layer) -> Self | Creates a new component. |
Component :: fn with_dependency(mut self, dep : Dependency) -> Self | Adds a dependency. |
Component :: fn validate(& self) -> Result <()> | Validates all dependencies |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier foundation with 27 other crates: foundation-audit-log, foundation-basemodels, foundation-bounded-io, foundation-conversation-closure, foundation-crypto-sign, foundation-decisioning, foundation-encounter-vocabulary, foundation-fs-metadata, … (27 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | foundation |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/foundation/layers |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
serde | ^1 | derive | no | always |
thiserror | ^2 | — | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
serde_json | ^1 | — | no | always |
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. Nothing in this workspace.
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | foundation_layers | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
LayerError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 26 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 7 | 0 | 0 |
What the tests establish, by name:
test_assert_layer_macro_ok—src/lib.rstest_component_new—src/lib.rstest_component_serialization—src/lib.rstest_component_validate_ok—src/lib.rstest_component_validate_violation—src/lib.rstest_component_with_dependency—src/lib.rstest_dependency_new—src/lib.rstest_invalid_layer_error—src/lib.rstest_layer_all—src/lib.rstest_layer_allowed_dependencies—src/lib.rstest_layer_can_depend_on_lower—src/lib.rstest_layer_can_depend_on_self—src/lib.rstest_layer_cannot_depend_on_higher—src/lib.rstest_layer_description—src/lib.rstest_layer_display—src/lib.rstest_layer_error_display—src/lib.rstest_layer_from_str—src/lib.rstest_layer_from_str_invalid—src/lib.rstest_layer_level—src/lib.rstest_layer_name—src/lib.rstest_layer_ordering—src/lib.rstest_layer_serialization—src/lib.rstest_layer_validate_dependency_ok—src/lib.rstest_layer_validate_dependency_violation—src/lib.rstest_validate_dependencies_ok—src/lib.rstest_validate_dependencies_violation—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 18 | 20 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 18
"No rustdoc detected" : 2
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 497 |
| Code lines | 356 |
| Public API items | 20 |
| Public modules | 0 |
| Tests | 26 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 2 |
| Workspace reverse dependencies | 0 |
pie showData
title Public API by kind
"enum" : 2
"function" : 1
"method" : 13
"struct" : 2
"trait" : 1
"type alias" : 1
pie showData
title Rust source composition
"Code" : 356
"Blank or comment" : 141
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.