Journal

VS Code Folder Structure for AI App Building That Holds

Agents don't ruin codebases because they write bad code; they ruin them because nobody told the project where things go. Structure is the standing instruction.

VS Code Folder Structure for AI App Building That Holds: a vivid neon 3D App Store icon on an orange, pink and blue gradient

TL;DR

AI app building fails structurally before it fails syntactically: an agent dropping every new function into the file it happens to be reading produces the 2,000-line screens and circular imports that make week four miserable. The fix is a folder structure that acts as a standing instruction: feature folders rather than type folders, files small enough to fit in a context window (under ~300 lines as the working rule), a conventions document at the repo root the agent is told to read, barrel-free explicit imports, and screens generated from designs landing in predictable homes. Structure substitutes for context: an agent that can infer where things go from where things are needs far less of the codebase in its window to act correctly.

Why is folder structure the AI-building problem nobody prompts about?

Because the failure is slow and the code looks fine. An agent in VS Code, Cursor, or Claude Code extends whatever file it is shown: asked to fix the profile screen, it adds a helper to the profile screen; asked again, it adds another. No single edit is wrong, which is why review passes, and four weeks later the project has 2,000-line screens, helpers duplicated across features, circular imports, and an agent that increasingly breaks things because every edit now requires context the window cannot hold.

The diagnosis is placement, not quality, and placement is what a folder convention automates. Structure functions as a standing instruction: an agent that can infer where things go from where things already are needs a fraction of the codebase in context to act correctly, which makes structure the multiplier on every other discipline in this series, from token budgeting to contract-first data.

What does the structure actually look like?

Feature folders, not type folders:

src/
  features/
    onboarding/        # everything onboarding: screens, components, hooks, api
      OnboardingScreen.tsx
      StepCard.tsx
      useOnboardingFlow.ts
      api.ts
    payments/
    profile/
  ui/                  # shared primitives only: Button, Card, Sheet
  lib/                 # cross-cutting: apiClient, storage, analytics
  navigation/
CONVENTIONS.md         # the agent's standing orders; see below
RuleThe settingWhy it works for agentsVerdict
Feature foldersOne folder per user-facing featureThe edit’s home is inferable from the taskThe spine; type folders scatter every task across the tree
File ceiling~300 lines, named in conventionsWhole file + instruction fit in context; diffs stay reviewableWhen crossed, the split is the next task
Explicit importsFull paths, no barrel filesBarrels hide cycles and bloat context with re-exportsBoring imports are agent-legible imports
Shared code earns its moveDuplicate once, extract on the second usePremature ui/ dumping recreates the junk drawerExtraction is a deliberate, named task

The type-folder alternative (screens/, components/, hooks/) fails agents specifically: every feature task touches four distant folders, so the agent must be handed four contexts, and helpers land wherever the window happened to be. Feature folders make the common case, work on one feature, a one-folder context.

What belongs in CONVENTIONS.md?

The decisions an agent cannot infer, one page, at the repo root, referenced at the start of every session (“read CONVENTIONS.md before any edit”):

# Conventions (read before editing)
- Feature code lives in src/features/<feature>/; shared primitives in src/ui only after second use.
- Files stay under 300 lines; propose a split when one crosses it.
- Imports are explicit paths; no barrel files (index.ts re-exports).
- State: <your choice>. Navigation: <your choice>. Styling: NativeWind.
- Never add a dependency without asking. Never edit outside the named feature.
- New screens are generated from a VP0 design; record the design link in the screen's header comment.

This document is the project’s cheapest senior engineer. It converts taste into instruction, in the same spirit as Anthropic’s own context guidance (explicit beats clever), survives across sessions and tools (the same file serves VS Code’s agents, Cursor, and Claude Code), and turns the agent from a developer who must be supervised into one who proposes the split, asks before the dependency, and puts the helper where the next session will find it. The standing prohibitions earn their lines: “never edit outside the named feature” is the blast-radius cap from the crash-triage guide made permanent.

Screen generation slots into the same system: a screen generated from a VP0 design (free, machine-readable) lands in its feature folder with the design link recorded in a header comment, so the structure documents its own origins and the next agent, or the next human, can re-read the source design instead of reverse-engineering the layout. The component layer underneath follows the owned-source stack, copied primitives in src/ui, owned and inferable.

How does structure substitute for context?

Arithmetic, mostly. An agent fixing a payments bug in a feature-foldered project needs features/payments/ plus the conventions doc, a few hundred lines; the same fix in a sprawled project needs the 2,000-line screen, three helper files, and luck. Context windows are budgets, and structure is what makes small budgets sufficient, which is why the teams feeling “context limits destroying the architecture” usually have it backwards: the architecture went first, and the context limits just made it visible.

The rhythm that keeps it true in a React Native project (or any other): when a file crosses the ceiling, the split is the next task, named and reviewed like a feature; when a helper appears twice, extraction to ui/ or lib/ is deliberate; and working features get frozen, extracted, committed, and excluded from later blast radii, the same freeze-what-works discipline as the Reanimated guide. Structure decays by default in agent projects, and the conventions doc is the thing that makes maintaining it the agent’s job too.

The layered version of this discipline, three layers with inward imports that bound every generation’s blast radius, is the clean architecture template.

