Skip to content

Commit 8e36a54

Browse files
authored
feat: reorganize services and specs for src cleanup (#165)
## Summary - collapse AWS service modules under `quilt_mcp.services` and remove the empty `quilt_mcp.aws` namespace - refresh specs for issue #164, documenting inventory, design, and checklists for the new directory layout - align with latest main branch changes (new coverage tooling, reorganized tests) and ensure `make test` passes ## Testing - make test
1 parent aa6847d commit 8e36a54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+499
-200
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- **Testing**: Updated make coverage target to run comprehensive multi-suite analysis with threshold validation
2323
- **CI Performance**: PR feedback time reduced to <5 minutes with single Python version testing
2424
- **Release Safety**: Production releases now require successful main branch validation via workflow dependencies
25+
- **Source Layout**: Collapsed legacy `quilt_mcp.aws` namespace into `quilt_mcp.services`, updated tests/docs, and added full spec package describing the src cleanup (Issue #164)
2526

2627
## [0.6.6] - 2025-09-18
2728

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Requirements - Cleanup src Layout
3+
4+
**GitHub Issue**: #164 "cleanup src"
5+
**Problem Statement**: The `src/` directory contains numerous single-file subfolders that add unnecessary nesting. We need a clearer layout without gratuitous behavioral changes and with all references updated accordingly.
6+
7+
## User Stories
8+
9+
1. **As a maintainer**, I want related modules grouped in meaningful packages so that I can navigate the codebase quickly.
10+
2. **As a contributor**, I want module paths to reflect actual project structure so that refactoring and new features can be implemented with less guesswork.
11+
3. **As a release engineer**, I want configuration and documentation references to stay accurate after the reorganization so that builds and published artifacts remain reliable.
12+
13+
## Acceptance Criteria
14+
15+
1. Identify single-file directories under `src/` that can be collapsed without losing organizational clarity.
16+
2. Consolidate modules into a rational structure that maintains behavior (imports, entry points, CLI) with minimal churn.
17+
3. Update all code, configuration, and top-level documentation references impacted by the new structure (excluding historical specs).
18+
4. Ensure automated tests, linting, and packaging workflows continue to pass after the reorganization.
19+
5. Communicate the new layout to developers via updated operational docs where necessary (e.g., `CLAUDE.md`).
20+
21+
## Success Metrics
22+
23+
1. Directory depth under `src/` is reduced for previously single-file packages while preserving semantic grouping.
24+
2. No runtime regressions or import errors occur when running `make test` and `make lint`.
25+
3. Contributors can locate modules using names that match their function without redundant folder indirection.
26+
4. Documentation that references affected paths is updated on the same branch with no broken links.
27+
28+
## Open Questions
29+
30+
1. Are there historical reasons certain modules live in their own package that we must preserve (e.g., for dynamic imports)?
31+
2. Do any third-party integrations depend on the existing package paths outside this repository (e.g., published API packages)?
32+
3. Are there additional operational docs beyond `CLAUDE.md` and top-level README that reference the current layout?
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Analysis - Cleanup src Layout
3+
4+
**Reference**: Requirements in `spec/164-cleanup-src/01-requirements.md`
5+
6+
## Current Architecture
7+
8+
1. The `src/` tree exposes the `quilt_mcp` package along with `deploy/` assets and the CLI entry point `main.py`.
9+
2. Within `quilt_mcp`, major domains already exist: `tools/`, `search/`, `visualization/`, `optimization/`, `aws/`, `telemetry/`, `validators/`, and `services/`.
10+
3. Several subpackages (e.g., `search/backends`, `visualization/generators`) are richly populated and use deeper hierarchies, while others (`services/`, `validators/`, `aws/`) are shallow wrappers around one or two modules.
11+
4. Some directories (such as `config/`, `operations/`, `utilities/`) appear to be stubs or legacy placeholders with no tracked `.py` files, though compiled bytecode artifacts remain from previous executions.
12+
5. Tests (see `tests/`) and runtime modules import functionality directly from current module paths (e.g., `quilt_mcp.tools.package_ops`, `quilt_mcp.services.quilt_service`).
13+
14+
## Implementation Idioms & Conventions
15+
16+
1. Public APIs are exposed via module-level functions and classes; consumers import from the package path (no dynamic discovery).
17+
2. `__init__.py` files typically re-export symbols (especially in `tools` and `visualization`) to simplify imports.
18+
3. Behavior-driven tests patch nested module paths extensively (e.g., `@patch("quilt_mcp.services.quilt_service.quilt3")`), coupling tests to the current directory layout.
19+
4. Configuration for packaging and entry points (e.g., `pyproject.toml`, `setup.cfg`, `Makefile`) relies on module paths inside `src/`.
20+
21+
## System Constraints & Limitations
22+
23+
1. Reorganization must preserve import paths consumed by published packages or external automation; breaking changes would ripple through tests and possibly deployed clients.
24+
2. Build tooling expects packages under `src/` following the standard `src-layout`; moving files requires updating `pyproject` metadata if package names change.
25+
3. Without runtime guards, collapsing packages risks circular imports if formerly separated modules now reside in a single file/scope.
26+
4. Tests assume module paths for patching; failing to realign them will cause import errors at test runtime.
27+
28+
## Technical Debt & Refactoring Opportunities
29+
30+
1. Single-module subpackages (e.g., `services`, `telemetry`, `aws`) add unnecessary nesting and cognitive overhead when the submodule names already convey domain context.
31+
2. Empty placeholder packages (`config`, `operations`, `utilities`) indicate either dead code or missing implementations that should be removed or populated.
32+
3. Some modules (e.g., `version_sync.py`, `utils.py`) serve as catch-alls; reorganizing could clarify their relationships to other domains.
33+
4. Lack of documentation about rationale for the current layout makes it difficult to distinguish intentional boundaries from historical baggage.
34+
35+
## Gaps Between Current State & Requirements
36+
37+
1. No current mapping documents which directories are candidates for consolidation or removal.
38+
2. There is no automated safeguard ensuring docs/configs reference the correct module paths after refactors.
39+
3. Tests cover behavior but may not assert on module locations; restructuring risks silent breakage if certain modules are loaded dynamically.
40+
41+
## Architectural Challenges
42+
43+
1. Maintaining backward-compatible import paths may require alias modules (`__init__` exports) during transition, which must be planned carefully to avoid duplication.
44+
2. Consolidating packages may affect relative imports inside modules; re-evaluating import strategy is necessary to prevent circular dependencies.
45+
3. Updating top-level documentation (e.g., `CLAUDE.md`) is mandatory per guidelines, yet we must avoid modifying historical specs.
46+
4. Ensuring minimal churn means batching logical moves and keeping diffs focused, but file moves inherently create large diffs and require precise test coverage.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Specifications - Cleanup src Layout
3+
4+
**Reference**: Analysis in `spec/164-cleanup-src/02-analysis.md`
5+
6+
## Desired End State
7+
8+
1. Consolidated `src/` structure where single-module directories are either promoted into parent packages or merged into cohesive modules without losing semantic clarity.
9+
2. All Python imports, entry points, configuration references, and documentation are updated to match the new layout.
10+
3. Tests, linting, and packaging workflows run green without requiring changes to behavioral expectations.
11+
4. Historical specifications remain untouched; new documentation (e.g., `CLAUDE.md`) captures rationale for directory moves.
12+
13+
## Scope & Boundaries
14+
15+
- **In Scope**: Python modules under `src/quilt_mcp`, associated tests, CLI entry points, build configuration, top-level operational docs.
16+
- **Out of Scope**: Historical spec documents under `spec/`, release history, or changes to public API semantics.
17+
18+
## Engineering Constraints
19+
20+
1. Maintain import compatibility by either preserving module names or providing backward-compatible alias exports where possible.
21+
2. Keep diffs focused on file moves and necessary path updates; avoid opportunistic refactors unrelated to directory cleanup.
22+
3. Ensure refactoring steps follow TDD: introduce failing tests capturing expected behavior before moving code.
23+
4. Preserve package namespace integrity required by packaging metadata (`pyproject.toml`, `setup.cfg`).
24+
25+
## Success Criteria
26+
27+
1. Macroscopically, `src/quilt_mcp` exhibits a clear, intention-revealing hierarchy with minimal single-file directories.
28+
2. `make test` and `make lint` complete successfully post-change without flaky behavior.
29+
3. Tests remain behavior-driven; no direct assertions on file locations unless required to guard critical imports.
30+
4. Documentation explicitly notes the new module organization to aid future contributors.
31+
32+
## Risks & Mitigations
33+
34+
1. **Risk**: Breaking external imports. **Mitigation**: Provide compatibility shims or communicate intentional renames within the package where unavoidable.
35+
2. **Risk**: Missing updates in configuration or docs. **Mitigation**: Search/replace guided by checklist; run lint/tests to detect stale paths.
36+
3. **Risk**: Large, hard-to-review diffs. **Mitigation**: Execute moves in small, well-tested episodes guided by the workflow checklist.
37+
4. **Risk**: Circular imports introduced by moves. **Mitigation**: Design target structure carefully and adjust import direction to maintain acyclic dependencies.

spec/164-cleanup-src/04-phases.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Phases - Cleanup src Layout
3+
4+
**Reference**: Specifications in `spec/164-cleanup-src/03-specifications.md`
5+
6+
## Phase 1 - Inventory & Safety Net
7+
8+
- Audit `src/quilt_mcp` to catalog single-file directories and intended targets for consolidation.
9+
- Add behavior-driven tests (or expand existing ones) that lock in import expectations and key tool discovery flows before restructuring.
10+
- Document findings and planned moves without touching production code yet.
11+
12+
## Phase 2 - Restructure Core Packages
13+
14+
- Collapse identified single-file directories (e.g., `services`, `aws`, `telemetry`) into clearer module layouts while preserving behavior.
15+
- Adjust imports, configuration, and docs to align with the new structure.
16+
- Provide compatibility layers or re-export patterns where necessary to avoid breaking consumer imports.
17+
- Update operational documentation (`CLAUDE.md`) with the new layout insights.
18+
19+
## Phase 3 - Cleanup & Validation
20+
21+
- Remove obsolete placeholder packages (`config`, `operations`, `utilities`) or repurpose them with clear intent.
22+
- Run full lint/test/coverage suite to confirm stability.
23+
- Finalize checklists, ensure compatibility notes are recorded, and prepare for integration.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Phase 1 Design - Inventory & Safety Net
3+
4+
## Objectives
5+
6+
1. Catalog single-file directories and justify whether they should be merged or retained.
7+
2. Strengthen behavior-driven tests that exercise module discovery/import flows to prevent regressions during restructuring.
8+
3. Produce an inventory artifact that informs later phases without touching production code yet.
9+
10+
## Key Activities
11+
12+
- Traverse `src/quilt_mcp` and document the current tree, identifying empty or placeholder packages.
13+
- Review existing tests (e.g., `tests/unit/test_utils.py`, `tests/e2e/test_unified_search.py`) to confirm coverage of import-heavy workflows.
14+
- Add or enhance tests that assert the MCP server exposes expected tool registrations via public APIs (not file paths).
15+
- Record decisions in the phase checklist so reorganizations in later phases are backed by explicit rationale.
16+
17+
## Deliverables
18+
19+
- Updated tests capturing the expected behavior of tool discovery/imports (failing first per TDD).
20+
- Phase 1 checklist entries populated with inventory findings and test status.
21+
- No production code changes yet; only tests and documentation produced in this phase.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Phase 1 Episodes - Inventory & Safety Net
3+
4+
## Episode 1 - Capture Current Layout
5+
6+
- Script or document the existing `quilt_mcp` directory tree with annotations on single-file directories.
7+
- Record legacy/empty packages, noting if they are safe to remove or need further investigation.
8+
9+
## Episode 2 - Strengthen Import Behavior Tests
10+
11+
- Add behavior-driven tests that exercise tool discovery/import routines to fail if expected modules disappear.
12+
- Use factories/fixtures to interact with the public API (e.g., `quilt_mcp.utils` discovery functions) rather than importing private modules directly.
13+
14+
## Episode 3 - Catalogue External References
15+
16+
- Search configuration (`pyproject.toml`, `setup.cfg`, `Makefile`) and docs (`CLAUDE.md`, README) for sensitive import paths.
17+
- Document findings and potential impact areas in the phase checklist.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Phase 1 Checklist - Inventory & Safety Net
3+
4+
- [x] Inventory single-file directories in `src/quilt_mcp` and document decisions
5+
- [x] Confirm existing tests cover critical import paths
6+
- [x] Add new behavior-driven tests for tool discovery/imports (failing first)
7+
- [ ] Update checklist with catalog of external references (configs/docs)
8+
- [x] Run `make test-unit` to validate safety net additions
9+
10+
## Inventory Notes
11+
12+
- Collapsible candidates: `services/` (single functional module), `aws/` (two concrete modules plus `__init__`), `telemetry/` (multi-module but may expose single entry point), `validators/` (three validator modules sharing purpose).
13+
- Empty legacy packages: `config/`, `operations/`, `operations/quilt3/`, and `utilities/` (plus `utilities/aws/`) contain no tracked `.py` files; safe removal requires confirming no external imports rely on them.
14+
- Rich subpackages to keep structured: `search/` hierarchy, `visualization/` (analyzers/generators/layouts/utils), and `optimization/` already house multiple cohesive modules.
15+
16+
## Test Notes
17+
18+
- Confirmed existing unit/integration tests exercise imports for service-layer functionality.
19+
- Added failing test (`TestQuiltServiceAuthentication.test_services_package_exports_core_classes`) to require `quilt_mcp.services` to expose service classes directly.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Phase 2 Design - Restructure Core Packages
3+
4+
## Objectives
5+
6+
1. Collapse targeted single-module directories into a clearer hierarchy while preserving public behavior.
7+
2. Provide compatibility exports or adapters so existing imports remain functional.
8+
3. Update code, configs, and documentation to reflect the new layout.
9+
10+
## Target Structure (Tentative)
11+
12+
- Flatten service implementations under `quilt_mcp/services/` so core classes (`QuiltService`, `AthenaQueryService`, permission discovery primitives) share a package.
13+
- Delete the legacy `quilt_mcp/aws/` namespace entirely after migrating modules to `services/`.
14+
- Evaluate `telemetry/` and `validators/` to determine whether consolidating into single modules improves clarity or whether subpackages remain justified.
15+
- Remove empty packages (`config`, `operations`, `utilities`) after ensuring no references depend on them.
16+
17+
## Key Activities
18+
19+
- Move/rename files using tooling that preserves git history where possible.
20+
- Adjust import statements across the codebase (tests, runtime, configs) to reference the new module locations.
21+
- Introduce compatibility imports (e.g., re-export moved symbols from legacy module paths) when necessary to keep changes non-breaking.
22+
- Keep changes behavior-focused; defer stylistic refactors unless required to maintain functionality.
23+
24+
## Deliverables
25+
26+
- Updated module layout matching the agreed structure.
27+
- Passing tests and lint checks with updated imports.
28+
- Documentation updates (especially `CLAUDE.md`) describing the new organization and compatibility notes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!-- markdownlint-disable MD013 -->
2+
# Phase 2 Episodes - Restructure Core Packages
3+
4+
## Episode 1 - Services Module Consolidation
5+
6+
- Co-locate `QuiltService`, `AthenaQueryService`, and permission discovery primitives under the `quilt_mcp.services` package.
7+
- Update tests and runtime references to import from the new structure.
8+
9+
## Episode 2 - Remove Legacy AWS Namespace
10+
11+
- Delete the `quilt_mcp/aws` package after migrating modules.
12+
- Ensure all imports reference `quilt_mcp.services` equivalents.
13+
14+
## Episode 3 - Telemetry & Validators Review
15+
16+
- Decide whether telemetry and validator packages remain multi-module or should expose simplified entry points.
17+
- Apply renames/moves as needed, adding compatibility exports.
18+
19+
## Episode 4 - Documentation & Config Updates
20+
21+
- Update configuration files and `CLAUDE.md` with the new structure.
22+
- Verify no stale paths remain via targeted search.

0 commit comments

Comments
 (0)