Skip to main content

Teaching the AI the Layout

Share

Share this page

Pass it to someone who needs it.

Star on GitHub

Key takeaway: Give the agent a map

Your agent already reads a file every session that tells it your stack and your non-negotiables. But that file says what to do, not where anything lives. So new code lands wherever the agent guesses: a feature split across the wrong folders, a database call inside a button, a structure it invents instead of yours. This chapter gives the agent a map of your codebase in that same file, so its code extends your architecture instead of fighting it.

3.10.1Hand the agent the map

An architecture map is a compact picture of your codebase, added to the file your agent reads first. It says where features live, how the layers stack, what things are named, and where new code goes. It is the same thing a senior would tell a new hire before they touch anything.

Without it, the agent reverse-engineers your structure from whatever files it happened to open, and gets it wrong half the time. With it, the agent places code instead of guessing at it.

3.10.2Rules plus structure in one file

The map lives in the same always-read file as your rules, the one most tools share as AGENTS.md or call CLAUDE.md. Rules say how to behave; the map says where the code goes. The agent needs both in front of it every session.

Keep it a map, not an essay. A dozen lines that a beginner could not have written but an agent can follow exactly:

## Architecture - Features live in src/features/<name>/, self-contained. - Layers: ui -> hooks -> lib -> db. A layer imports only downward, never up or sideways. - Shared code in src/lib/, shared UI in src/ui/. - Naming: components PascalCase, hooks use*, files kebab-case. - New feature = a new folder under src/features/. Nothing goes in the root. Match the nearest neighbor's structure.

3.10.3New code lands in the right place

That last line does the heavy lifting. "New feature goes under src/features/, match the nearest neighbor" turns a vague instruction into a placement the agent cannot miss. The layer rule then stops it from wiring a database call straight into the UI. The naming line makes the new file look like it was always there.

Because this lives in the always-read file, it holds on every session, not just the one where you happened to explain it. The agent stops inventing structure and starts filling in yours.

3.10.4Keep the handoff current

The map is only as good as its accuracy. Add a new top-level folder or a new layer and forget to update the map, and the agent follows the old one straight into the wrong place. A stale map misroutes worse than no map at all.

Do not maintain it by hand. When you and the agent add a real structural piece, have it update the map in the same change. That is how your memory file grows itself when you correct it. Treat a map written months ago like old documentation: check it against the real folders before you trust it.

Update the map in the same change, or a stale map misroutes worse than none.

3.10.5Write the map into your file

This prompt has your agent read the code and write the map:

Ready prompt
Act as a senior engineer documenting my codebase for an engineer joining today. Read my project, my spec, and the layer, boundary, and naming rules I already decided. Then add an Architecture section to the file my agent reads every session (CLAUDE.md, AGENTS.md, or my rules file). Keep it a compact map, not prose: where each feature lives, the layer rule and its allowed import direction, the naming convention, and one line saying where new code goes. Infer the real structure from the code, do not invent one. Keep it under fifteen lines, and list every place the code and my recorded rules disagree instead of picking a side for me. If you need the full reasoning behind this step, read https://zalt.me/guides/vibe-coding/architect/architecture-handoff My structure, layers, and conventions:

Do this now: paste the prompt so your agent writes the map, then read it against your real folders and cut any line the code does not actually follow.

Mahmoud Zalt

Mahmoud Zalt

Software engineer, 16+ yrs · built Sistava.com in 3 months, idea to production, using these methods

Resources
Star on GitHubContribute
Donate

Support my work

A small tip keeps the free work coming.

© 2026 Mahmoud Zalt. Free to read, not to republish.
Copyright & license