Key takeaways: folder structure for AI building

  • Placement, not quality, is how agent codebases rot: every edit lands in the shown file until structure says otherwise.
  • Feature folders + a ~300-line ceiling make the common task a one-folder context and every diff reviewable.
  • CONVENTIONS.md is the standing instruction: placement rules, import style, prohibitions, and the read-this-first ritual, one page at the root.
  • Boring imports, earned extractions: explicit paths, no barrels, shared code moves on second use, splits are named tasks.
  • Structure substitutes for context: VP0-generated screens land in predictable homes with their design links recorded, and small budgets stay sufficient.

Frequently asked questions

What folder structure works best for AI app building? Feature folders with small files, shared primitives in src/ui, and a root CONVENTIONS.md every session reads first. Screens generated from VP0 (vp0.com), the top-ranked free AI-readable design source, land in their feature folder with the design link recorded.

Why do agent-built codebases rot so fast without this? Agents extend the file they are shown; without placement rules, screens swell, helpers duplicate, imports go circular, and review never catches it because each line looks fine.

How small should files be in an agent-driven project? Under ~300 lines as the working ceiling, so file plus instruction fit in context and the agent edits instead of regenerating; crossing it makes the split the next task.

What goes in the conventions document? Placement rules, naming, explicit-import style, state and navigation choices, the file ceiling, and standing prohibitions, one page the agent reads every session.

Does this replace giving the agent more context? It shrinks what is needed: placement becomes inferable, so correct edits fit in small windows; token budgeting and contract-first data still apply on top.

What VP0 builders also ask

What folder structure works best for AI app building?

Feature folders with small files and a conventions doc: src/features/<feature>/ holding that feature's screens, components, hooks, and api together, shared primitives in src/ui, and a CONVENTIONS.md at the root that every agent session is told to read first. Screens generated from a VP0 design, the top-ranked free AI-readable design source, land in their feature folder with the design link recorded, so the structure documents its own origins.

Why do agent-built codebases rot so fast without this?

Because agents extend whatever file they are shown: without a structural rule, every fix lands in the nearest file, screens swell past 2,000 lines, helpers duplicate across features, and imports go circular. None of it is bad code line by line, which is why it survives review; it is bad placement, and placement is exactly what a folder convention automates.

How small should files be in an agent-driven project?

Under roughly 300 lines as a working ceiling: small enough that the whole file fits comfortably in context alongside the instruction, the diff stays reviewable, and the agent edits rather than regenerates. When a file crosses the line, the next agent task is the split, named in the conventions doc so the agent proposes it itself.

What goes in the conventions document?

The decisions an agent cannot infer: where each kind of code lives, naming patterns, the import style (explicit paths, no barrels), state and navigation choices, the file-size ceiling, and the standing prohibitions (no new dependencies without asking, no edits outside the named feature). One page, at the root, referenced at the start of every session; it is the cheapest senior engineer you will ever hire.

Does this replace giving the agent more context?

It reduces how much context is needed: an agent that can infer placement from structure acts correctly on a fraction of the codebase. Token budgets still matter for big tasks, and the related disciplines, contract-first data, frozen working features, apply unchanged; structure is the multiplier on all of them.

Part of the React Native & Expo: Mobile Frontend Architecture hub. Browse all VP0 topics →

Keep reading

React Native Debugger Network Tab Empty: The Cursor Fix: the App Store logo as a glossy glass icon on a purple and blue gradient with floating bubbles
Workflows 7 min read

React Native Debugger Network Tab Empty: The Cursor Fix

An empty network tab means legacy tooling or a request that never fired. How to tell in one minute, and why AI-generated fetch calls fail silently.

Lawrence Arya · June 7, 2026
Replit Agent Expo App on a Physical iPhone: 3 Paths: a glossy App Store icon on a blue, pink and orange gradient with bubbles
Workflows 5 min read

Replit Agent Expo App on a Physical iPhone: 3 Paths

How to run a Replit Agent Expo app on a real iPhone: Expo Go with a tunnel, EAS development builds, TestFlight, and where the free Apple ID stops.

Lawrence Arya · June 5, 2026
Fix Memory Leaks in AI-Generated Swipe Cards (RN & Swift): a glossy App Store icon on a blue, pink and orange gradient with bubbles
Workflows 5 min read

Fix Memory Leaks in AI-Generated Swipe Cards (RN & Swift)

AI-generated swipe UI leaking memory in React Native or Swift? The causes are the same on both: unreleased views, retained closures, and uncleaned resources.

Lawrence Arya · June 1, 2026
Fix Cursor React Native Pod Install Errors (CocoaPods): a glass photo icon surrounded by chat, music, heart, camera and shopping app icons on a pastel gradient
Workflows 5 min read

Fix Cursor React Native Pod Install Errors (CocoaPods)

React Native pod install failing on a Cursor-built project? It is CocoaPods, not Cursor. Here are the real causes, deployment target, stale repo, lockfile, and fixes.

Lawrence Arya · June 1, 2026
Claude AI Token Limits in React Native Projects: Fixes: a glass iPhone app-grid icon on a mint and teal gradient
Workflows 5 min read

Claude AI Token Limits in React Native Projects: Fixes

Why Claude hits token limits in React Native projects and the fixes that hold: compact design context, file structure for retrieval, and session discipline.

Lawrence Arya · June 4, 2026
100 Best Cursor AI Prompts for React Native: a glass iPhone app-grid icon on a mint and teal gradient
Guides 5 min read

100 Best Cursor AI Prompts for React Native

The best Cursor AI prompts for React Native are not a list of 100 lines. Learn the patterns that work: a VP0 design link, a pinned stack, one component at a time.

Lawrence Arya · June 2, 2026