The code works. The architecture is still wrong.
An AI refactor replaces UserRepository with a direct database query inside user.service.ts. Types pass. Tests pass. But the shortcut breaks the data-access boundary that later agents will copy. Mneme names ADR-004 and blocks the change in strict mode.
Working code can still break the architecture.
This trace ends at the block. It shows the failure a team needs to catch, not a made-up recovery.
ADR-004 · Repository pattern is the only data-access boundary. Services depend on repository interfaces. Direct database imports, raw SQL, and ORM calls stay inside repository implementations.
-
01 Decision
The repository boundary is recorded with a service-layer file scope and explicit anti-patterns.
ADR-004 · scope: **/*.service.ts -
02 GuidanceN/A
This evidence is a post-generation CI check; it does not contain a pre-flight guidance event.
Not present in this reproduction -
03 Violation
The service drops its repository dependency and opens a direct SQL path.
+ this.db.query('SELECT * FROM users ...') -
04 Deny / warnDENY
Strict mode matches the direct access pattern, names the file, and exits non-zero.
FAIL [ADR-004] · user.service.ts · exit 2 -
05 CorrectionN/A
The evidence does not include the refactor back through
UserRepository.Not demonstrated -
06 AllowN/A
A clean follow-up check is not part of this supporting example.
Not demonstrated
Run it yourself
Reproduce the strict boundary check
Record ADR-004, save the proposed service diff, and evaluate it in strict mode.
pipx install "mneme-hq>=0.5.1"
mneme check --mode strict \
--memory .mneme/project_memory.json \
--input user-service.diff --query "repository data access"
# FAIL [ADR-004] ยท exit 2
This is a command-level reproduction. The page does not claim a bundled corrected fixture.
What happened
Linters, types, and behavior tests can all pass while the service boundary is being dismantled.
Once direct SQL becomes precedent, later agents copy it and the repository layer stops functioning as a contract.
The verdict names ADR-004 and the offending file, so an override must become an explicit decision.
Common questions
Why is this a DENY?
Direct data access from a service invalidates the boundary ADR-004 exists to protect. Its downstream cost compounds, so strict mode returns a non-zero failure.
Does the denial block the pull request?
Yes, when mneme check --mode strict is wired into the required CI workflow.
Why are correction and allow absent?
The supplied trace ends at the block. A corrected diff and clean rerun belong in a future reproduction, not in a fabricated ending.
Keep the boundary executable.
Record the pattern once, then enforce it in the editor and at the merge gate.
pipx install "mneme-hq>=0.5.1"