ADR-005: Eliminate Dual Repository Implementations via Pattern #1 Migration

Date: July 14, 2025 Status: Accepted Deciders: Claude Code (Architecture Assistant), Development Team

Context

During architectural compliance audit, we discovered dual implementations of WorkflowRepository causing technical debt and pattern violations:

  1. Legacy WorkflowRepository (services/repositories/workflow_repository.py):
    • Raw SQL with asyncpg connection pools
    • Used by API endpoints for read operations
    • Does NOT inherit from BaseRepository
  2. Modern WorkflowRepository (services/database/repositories.py):
    • Inherits from BaseRepository (Pattern #1 compliant)
    • Used by orchestration engine for write operations
    • SQLAlchemy ORM with AsyncSession

Root Cause: Incomplete migration - API endpoints never migrated to RepositoryFactory pattern when orchestration engine was modernized.

Impact:

Decision

Eliminate dual repository implementations by completing the WorkflowRepository migration to achieve 100% Pattern #1 compliance.

Migration Strategy:

  1. Add missing methods to modern WorkflowRepository (find_by_id())
  2. Migrate API endpoints from legacy direct import to RepositoryFactory pattern
  3. Remove legacy implementation after verification
  4. Use TDD approach to ensure reliability

Pattern #1 Requirements:

Consequences

Positive

Negative

Neutral

Implementation Details

Phase 1: TDD Implementation

Phase 2: API Migration

Phase 3: Legacy Cleanup

Technical Issues Identified

DDD Violation: Database model to_domain() method triggers lazy loading

Database Transaction Issues: Asyncpg connection cleanup errors in test teardown

Compliance Impact

Before Migration: 71% Pattern #1 compliance (5/7 repositories) After Migration: 100% Pattern #1 compliance (6/6 active repositories)

Repository Status:

Remaining Work:

Lessons Learned

  1. Incremental Migrations Risk: Incomplete migrations create technical debt that compounds over time
  2. Interface Documentation: Different method signatures prevented obvious conflicts, hiding the duplication
  3. TDD Value: Test-driven approach caught lazy loading issues before production
  4. Eager Loading: Modern ORMs require careful relationship loading strategy for complex domain conversions

Implementation Date: July 14, 2025 Migration Duration: ~16 minutes focused work Risk Level: Low (verified with integration testing) Business Impact: None (transparent to users)