Skip to main content

SKY-Q805 · Quality, structure and performance

Architecture layer policy violation

Varies

The catalog gives no severity. Each rule of the policy sets its own severity (HIGH when it sets none); a module outside every layer under strict = true is MEDIUM.

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] defines layers and rules
Quality gate
counted toward the gate limits (full and diff scans). Listed by default and counted toward max_quality.
Needs
a layer policy: layers and rules under [tool.skylos.architecture]
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

shop/domain/orders.py · PythonReported on line 1
"""Order rules.""" from shop.web.session import current_user_id  def can_cancel(order, request):    return order.owner_id == current_user_id(request)
shop/web/session.py · Python
"""Request session helpers."""  def current_user_id(request):    return request.cookies.get("user_id")
pyproject.toml · TOML
[tool.skylos.architecture]layers = [  { name = "domain", patterns = ["shop.domain"] },  { name = "web", patterns = ["shop.web"] },]rules = [  { from = "domain", deny = ["web"] },]
shop/__init__.py · Python
"""The shop package."""
shop/domain/__init__.py · Python
"""Business rules."""
shop/web/__init__.py · Python
"""Web layer."""

What Skylos leaves alone

shop/domain/orders.py · Python
"""Order rules."""  def can_cancel(order, user_id):    return order.owner_id == user_id
shop/web/views.py · Python
"""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 204

pyproject.toml: same as in the flagged example.

shop/__init__.py: same as in the flagged example.

shop/domain/__init__.py: same as in the flagged example.

shop/web/__init__.py: same as in the flagged example.

Why 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

  1. Runs with --quality when [tool.skylos.architecture] has both layers and rules. It uses the import graph of the project's Python modules (top-level imports only) and TypeScript and JavaScript modules.
  2. 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.
  3. For each import from a layer that has a rule: reports it when the target layer is in deny, or when allow is set and does not list the target layer. With strict = true, an import to or from a module in no layer is also reported, MEDIUM.
  4. 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.

shop/domain/orders.py · Python · the fix, against the flagged file
"""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_id

When 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 web puts shop.admin.web in 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 layer
  • ignore = ["SKY-Q805"] under [tool.skylos] turns the rule off; changing the policy's allow or deny lists accepts one crossing for good.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.