✨ Feature Request: Add predefined rules for Onion / Hexagonal and Layered Architecture (inspired by ArchUnit)
Title: ✨ Feature Request: Add predefined rules for Onion / Hexagonal and Layered Architecture (inspired by ArchUnit)
Body:
Hi 👋 and thanks for the great work on pytestarch! It's great to see a tool bringing architectural tests into Python in the spirit of [ArchUnit for Java](https://www.archunit.org/).
I'd like to propose adding predefined architecture rules for common architectural styles such as:
- Layered Architecture (e.g., Presentation → Application → Domain → Infrastructure)
- Onion / Hexagonal Architecture (Domain-centric, enforcing direction of dependencies)
Motivation
ArchUnit provides predefined rules for [Layered Architecture] and [Onion Architecture], making it easy to enforce standard patterns with minimal boilerplate. It would be amazing if pytestarch could offer something similar out-of-the-box for Python projects adopting these architectures.
These predefined rules would:
- Help teams adopt
pytestarchmore quickly - Promote clean architecture patterns
- Encourage consistency and long-term maintainability
- Lower the entry barrier for developers unfamiliar with defining architectural rules from scratch
Proposed Features
Some examples of what this could look like:
# Proposed API sketch for layered architecture
from pytestarch.dsl import predefined
def test_layered_architecture():
predefined.layered_architecture(
layers=[
"my_project.presentation",
"my_project.application",
"my_project.domain",
"my_project.infrastructure"
],
allowed_dependencies={
"presentation": ["application"],
"application": ["domain"],
"domain": [],
"infrastructure": ["application", "domain"]
}
)
# Proposed API sketch for onion architecture
def test_onion_architecture():
predefined.onion_architecture(
domain_layer="my_project.domain",
application_layer="my_project.application",
infrastructure_layer="my_project.infrastructure"
)
This would make adoption of clean architecture principles more seamless and aligns with how ArchUnit empowers Java teams.
Next Steps
If this sounds like something you'd be open to, I'd be happy to contribute with a draft implementation or help brainstorm the DSL and defaults.
Thanks again for this valuable tool!