Phase 1: DI Foundation + Monorepo Prep
Parent Epic: #116
Target: Week 1 (5-7 days)
Risk Level: Low
Build core DI infrastructure while preparing for monorepo split by extracting ready packages and moving shared types.
Goals
- Core DI components (Container, Depends(), factories)
- Type-safe dependency resolution
- Override mechanism for testing
- Extract ready packages (tokenizers, daemon)
- Move SearchResult types to core
- 100% test coverage on DI
- Zero production changes
Why This Phase Matters
This phase creates the foundation that will eliminate 75% of circular dependencies in Phase 2. It also extracts packages that are already independent, giving us quick wins.
Implementation Checklist
Part A: Package Extraction (Days 1-2)
Extract immediately (already independent):
Move shared types:
Part B: DI Infrastructure (Days 3-5)
Core components:
Container Implementation:
Provider Factories:
Key Pattern:
# Factory hides complexity
async def get_embedding_provider() -> EmbeddingProvider:
"""Factory auto-resolves from registry + settings."""
from codeweaver.common.registry import get_provider_registry
registry = get_provider_registry()
# ... all the messy logic HERE, not in services
return registry.get_embedding_provider_instance(...)
# Type alias for clean signatures
EmbeddingDep = Annotated[EmbeddingProvider, Depends(get_embedding_provider)]
Part C: Testing (Days 6-7)
Comprehensive testing:
Test examples:
def test_container_override():
container = Container()
container.register(EmbeddingProvider, get_embedding_provider)
container.override(EmbeddingProvider, MockEmbedding())
result = await container.resolve(EmbeddingProvider)
assert isinstance(result, MockEmbedding)
Part D: Documentation
Package Placement
DI infrastructure location:
- Initially:
src/codeweaver/di/ (within main package)
- Phase 3: Move to
packages/codeweaver-core/ (foundation layer)
Provider factories:
- Initially:
src/codeweaver/di/providers.py
- Phase 3: Stay with or move to
packages/codeweaver-providers/
Why Extract Packages Now?
Tokenizers & Daemon:
- ✅ Already independent (0 dependency violations)
- ✅ Perfect test cases for monorepo structure
- ✅ Quick wins that prove the approach
- ✅ Won't be affected by DI migration
SearchResult types:
- ✅ Breaks provider → agent_api dependency
- ✅ Makes core types truly foundational
- ✅ Enables clean package boundaries in Phase 3
Acceptance Criteria
Deliverables
End of Week 1:
- ✅ Working DI system (tested, documented)
- ✅ 2 packages extracted (tokenizers, daemon)
- ✅ SearchResult types moved to core
- ✅ Zero production behavior changes
- ✅ Ready for Phase 2 migration
Connection to Monorepo Strategy
This phase creates the foundation for Week 1 of the integrated strategy:
- DI foundation → Enables Phase 2 to break circular dependencies
- Package extraction → Proves monorepo structure works
- Type movement → Eliminates key coupling points
Success Metrics
Technical:
- 0 test failures
- 100% coverage on DI code
- 2 packages building independently
- SearchResult moved with 0 violations
Quality:
- Clear documentation
- Simple, obvious API design
- FastAPI-familiar patterns
- Easy to extend
Next Phase Preview
Phase 2 (#118) will use this foundation to:
- Migrate Indexer to DI → Eliminates 20+ violations
- Migrate search services → Eliminates 30+ violations
- Update tests with overrides → Simplifies testing by 80%
Reference
- Planning:
INTEGRATED_DI_MONOREPO_STRATEGY.md (Week 1)
- Examples:
plans/DI_PROVIDER_EXAMPLES.md
- Original plan:
plans/dependency-injection-architecture-plan.md
Phase 1: DI Foundation + Monorepo Prep
Parent Epic: #116
Target: Week 1 (5-7 days)
Risk Level: Low
Build core DI infrastructure while preparing for monorepo split by extracting ready packages and moving shared types.
Goals
Why This Phase Matters
This phase creates the foundation that will eliminate 75% of circular dependencies in Phase 2. It also extracts packages that are already independent, giving us quick wins.
Implementation Checklist
Part A: Package Extraction (Days 1-2)
Extract immediately (already independent):
Create
packages/codeweaver-tokenizers/src/codeweaver/tokenizers/→ packageCreate
packages/codeweaver-daemon/src/codeweaver/daemon/→ packageMove shared types:
src/codeweaver/core/search_types.pyagent_api/find_code/types.pyPart B: DI Infrastructure (Days 3-5)
Core components:
codeweaver/di/package structure__init__.py- Public APIcontainer.py- Container implementationdepends.py- Depends markerproviders.py- Provider factoriestypes.py- Type definitionsContainer Implementation:
Provider Factories:
get_embedding_provider()factoryget_sparse_embedding_provider()factory (optional)get_reranking_provider()factory (optional)get_vector_store()factoryKey Pattern:
Part C: Testing (Days 6-7)
Comprehensive testing:
Test examples:
Part D: Documentation
Package Placement
DI infrastructure location:
src/codeweaver/di/(within main package)packages/codeweaver-core/(foundation layer)Provider factories:
src/codeweaver/di/providers.pypackages/codeweaver-providers/Why Extract Packages Now?
Tokenizers & Daemon:
SearchResult types:
Acceptance Criteria
Deliverables
End of Week 1:
Connection to Monorepo Strategy
This phase creates the foundation for Week 1 of the integrated strategy:
Success Metrics
Technical:
Quality:
Next Phase Preview
Phase 2 (#118) will use this foundation to:
Reference
INTEGRATED_DI_MONOREPO_STRATEGY.md(Week 1)plans/DI_PROVIDER_EXAMPLES.mdplans/dependency-injection-architecture-plan.md