Boundary Enforcement with Layered Architecture: Preventing LLM Spaghetti Code

James Phoenix
James Phoenix

Summary

LLMs create spaghetti architectures by violating layer boundaries—routes accessing databases directly, domain logic mixed with infrastructure. ESLint boundary rules automatically enforce layered architecture (presentation → application → domain → infrastructure), catching violations at lint-time and guiding LLMs to respect architectural patterns through immediate feedback.

The Problem

Without enforced boundaries, LLMs leak code between architectural layers—presentation accessing infrastructure directly, domain logic depending on external APIs, business rules scattered across layers. This creates unmaintainable spaghetti code that’s hard to test, debug, and refactor. Traditional code reviews catch this too late; LLMs need real-time feedback during generation.

The Solution

Use ESLint boundary rules (eslint-plugin-boundaries) to automatically enforce layered architecture constraints. Define clear layers (presentation, application, domain, infrastructure) with explicit dependency rules (presentation can use application/domain, application can use domain, domain depends on nothing). Linting fails immediately when LLM violates boundaries, forcing correction and teaching proper architecture through rapid feedback loops.

Leanpub Book

Read The Meta-Engineer

A practical book on building autonomous AI systems with Claude Code, context engineering, verification loops, and production harnesses.

Continuously updated
Claude Code + agentic systems
View Book

Related Concepts

References

Topics
Developer ExperienceDomain Driven DesignLintingQuality GatesSoftware Architecture

Newsletter

Become a better AI engineer

Weekly deep dives on production AI systems, context engineering, and the patterns that compound. No fluff, no tutorials. Just what works.

Join 306K+ developers. No spam. Unsubscribe anytime.


More Insights

Cover Image for The Environment Leads The Agent

The Environment Leads The Agent

For a long time I tried to lead my coding agents with better and better prompts, and they kept drifting. What finally worked was the opposite move. As I optimised the boilerplate of the repository I was building, I kept pushing each lesson I learned down into the floor of the repo: hermetic environments, typed contracts, mechanical lint, integration-first tests, queryable telemetry. Somewhere along the way the repo itself became the thing steering the agent, and it asks me what to do far less than it used to. This is the journey that got me there, and what it taught me.

James Phoenix
James Phoenix
Cover Image for Your Own Life Is a Queryable, Validated Corpus

Your Own Life Is a Queryable, Validated Corpus

Your private data exhaust deserves the same treatment as production data: indexed, validated, version-controlled, and queried by an agent. Once you make that move, writing a song, paying a tax bill, and updating a CV all become the same engineering problem.

James Phoenix
James Phoenix