<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd" -->

---
title: Spec-Driven Development: Enforcing Agent Architectural...
description: Autonomous coding agents like Copilot Workspace, Devin, Claude Code, and GPT Engineer can introduce 10 to 50 architectural boundary violations per session, far...
canonical: https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Spec-Driven Development: Enforcing Agent Architectural Contracts | daily.dev
og:description: Autonomous coding agents like Copilot Workspace, Devin, Claude Code, and GPT Engineer can introduce 10 to 50 architectural boundary violations per session, far...
og:url: https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd
og:image: https://api.daily.dev/og/posts/xvqGn1FyD.png
og:image:alt: Spec-Driven Development: Enforcing Agent Architectural Contracts
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Spec-Driven Development: Enforcing Agent Architectural Contracts

**[SitePoint](https://daily.dev/sources/sitepoint)** · 21 min read · 3 upvotes · 0 comments

## Summary

Autonomous coding agents like Copilot Workspace, Devin, Claude Code, and GPT Engineer can introduce 10 to 50 architectural boundary violations per session, far exceeding human error rates, because they lack institutional knowledge of a codebase's design conventions. Spec-driven development addresses this by encoding architectural rules as machine-readable contracts across three layers: structural contracts (module dependency direction) using Zod schemas, type-shape contracts for API surfaces, and behavioral contracts via Vitest tests. The piece walks through building a TypeScript contract registry, an AST-based dependency linter using the TypeScript Compiler API, violation detection logic, and Vitest architectural tests, then covers integrating these checks into pre-commit hooks and CI gates so agents receive structured feedback to self-correct. It also notes the described tooling (arch-contracts, ast-linter, vitest-arch, agent-gate) is illustrative and not currently published as npm packages.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.sitepoint.com/spec-driven-development-architectural-contracts-coding-agents>

## Questions this post answers

### How do I stop AI coding agents like Claude Code or Devin from violating my project's architecture layers?

Define machine-readable architectural contracts using a Zod schema registry that declares each module's allowed dependencies, forbidden imports, and public export shapes, then enforce them with an AST-based linter built on the TypeScript Compiler API plus Vitest tests wired into pre-commit hooks and CI. Feeding structured violation reports back to the agent lets it self-correct before human review.

_Developers hardening agent-generated code can track architectural-contract patterns like this on daily.dev._

### Why do regex-based import checks fail to catch architecture violations in TypeScript codebases?

Regex import extraction misses dynamic imports like await import('./module'), re-exports such as export { Foo } from './bar', and type-only imports, all of which evade pattern matching. Reliable enforcement instead requires parsing the actual AST with the TypeScript Compiler API, using ts.createProgram and ts.forEachChild to traverse ImportDeclaration nodes and resolve module specifiers to real file paths.

_Teams choosing between linting approaches can compare tradeoffs like these on daily.dev._

### What version of minimatch should I use for glob-based import path matching in Node.js?

Use minimatch version 7.x with a default import (import minimatch from 'minimatch') since it is CommonJS and exports the function itself as the default. Version 8 and above is ESM-only, exports a named minimatch function instead, and requires 'type': 'module' in package.json or an ESM-compatible bundler.

_Developers wiring up dependency scanning tools can check versioning gotchas like this on daily.dev._

## Similar posts on daily.dev

- [Keep Your Code Clean with Spec-Driven AI](https://daily.dev/posts/keep-your-code-clean-with-spec-driven-ai-fbguaamdc) · Aviator Blog · 3 upvotes · 0 comments
- [The Spec Layer](https://daily.dev/posts/the-spec-layer-egj5dj0vq) · Matt Rickard · 7 upvotes · 2 comments
- [The Spec Is the New Unit of Work: Spec-Driven Development for Teams Running AI Agents](https://daily.dev/posts/the-spec-is-the-new-unit-of-work-spec-driven-development-for-teams-running-ai-agents-thbd17u7t) · Medium · 0 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#architecture](https://daily.dev/tags/architecture), [#typescript](https://daily.dev/tags/typescript), [#spec-driven-development](https://daily.dev/tags/spec-driven-development), [#zod](https://daily.dev/tags/zod)

[View this post on daily.dev](https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Spec-Driven Development: Enforcing Agent Architectural Contracts","url":"https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd"},"datePublished":"2026-09-18T20:27:09.904Z","dateModified":"2026-09-18T20:27:37.394Z","description":"Autonomous coding agents like Copilot Workspace, Devin, Claude Code, and GPT Engineer can introduce 10 to 50 architectural boundary violations per session, far...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fbfaa16457a25ac379223fe515e733b6?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fbfaa16457a25ac379223fe515e733b6?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SitePoint","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SitePoint","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/sitepoint","url":"https://daily.dev/sources/sitepoint"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,architecture,typescript,spec-driven-development,zod","timeRequired":"PT21M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SitePoint","item":"https://daily.dev/sources/sitepoint"},{"@type":"ListItem","position":3,"name":"Spec-Driven Development: Enforcing Agent Architectural Contracts"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/spec-driven-development-enforcing-agent-architectural-contracts-xvqgn1fyd#faq","mainEntity":[{"@type":"Question","name":"How do I stop AI coding agents like Claude Code or Devin from violating my project's architecture layers?","acceptedAnswer":{"@type":"Answer","text":"Define machine-readable architectural contracts using a Zod schema registry that declares each module's allowed dependencies, forbidden imports, and public export shapes, then enforce them with an AST-based linter built on the TypeScript Compiler API plus Vitest tests wired into pre-commit hooks and CI. Feeding structured violation reports back to the agent lets it self-correct before human review. Developers hardening agent-generated code can track architectural-contract patterns like this on daily.dev."}},{"@type":"Question","name":"Why do regex-based import checks fail to catch architecture violations in TypeScript codebases?","acceptedAnswer":{"@type":"Answer","text":"Regex import extraction misses dynamic imports like await import('./module'), re-exports such as export { Foo } from './bar', and type-only imports, all of which evade pattern matching. Reliable enforcement instead requires parsing the actual AST with the TypeScript Compiler API, using ts.createProgram and ts.forEachChild to traverse ImportDeclaration nodes and resolve module specifiers to real file paths. Teams choosing between linting approaches can compare tradeoffs like these on daily.dev."}},{"@type":"Question","name":"What version of minimatch should I use for glob-based import path matching in Node.js?","acceptedAnswer":{"@type":"Answer","text":"Use minimatch version 7.x with a default import (import minimatch from 'minimatch') since it is CommonJS and exports the function itself as the default. Version 8 and above is ESM-only, exports a named minimatch function instead, and requires 'type': 'module' in package.json or an ESM-compatible bundler. Developers wiring up dependency scanning tools can check versioning gotchas like this on daily.dev."}}]}
```

