Skip to content

[T-009] Enforce layered architecture with import-linter contracts #14

Closed

Description

@CodewithJha

Task T-009 · Milestone M1 — Foundation · Size XS · Priority P0 · Epic #1

Implements NFR-EXT-002

Branch chore/t-009-enforce-layered-architecture-with-import — one task = one branch = one PR (doc 32 §6)

Summary

Add the three import-linter contracts from doc 16 §2 so that layering violations fail make lint from the very first line of domain code.

Context / motivation

Modularity is a hard requirement (NFR-EXT-002). If the contracts exist before the code, AI agents working in parallel cannot accidentally couple the domain to infrastructure (e.g. selection importing sqlalchemy).

Scope

In scope

  • [tool.importlinter] section in backend/pyproject.toml with: (1) layers contract, (2) independence/forbidden contract for domain packages vs roboprobe.store, roboprobe.backends, roboprobe.api, fastapi, sqlalchemy, rclpy, (3) only roboprobe.bootstrap may import adapters together with application services.
  • make lint runs lint-imports.
  • A short section in CONTRIBUTING.md explaining how to read a contract failure.

Out of scope

  • CI wiring (done in T-006a by calling make lint)

Implementation guidance

  • Layers (top → bottom): roboprobe.api | roboprobe.cli → roboprobe.runner | roboprobe.experiments | roboprobe.reporting → roboprobe.selection | roboprobe.oracles | roboprobe.analysis | roboprobe.risk | roboprobe.metrics | roboprobe.scenario → roboprobe.core.
  • Use type = "layers" with containers = ["roboprobe"] and type = "forbidden" for the external libraries (set allow_indirect_imports = false where supported).
  • roboprobe.geometry and roboprobe.perturbation are kernel-level (L1) like core.
  • Add a deliberately-violating test module under tests/contract/_import_violation_example.py? No — instead document how to verify locally by temporarily adding an import.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Acceptance criteria

  • lint-imports runs in make lint and passes on the skeleton.
  • Adding import sqlalchemy to roboprobe/selection/__init__.py makes make lint fail (verified manually, noted in PR).
  • Contracts match doc 16 §2 exactly.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • CI lint job (T-006a) executes the contracts.

Dependencies

Blocked by: #12 (T-001)

Blocks: #28 (T-006a)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/pyproject.toml ([tool.importlinter] only)
  • CONTRIBUTING.md (one section)

Tiny, touches one TOML section; merge early.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-009 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 16 §2 · doc 34 §3 · ADR-0016 · doc 04 §2.1

Requirements: NFR-EXT-002 (traceability: doc 28)

External:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ciCI/CD workflowsarea:coreDomain core, plugin registry, shared typesgood first issueGood for newcomersmilestone:M1M1 — Foundationpriority:P0Critical path / blocks otherssize:XS< 2 hourstaskChild task of a milestone epictype:choreMaintenance / scaffolding

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions