SKY-Q805 · Quality, structure and performance
Architecture layer policy violation
A layer policy names the parts of a project (for example domain and web) and says which part may import which. SKY-Q805 reports every import between project modules that breaks the policy you configured under [tool.skylos.architecture].
- Languages
- Python, TypeScript, JavaScript
- Turned on by
--quality, when[tool.skylos.architecture]defineslayersandrules- Quality gate
- counted toward the gate limits (full and diff scans). Listed by default and counted toward
max_quality. - Needs
- a layer policy:
layersandrulesunder[tool.skylos.architecture] - Finding type
- review
Why it matters
Business rules that import web code can no longer run in a job, a test or a command-line tool without a web request. Layer rules keep that separation, and an import that crosses it is caught in review instead of months later.
What Skylos flags
"""Order rules.""" from shop.web.session import current_user_id def can_cancel(order, request): return order.owner_id == current_user_id(request)"""Request session helpers.""" def current_user_id(request): return request.cookies.get("user_id")[tool.skylos.architecture]layers = [ { name = "domain", patterns = ["shop.domain"] }, { name = "web", patterns = ["shop.web"] },]rules = [ { from = "domain", deny = ["web"] },]"""The shop package.""""""Business rules.""""""Web layer."""What Skylos leaves alone
"""Order rules.""" def can_cancel(order, user_id): return order.owner_id == user_id"""Order views.""" from shop.domain.orders import can_cancel def cancel_view(order, request): if not can_cancel(order, request.cookies.get("user_id")): return 403 order.cancel() return 204Why Skylos leaves it alone
The web view imports the domain rule, which the policy allows; only domain importing web is denied. The domain function now takes the user ID instead of the request.
How Skylos decides
- Runs with
--qualitywhen[tool.skylos.architecture]has bothlayersandrules. It uses the import graph of the project's Python modules (top-level imports only) and TypeScript and JavaScript modules. - Puts each module in a layer: a pattern matches the dotted module name or file path, a prefix of it, a glob, or one of its parts. When several layers match, the most specific pattern wins. Other modules are in no layer.
- For each import from a layer that has a rule: reports it when the target layer is in
deny, or whenallowis set and does not list the target layer. Withstrict = true, an import to or from a module in no layer is also reported, MEDIUM. - Reports on line 1 of the importing module, naming both modules and layers, with the rule's
severity(HIGH by default).
How to fix it
Pass the value the lower layer needs as an argument, or move the shared code into a layer both may import, so the dependency points the allowed way.
"""Order rules.""" Removed: from shop.web.session import current_user_id Removed: Removed: def can_cancel(order, request):Removed: return order.owner_id == current_user_id(request)Added: def can_cancel(order, user_id):Added: return order.owner_id == user_idWhen it can be wrong
- A short pattern can put a module in the wrong layer: it also matches any module with a name part equal to it, so the pattern
webputsshop.admin.webin the web layer too. - Imports inside functions and
if TYPE_CHECKING:blocks are not read, so those crossings are not reported.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
An inline marker does not work for this rule: with this comment on line 1 of the importing module, it is still reported.
Python """Order rules.""" # skylos: ignore[SKY-Q805] moving to the web layerignore = ["SKY-Q805"]under[tool.skylos]turns the rule off; changing the policy'sallowordenylists accepts one crossing for good.