# Import-linter contracts for mgf-fastapi (DP-01 / WF-02 / PR-01).
#
# mgf-fastapi is a thin FastAPI-integration adapter. Its closed-box
# invariant: it depends on mgf-common + fastapi/starlette (and, behind
# the [sqlalchemy]/[livepush] extras, mgf.sqlalchemy / mgf.livepush) and
# NOTHING ELSE in the federation. These contracts make that mechanical;
# CI runs `lint-imports`.

[importlinter]
root_packages =
    mgf.fastapi
    mgf.common
# Contracts below name external top-level packages (consumer projects,
# UI frameworks) as forbidden — import-linter needs this flag to start.
include_external_packages = True

[importlinter:contract:mgf-fastapi-no-private-mgf-common]
# AP-14: the closed-box rule. mgf.fastapi MUST consume mgf.common only
# through its public surface — never reach into a private `_`-prefixed
# module. Private internals (mgf.common._lifecycle, _identity, ...) are
# refactor-at-will; importing them couples mgf.fastapi to mgf.common's
# implementation and breaks on any internal reshuffle. The public names
# (bootstrap / AppContext / bootstrap_for_test / get_request_id, ...)
# are re-exported from the `mgf.common` package root for exactly this.
# mgf.common is added to root_packages above so its private subpackages
# are nameable as forbidden targets (import-linter rejects subpackages
# of a purely-external root).
#
# import-linter wildcards can only replace a WHOLE segment (`mgf.common.*`
# would also forbid the legitimate public submodules mgf.fastapi uses —
# mgf.common.exceptions / mgf.common.observability), so the `_`-prefixed
# privates are enumerated. Adding a new private module to mgf.common? Add
# a row here too.
name = mgf.fastapi does not import mgf.common private internals (AP-14, closed-box)
type = forbidden
# Direct imports only: the public mgf.common package legitimately reaches
# its own privates internally — we only forbid mgf.fastapi reaching them
# FIRST-HAND.
allow_indirect_imports = True
source_modules =
    mgf.fastapi
forbidden_modules =
    mgf.common._doctor_snapshot
    mgf.common._env_source
    mgf.common._errors
    mgf.common._identity
    mgf.common._io
    mgf.common._lifecycle
    mgf.common._request_id
    mgf.common._test_helpers
    mgf.common._warnings

[importlinter:contract:mgf-fastapi-does-not-import-consumers]
name = mgf.fastapi does not import any consumer or unrelated sibling project
type = forbidden
source_modules =
    mgf.fastapi
forbidden_modules =
    # Consumer applications (top-level package roots).
    vmanager
    plasmamapper
    teleplasma
    inthewords
    figrecovery
    # mgf.fastapi's legitimate federation deps are mgf.common +
    # (extras) mgf.sqlalchemy / mgf.livepush — everything else is out.

[importlinter:contract:mgf-fastapi-forbids-ui-frameworks]
name = mgf.fastapi does not import any UI framework (PR-01)
type = forbidden
source_modules =
    mgf.fastapi
forbidden_modules =
    PySide6
    PyQt6
    PyQt5
    textual
    rich
    click
    flask
    django
    streamlit
    gradio
