Skip to main content
← Back to list
01Issue
FeatureShippedSwamp CLI
Assigneesstack72

#229 DDD: refactor data services to depend on domain-side ports instead of infrastructure types

Opened by stack72 · 5/4/2026· Shipped 5/4/2026

Problem

`src/domain/data/data_rename_service.ts` and `src/domain/data/data_delete_service.ts` (added in issue #181) both import types directly from `src/infrastructure/persistence/`:

```ts import type { UnifiedDataRepository } from "../../infrastructure/persistence/unified_data_repository.ts"; import type { YamlDefinitionRepository } from "../../infrastructure/persistence/yaml_definition_repository.ts"; ```

These imports violate the dependency-inversion principle the rest of the codebase aims for. The DDD layer-rules ratchet at `integration/ddd_layer_rules_test.ts` records them as known violations — the count is currently 27 (it was bumped from 26 when issue #181 added the data delete service to match the existing rename pattern).

The interfaces (`UnifiedDataRepository`, `DefinitionRepository`) live alongside their implementations in the infrastructure layer rather than in the domain layer where they should live per dependency-inversion.

Proposed Solution

  1. Lift the `UnifiedDataRepository` and `DefinitionRepository` interfaces (the abstract contracts, not the implementations) into `src/domain/data/` and `src/domain/definitions/` respectively.
  2. Update the infrastructure files (`src/infrastructure/persistence/unified_data_repository.ts`, `src/infrastructure/persistence/yaml_definition_repository.ts`) to import the interfaces from domain and `implements` them.
  3. Update both data services (`data_rename_service.ts`, `data_delete_service.ts`) to import only from the domain side.
  4. Decrement `KNOWN_DOMAIN_INFRA_VIOLATIONS` in `integration/ddd_layer_rules_test.ts` by 2.

Out of Scope

  • The other 25 known violations in the ratchet — this issue is scoped to the two data services.
  • Service constructor signatures and call sites — type names stay identical, only their import paths change.

Alternatives Considered

  • Leave as-is — but the violation count grows linearly with every new data service following the rename/delete pattern. The fix is a one-time refactor that unblocks future data services.
  • Move the implementations into domain — wrong direction; infrastructure types belong in infrastructure, only the abstract contracts should sit in domain.

Acceptance

  • `data_rename_service.ts` and `data_delete_service.ts` no longer appear in the violations list.
  • `KNOWN_DOMAIN_INFRA_VIOLATIONS` is 25 (down from 27).
  • All existing tests still pass.
02Bog Flow
OPENTRIAGEDIN PROGRESSSHIPPED+ 1 MOREASSIGNED+ 4 MOREREVIEW+ 3 MOREPR_MERGEDSHIPPED

Shipped

5/4/2026, 10:31:09 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
stack72 assigned stack725/4/2026, 9:12:25 PM

Sign in to post a ripple.