Skip to content

docs(repo): name the cross-slice read-only import pattern in ARCHITECTURE.md #264

@w7-mgfcode

Description

@w7-mgfcode

Source

PRP-31 system review:
`.agents/system-reviews/prp-31-mlzoo-d-frontend-registry-explainability-review.md` → "System Improvement Actions" → third action ("Update docs/_base/ARCHITECTURE.md").

Why

The cross-slice read-only import pattern has now been used twice in production code (app/features/explainability/service.py:57 reading ModelRun; app/features/forecasting/service.py with the PRP-31 lazy imports) but is nowhere named in the docs. Without a named pattern in ARCHITECTURE.md, the next maintainer encountering a cross-slice import discussion has to re-derive the rationale from PR history.

The system review marked the new subsection text as DECISIONS LOCKED — the text below should land verbatim.

Change

Add a new subsection "Cross-slice read-only import pattern" to `docs/_base/ARCHITECTURE.md` (verbatim from the system review):

When a feature slice needs to call a service method or read a schema from a different feature slice (e.g., `forecasting/service.py` → `RegistryService`):

  • Import at the call site (inside the method), not at module scope, IF any of these are true:

    • The upstream slice's `schemas.py` imports a type from this slice
    • The downstream slice is loaded by `alembic/env.py` at migration time
    • The import would close an SQLAlchemy registry cycle
  • Prefer importing the service class over the ORM model — calls go through the public surface, not the persistence layer.

  • Document the lazy import with a single-line NOTE comment at the top of the file naming the cycle it breaks.

Existing precedents:

  • `app/features/explainability/service.py:57` — read-only `ModelRun` import
  • `app/features/forecasting/service.py` — lazy `RegistryService` / `JobService` / `RunStatus` imports inside `get_feature_metadata_for_*` methods (added by PRP-31; required because `RunResponse.model_family` computed_field closes the cycle at alembic cold-boot)

Definition of done

  • New subsection lands in `docs/_base/ARCHITECTURE.md`
  • PR merged to `dev` with 4 required checks green
  • Closes this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions