Agent-friendly directory structure is becoming a practical fix for teams whose repositories are overrun by AI-written code. At Pyn, engineers reorganized their codebase around self-contained “apps” after pull requests began arriving by the hundreds each day.
The problem is traffic. When engineers and agents ship 100 or more pull requests a day, the repository starts to behave like a busy airport. Merge conflicts pile up, the review backlog grows, and older pull requests sit unmerged.
From MVC trees to self-contained apps
Pyn’s old layout followed classic Rails MVC. Models lived in one tree, controllers in another and views in a third. That works when each layer is touched on its own, and it keeps frontend code next to other frontend code.
Building a single feature, though, meant moving through several trees. Flipping that structure was one of the first big changes the team made for AI-assisted work.
Now the codebase is organized by “app.” An app is one discrete domain, such as a single integration, with everything needed to deliver it in one place.
Four payoffs of a domain-centric layout
The team points to four benefits of the new directory structure.
- Clear lanes for agents. Pointing an agent at one directory gives it what it needs. Without that, it wanders the repository and copies whatever it finds.
- Fewer merge conflicts. Agents working in separate apps don’t touch the same files, so merges move faster. Once pull requests collide, work turns sequential no matter how many agents are running.
- Navigation that follows the files. Each package carries an index.md, which gives clickable navigation through the codebase.
- Gold templates. Once one app is in good shape, an engineer can point an agent at it and ask for “another one of those.”
What goes inside an app
An app in this setup holds the code for one domain, and a single integration is the standard example. Everything that domain needs sits together, so an engineer or an agent can finish a feature without hopping between folders for models, controllers and views.
That is the core of an agent-friendly directory structure: the boundary of the task matches the boundary of the folder. An instruction like “work on this directory” then has a precise meaning, and the agent has less reason to go looking elsewhere for patterns to imitate.
The trade-off for human readers
The old layout still has a case. Keeping all frontend code together helps when a change cuts across many features at once. Moving to apps gives up some of that, and teams should expect to relearn where things live.
Pyn’s bet is that most work now happens inside one domain at a time, so the new layout fits how work is actually divided. Engineers still navigate the repository too, and the index files help them as much as they help agents.
Why conflicts hurt more with agents
Pyn treats 200 pull requests as a normal day, and it enforces a hard cap on open pull requests. A request stuck on a conflict therefore occupies one of a limited number of slots.
Shared code is where collisions still happen. The advice here is to keep it small and discrete and handle it carefully. Done right, it stops being a problem.
Accepting some duplication
Copying a template app produces duplicated code, and Pyn is fine with that within limits. Refactoring is cheap with AI, so cleanup becomes its own separate loop instead of a blocker for new work.
That trade makes sense for teams running many agents at once. A little repeated code costs less than a stalled queue of pull requests.
What it means for teams adapting codebases
The takeaway for engineering leads is that directory structure now serves agents as well as people. A layout designed for humans reading across layers can slow down automated contributors who need a tight, self-contained scope.
Teams considering the same move can begin small. Pick one domain, group everything it needs into a single app, add an index file, and see whether agents stay inside the lane. If conflicts drop, repeat the pattern elsewhere.
Where this goes next
Review capacity is the next bottleneck for any team that merges hundreds of pull requests a day. Pyn’s approach doesn’t remove that limit, but it reduces the collisions that waste slots. Expect more teams to rework their agent-friendly directory structure before they try anything more elaborate, since it costs little and changes how work gets routed.
The same logic applies to documentation. Navigation files and templates give agents context in the places they already look, which beats writing longer prompts.
Source: jonathannen.com