You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CacheRoute currently discovers Python packages directly from the repository root ([tool.setuptools.packages.find] where = ["."]). This makes it easy for cross-component features to add new functional top-level directories such as cacheroute_compat/ and the proposed cacheroute_observability/. Each directory can be reasonable in isolation, but continued growth will make the repository root increasingly flat, fragmented, and difficult to navigate.
This also creates architectural ambiguity:
there is no single canonical Python namespace for CacheRoute;
dependency-light shared code is separated by new root package names rather than by a planned package hierarchy;
imports, CLI/module entry points, tests, Docker commands, scripts, monkeypatch targets, and documentation links can silently break when directories are moved;
root README and component READMEs can drift away from the actual repository layout;
future work may continue introducing cacheroute_<feature>/ directories without an architectural review.
This issue establishes a repository-level source layout and migration plan before continuing the runtime integration phases of #141.
The repository root should contain only a small, reviewed set of project categories such as source, tests, documentation, scripts, deployment/configuration assets, examples, and project metadata. New functional Python packages must not be added directly at the root.
Architectural requirements
1. Inventory the current repository before moving files
Produce a complete inventory of all current top-level directories and classify each as one of:
Python runtime package;
test suite;
documentation;
scripts/tooling;
deployment/configuration;
examples/assets;
generated or temporary content.
For every Python runtime package, identify:
its public import paths;
imports from other packages;
imports into it;
application entry points;
python -m usage;
Uvicorn/FastAPI module strings;
subprocess module invocation;
monkeypatch/mock target strings;
serialization or plugin strings containing module paths;
Dockerfile, Compose, shell, CI, and documentation references;
test collection and fixture dependencies.
Do not move a package until its reference inventory is recorded.
2. Define the canonical namespace and dependency direction
Use src/cacheroute/ as the canonical Python namespace.
src/cacheroute/__init__.py must remain empty or extremely lightweight. Importing cacheroute must not eagerly import FastAPI, Redis, NumPy, Torch, vLLM, LMCache, Scheduler, Proxy, Instance, KDN runtime services, or application configuration.
Dependency-light packages such as compatibility and observability must remain independently importable:
temporary compatibility re-export with a documented removal milestone; or
intentional breaking migration before the next release, with every in-repository consumer updated.
Do not leave two permanent implementations. Compatibility layers, when used, must be thin forwarding modules with tests proving that old and new imports resolve to the same objects.
The final issue state must not retain functional root package directories merely to avoid updating references.
6. Preserve runtime and command entry points
Audit and update all executable references, including but not limited to:
python3 -m ... commands;
direct script execution;
Uvicorn/FastAPI module:app strings;
console entry points in package metadata;
Docker CMD/ENTRYPOINT;
Compose commands and mounted paths;
shell scripts;
CI commands;
subprocess calls in tests;
developer documentation.
For each changed entry point, provide a before/after mapping and a smoke test.
No service should require ad-hoc sys.path insertion after the migration, except narrowly justified standalone scripts that are not installed entry points.
7. Preserve method, class, and module references
Moving files must not silently break:
public re-exports and __all__;
type annotations using qualified names;
Pydantic discriminators or serialized type names;
pickled objects, if any are in scope;
decorators or registries keyed by module/function name;
monkeypatch targets;
logging names relied upon by tests or operations;
plugin/adapter lookup strings;
relative imports inside moved packages.
Add targeted tests for any string-based method/module references discovered during the audit.
8. README and Markdown-link migration
Do not rewrite or delete existing README introductions merely because directories move.
Apply progressive disclosure:
root README.md: project-level overview only;
src/cacheroute/README.md or maintained architecture document: canonical package map and dependency rules;
component READMEs: component purpose, directory map, entry points, and links to deeper contracts/tests;
detailed protocol and workflow documentation remains in nested READMEs or doc/.
When files move:
update every relative Markdown link;
update source-file links and code examples;
update directory trees;
update commands that contain old module paths;
ensure every nested README links back to its parent architecture document;
do not introduce a second documentation root (docs/); keep the existing doc/ convention.
Add an automated repository-wide Markdown link check that handles local relative paths and anchors where practical. At minimum, all local file links must resolve.
9. Root-directory governance
Document a root-directory allowlist or equivalent architectural rule.
Required rule:
No new functional top-level directory may be added without a dedicated architecture Issue. New Python capabilities must first be placed under src/cacheroute/<domain>/ or an existing component hierarchy. Cross-component shared code must use a dependency-light, side-effect-free package under the cacheroute namespace.
Add this rule to the repository's contributor/agent guidance so future implementation sessions apply it automatically.
The root README must not be expanded with detailed package internals; it should link inward.
Context
CacheRoute currently discovers Python packages directly from the repository root (
[tool.setuptools.packages.find] where = ["."]). This makes it easy for cross-component features to add new functional top-level directories such ascacheroute_compat/and the proposedcacheroute_observability/. Each directory can be reasonable in isolation, but continued growth will make the repository root increasingly flat, fragmented, and difficult to navigate.This also creates architectural ambiguity:
cacheroute_<feature>/directories without an architectural review.This issue establishes a repository-level source layout and migration plan before continuing the runtime integration phases of #141.
Related work:
Goal
Adopt a clear, scalable Python source layout centered on one canonical namespace:
The repository root should contain only a small, reviewed set of project categories such as source, tests, documentation, scripts, deployment/configuration assets, examples, and project metadata. New functional Python packages must not be added directly at the root.
Architectural requirements
1. Inventory the current repository before moving files
Produce a complete inventory of all current top-level directories and classify each as one of:
For every Python runtime package, identify:
python -musage;Do not move a package until its reference inventory is recorded.
2. Define the canonical namespace and dependency direction
Use
src/cacheroute/as the canonical Python namespace.src/cacheroute/__init__.pymust remain empty or extremely lightweight. Importingcacheroutemust not eagerly import FastAPI, Redis, NumPy, Torch, vLLM, LMCache, Scheduler, Proxy, Instance, KDN runtime services, or application configuration.Dependency-light packages such as compatibility and observability must remain independently importable:
They must not be placed under a component package if doing so reverses dependencies for Scheduler, Proxy, KDN, Gateway, or Instance.
Define and document allowed dependency directions between at least:
Add an import-cycle or import-isolation check where practical.
3. Update packaging to a real
srclayoutUpdate
pyproject.tomlso setuptools discovers packages fromsrc, for example through the appropriate equivalents of:Verify all required package data and editable installs still work.
Test both:
python3 -m pip install -e .;The installed package must not depend on the repository root being on
sys.path.4. Migrate in reviewable phases
This issue may be completed by multiple PRs, but the final state must satisfy all acceptance criteria.
Recommended sequence:
Phase A — establish the namespace and migrate dependency-light packages
src/cacheroute/;cacheroute_compat/tosrc/cacheroute/compat/;src/cacheroute/observability/after its contract issues are corrected;core/runtime_compat.pyand all other imports to use the canonical namespace;Phase B — migrate shared and KDN packages
core/into the planned namespace without preserving eager import side effects;kdn_server/to the agreed canonical package path, preferablycacheroute.kdn, while preserving its existing HTTP/CLI operational behavior;Phase C — migrate application components
Do not perform an unreviewable blind
git mvof the whole repository in one commit.5. Import compatibility and deprecation policy
Before changing an import path, search the entire repository for:
importliband dynamic imports;For old paths such as:
choose one explicit policy:
Do not leave two permanent implementations. Compatibility layers, when used, must be thin forwarding modules with tests proving that old and new imports resolve to the same objects.
The final issue state must not retain functional root package directories merely to avoid updating references.
6. Preserve runtime and command entry points
Audit and update all executable references, including but not limited to:
python3 -m ...commands;module:appstrings;CMD/ENTRYPOINT;For each changed entry point, provide a before/after mapping and a smoke test.
No service should require ad-hoc
sys.pathinsertion after the migration, except narrowly justified standalone scripts that are not installed entry points.7. Preserve method, class, and module references
Moving files must not silently break:
__all__;Add targeted tests for any string-based method/module references discovered during the audit.
8. README and Markdown-link migration
Do not rewrite or delete existing README introductions merely because directories move.
Apply progressive disclosure:
README.md: project-level overview only;src/cacheroute/README.mdor maintained architecture document: canonical package map and dependency rules;doc/.When files move:
docs/); keep the existingdoc/convention.Add an automated repository-wide Markdown link check that handles local relative paths and anchors where practical. At minimum, all local file links must resolve.
9. Root-directory governance
Document a root-directory allowlist or equivalent architectural rule.
Required rule:
Add this rule to the repository's contributor/agent guidance so future implementation sessions apply it automatically.
The root README must not be expanded with detailed package internals; it should link inward.
10. Coordination with #141 and PR #156
Until this issue's Phase A layout is merged:
src/cacheroute/observability/or rebase it after the structural PR, according to the least risky review sequence;doc/research/issue-141-unified-observability.mdlinks;Refs #141; do not close v0.1.10-4: Add Unified v1 LMCache Gateway, Tier, Adapter, and Queue Observability #141 from a structure-only PR.Resume #141 runtime integration only after the canonical package location and import policy are merged and verified.
Required validation
The implementing PRs must report exact results for the applicable commands.
At minimum:
Build/install validation:
Add fresh-process import-isolation checks proving that importing dependency-light packages does not load heavy application modules.
Add a repository-wide stale-reference check covering old package paths in:
Any remaining old reference must be either:
Acceptance criteria
src/cacheroute/is the canonical Python source namespace.src, not the repository root.cacheroute.compatreplaces the permanent rootcacheroute_compat/implementation.cacheroute.observability, not a permanent rootcacheroute_observability/package.cacheroute/__init__.pyhas no heavy imports or application side effects.Non-goals