Layers
archtool can enforce layer boundaries across your modules, preventing lower-level layers from importing higher-level ones.
Built-in layers
| Layer | Allowed to import from |
|---|---|
InfrastructureLayer |
ApplicationLayer, DomainLayer |
ApplicationLayer |
DomainLayer |
DomainLayer |
nothing above itself |
Wiring with layers
from archtool.dependency_injector import DependencyInjector
from archtool.global_types import AppModule
from archtool.layers.default_layers import DomainLayer
injector = DependencyInjector(
modules_list=[AppModule("app.users")],
layers=[DomainLayer],
)
injector.inject()
If any module violates the layer rules, archtool raises TopLevelLayerUsingException at assembly time — not at runtime when the bug causes an obscure traceback.
Custom layers
Subclass Layer to define your own hierarchy: