Skip to content

refactor: move service/llm_keys.py out of the service layer (CODE_HEALTH #4) #41

Description

@duanyiqun

CODE_HEALTH #4 (see docs/CODE_HEALTH.md in #37).

cognifold.service.llm_keys is imported by five packages below the service layer: agent/ (7 sites), query/ (incl. query/llm.py:16), utils/, embeddings/, and config.py:161 — meaning the root config module depends on the HTTP service layer, inverting the documented layering (docs/ARCHITECTURE.md §Module Dependencies). A visible symptom: 287 function-local from cognifold... imports across src/ exist to dodge the resulting cycles.

llm_keys.py has no FastAPI dependency — it is simply misfiled.

Fix direction (small + mechanical, good first refactor):

  • Move service/llm_keys.py → cognifold/llm/keys.py (or utils/)
  • Keep a thin deprecation re-export at the old path
  • Update the ~13 import sites; promote now-safe deferred imports to top level
  • Add a note/lint guard so nothing below service/ imports from it again (rule already stated in CLAUDE.md)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions