You type a prompt into your AI assistant. "Add user authentication." The code appears instantly. It works. You feel like a wizard. Then three weeks later, you try to change the database schema, and suddenly your frontend breaks, your API contracts are inconsistent, and no one knows which module owns the session logic. This is the trap of vibe coding without structure.
Vibe coding lets you build fast by describing intent in natural language. But LLMs don't understand architecture unless you force them to. They see tokens, not services. If you don't define service boundaries explicitly, the AI will happily couple everything together. It will import a UI component into a backend service. It will mix data access with business logic. The result? A tightly coupled mess that looks like a prototype but costs like a legacy system.
Why Prompts Create Hidden Coupling
Large Language Models (LLMs) are probabilistic engines. They predict the next token based on patterns they learned during training. They have no innate sense of domain-driven design or microservices. When you ask an AI to "add a feature," it optimizes for local correctness, not global architecture.
Consider a typical failure mode. You ask for a new reporting endpoint. The AI sees existing code where other endpoints query the database directly. So, it does the same. Now your reporting service depends directly on the user table's schema. Later, you refactor the user table. Your reporting service breaks. In a properly bounded system, the reporting service would depend on an interface, not a table. But the AI didn't know that boundary existed because you never told it.
This is what practitioners call "tight coupling from prompts." The model fills in gaps with assumptions. Without strict rules, those assumptions become technical debt. Autonoma’s research highlights that AI IDEs often improvise architectural decisions-like choosing synchronous HTTP calls over message queues-because the prompt didn't specify the constraint. The AI isn't malicious; it's just unguided.
Defining Service Boundaries in an AI World
In traditional software, we use terms like "bounded contexts" or "microservices" to describe separation. In vibe coding, you need to translate these concepts into artifacts the AI can read. You can't just say "keep things decoupled." You must provide concrete constraints.
A service boundary here means a clear rule set: Which files belong to this module? What can this module import? Who owns the data? For example, if you have a `billing` module and a `user` module, a strict boundary might dictate that `billing` can never import from `user`'s internal logic, only via a defined public interface.
Michael Shmilov argues that microservices work because they create boundaries where each unit has a clear responsibility. He suggests applying this mindset to AI agents. Instead of one agent trying to understand the whole repo, you assign specific agents to specific domains. One agent handles the frontend state. Another handles the API layer. A third manages database migrations. Each agent operates within its lane.
The Modular Monolith as a Safety Net
Most teams aren't ready for distributed microservices when using AI. The operational overhead is too high. Instead, a modular monolith offers the best balance. You keep one deployable unit but enforce strict internal boundaries.
WorldlineTech’s case study demonstrates this effectively. They used a monorepo structure with hard import rules. Code in `modules/grimoire` could never import from `modules/weaver`. This wasn't just a style guide suggestion; it was enforced by tooling and embedded in the AI's context. When the AI tried to violate this rule, the build failed, or the prompt instructions flagged it.
Here’s how you can structure it:
- Domain Modules: Split your codebase into folders representing distinct business capabilities (e.g., `auth`, `payments`, `inventory`).
- Shared Kernel: A small, stable core for common utilities that all modules can import.
- Strict Import Rules: Define who can talk to whom. Module A imports Module B’s interface, not its implementation.
- Data Ownership: Each module owns its tables. Cross-module queries are forbidden or go through a gateway.
This structure gives the LLM visual cues. When it scans the file tree, it sees the separation. If you tell it, "You are working in the `payments` module," it naturally restricts its changes to that folder if you’ve configured the context correctly.
Constitutional Architecture: Rules the AI Must Follow
To prevent drift, you need a "constitution" for your project. This is a collection of documents that the AI reads before generating any code. Think of it as the law of the land.
Key components of this constitution include:
- RULES.md: A short, high-level document listing non-negotiable architectural laws. Example: "No direct database access from controllers," or "All external APIs must be mocked in tests."
- Architectural Decision Records (ADRs): Detailed explanations of why certain choices were made. If you chose Drizzle ORM over Prisma, write an ADR explaining why. The AI reads this and respects the choice.
- Feature Specs: Before coding, define the input, output, and edge cases for a feature. The AI implements the spec, not its own interpretation of the prompt.
WorldlineTech found that requiring the AI to write a new ADR whenever it proposed a major change (like switching PDF generation from server-side to client-side) created crucial traceability. It forced the human developer to review the architectural impact before accepting the code.
Enforcing Boundaries at Runtime
Code structure is only half the battle. You also need runtime enforcement. If your AI-generated code accidentally opens a connection to the wrong database, your app might still run, but your boundaries are broken.
Northflank’s security guidelines suggest scoping credentials. Give each service or module its own database user with limited permissions. If the `inventory` service tries to write to the `users` table, the database rejects it. This creates a hard boundary that the AI cannot bypass, regardless of what code it generates.
Similarly, use sandboxed execution environments. If you're running AI-generated scripts, ensure they don't have network access to production databases unless explicitly allowed. This limits the "blast radius" of a bad prompt. If the AI hallucinates a destructive migration, it fails safely in the sandbox rather than corrupting prod.
Practical Workflow for Boundary-Aware Vibe Coding
How do you actually implement this day-to-day? Here’s a repeatable process:
| Step | Unstructured Vibe Coding | Boundary-Aware Vibe Coding |
|---|---|---|
| Prompt Input | "Build me a login page." | "Implement login in `auth` module per SPEC-04. Use `AuthInterface`. Do not touch `user-profile` DB." |
| Context Provided | Entire repository or recent chat history. | Specific module files, RULES.md, relevant ADRs. |
| AI Output | Code scattered across multiple layers; potential cross-imports. | Code contained within module; interfaces respected. |
| Review Focus | Does it work? | Does it respect boundaries? Does it match the ADR? |
| Long-term Cost | High refactoring debt. | Low maintenance, easier onboarding. |
Start by writing your RULES.md. Keep it under two pages. List your module names and their allowed dependencies. Then, configure your AI assistant (whether it's Cursor, Copilot, or a custom CLI wrapper) to inject this file into every prompt automatically. Many tools allow you to pin files to the context window.
When starting a new feature, don't just ask for code. Ask for a plan first. "Propose a file structure for this feature based on my RULES.md." Review the plan. If the AI suggests importing a UI library into a backend service, correct it immediately. This feedback loop trains the model-and your workflow-to respect the boundaries.
Common Pitfalls to Avoid
Even with good intentions, teams fall into traps. Here are the most common ones:
- The "Just Make It Work" Trap: Ignoring boundaries for speed in early prototypes. This leads to a rewrite later. Set boundaries from day one, even for MVPs.
- Over-Engineering: Creating 50 microservices for a solo dev project. Stick to a modular monolith until scale demands otherwise.
- Stale Documentation: If your ADRs don't match the code, the AI gets confused. Automate doc updates or make them part of the PR checklist.
- Ignoring Security Scopes: Giving the AI full admin access to your database. Always use least-privilege credentials.
Remember, the goal isn't to stop the AI from coding. It's to stop the AI from designing your architecture by accident. You remain the architect; the AI is the builder. Builders need blueprints.
Frequently Asked Questions
Do I need microservices to apply service boundaries in vibe coding?
No. In fact, a modular monolith is often better for AI-assisted development. Microservices add distributed complexity that can confuse both humans and AI. A modular monolith allows you to enforce logical boundaries (via import rules and folder structures) without the operational overhead of network latency and deployment coordination.
How do I teach an LLM about my service boundaries?
You teach it through context injection. Include a RULES.md file and relevant Architectural Decision Records (ADRs) in the AI's context window for every prompt. Explicitly state constraints like "Module A cannot import from Module B" in the prompt itself. Some advanced setups use linting errors fed back to the AI to correct violations automatically.
What happens if the AI ignores my boundaries?
If the AI violates a boundary, treat it as a bug. Correct the prompt or the context. If it happens frequently, your rules might be ambiguous. Consider enforcing boundaries technically, such as using TypeScript path aliases or ESLint rules that fail the build on illegal imports. This provides immediate feedback to both the developer and the AI.
Is vibe coding suitable for large enterprise applications?
Yes, but only with strong governance. The Cloud Security Alliance recommends policy enforcement, role-based access controls, and centralized logging for enterprise-scale vibe coding. You must limit what each AI agent or citizen developer can access. Without these controls, large teams risk creating thousands of tightly coupled, unmaintainable workflows.
Can I retrofit service boundaries onto an existing vibe-coded project?
It’s possible but painful. You’ll likely need to refactor code to separate concerns, then document the new boundaries in ADRs and RULES.md. Going forward, instruct the AI to respect these new rules. Starting with boundaries is significantly cheaper than untangling coupling later.