DEV Community

Cover image for How I Stopped AI Codebases From Collapsing: Architecture Drift vs. Deterministic Slices
vibecodiq
vibecodiq

Posted on

How I Stopped AI Codebases From Collapsing: Architecture Drift vs. Deterministic Slices

AI coding tools are amazing… until they silently break your architecture.

This article shows exactly why drift happens — and how ASA Core v1.0 fixes it with deterministic slice-based generation.


1. The Real Pain: AI Code Is Not Deterministic

Run the same instruction twice and you get different outputs:

# Version 1
class LoginService:
    def execute(self): ...

# Version 2
class Login:
    def run(self): ...
Enter fullscreen mode Exit fullscreen mode

Same prompt → different structure → instant drift.


2. Drift Gets Worse When Specs Change

Traditional workflow:

edit spec
↓
Regenerate
↓
💀 Custom code overwritten
Enter fullscreen mode Exit fullscreen mode

So engineers stop regenerating.
Schemas drift from implementation.
Tests no longer match the API.


3. ASA Core v1.0: Deterministic Pipeline

ASA uses a strict 3-step flow:

slice.spec.md → slice.contract.json → skeleton code
Enter fullscreen mode Exit fullscreen mode

Every step is deterministic — no randomness, no inference.


4. Before vs After (Real ASA Behavior)

❌ Before (traditional generation)

# Business logic gets overwritten when spec changes
def execute(self, req):
    # custom logic
Enter fullscreen mode Exit fullscreen mode

Change the spec → overwrite → cry.


✅ After (ASA regeneration)

You write logic ONLY between markers:

# === BEGIN USER CODE ===
def execute(self, request: LoginRequest) -> LoginResponse:
    user = self.repo.get_user_by_email(request.email)
    return LoginResponse(jwt_token="123", expires_in=3600)
# === END USER CODE ===
Enter fullscreen mode Exit fullscreen mode

Change the spec:

asa generate-contract auth/login
asa regenerate-slice auth/login
Enter fullscreen mode Exit fullscreen mode

ASA regenerates the file structure and injects your preserved logic back in.

This is guaranteed — documented and implemented in Core.


5. Boundary Violations Stop Instantly

ASA lints with AST analysis:

$ asa lint auth/login

❌ [LINT FAIL] Boundary violation in repository.py:
   Line 1: Illegal import 'domains.billing.invoice'
   -> Cannot import from other domains.
Enter fullscreen mode Exit fullscreen mode

Same-domain imports are fully allowed; cross-domain imports are forbidden.


6. Quick Reproducible Workflow

pip install -e ".[dev]"

asa create-slice auth/login

# edit slice.spec.md

asa generate-contract auth/login
asa generate-skeleton auth/login

# implement logic between markers

asa lint auth/login
Enter fullscreen mode Exit fullscreen mode

And when specs change:

asa generate-contract auth/login
asa regenerate-slice auth/login
Enter fullscreen mode Exit fullscreen mode

Zero drift. Zero overwrite. Fully deterministic.


7. Why This Matters

Clean architecture + deterministic regeneration =
AI codebases that don’t collapse.

This is the foundation for stable AI-assisted engineering.


Source code & starter kit:
https://github.com/vibecodiq/asa-starter-kit

Top comments (0)