Back to Guides
Problem-Solving

Cursor AI Keeps Putting Files in the Wrong Place

It's not a Cursor bug. Cursor doesn't know your folder structure -because you haven't told it yet. Here's the fix.

Last updated: 2026-07-01

Why this happens

Cursor generates code based on training data patterns. If your project uses a feature-based folder structure (src/features/auth/components/LoginForm.tsx), but the most common React pattern in training data is a flat src/components/ structure, Cursor will default to flat. It isn't broken -it just doesn't know your project's conventions without being told.

The fix: encode your folder structure explicitly

Add a .cursor/rules/.mdc file that maps out your exact folder structure and what belongs in each folder. Be specific. "Put components in components/" is too vague. "UI components used across 2+ routes live in src/components/. Route-specific components live in src/app/[route]/_components/ with an underscore prefix." is actionable.

Folder structure rules template

Customize this with your actual paths and drop it in .cursor/rules/structure.mdc.

.cursor/rules/structure.mdc
---
description: Project folder structure and file placement rules
alwaysApply: true
---

# File Placement Rules

When creating new files, use these rules to decide where they go:

## Components
- src/components/  → Shared UI used in 2+ different routes/features
- src/app/[route]/_components/  → UI used only in that specific route (underscore prefix hides from routing)
- src/features/[feature]/components/  → UI specific to one business domain

## Logic
- src/hooks/  → Shared custom hooks used across 2+ features
- src/features/[feature]/hooks/  → Hooks specific to one feature
- src/utils/  → Pure helper functions (no side effects, no React)
- src/lib/  → Pre-configured server-only clients (Prisma, Stripe, auth)

## State
- src/store/  → Zustand stores for global UI state only
- (Never store server/async data in Zustand -use React Query cache)

## Types
- src/types/  → Global TypeScript interfaces used across features
- src/features/[feature]/types.ts  → Types specific to one feature

## API / Server
- src/app/api/[route]/route.ts  → Next.js route handlers
- src/features/[feature]/actions/  → Server Actions for this feature

## DO NOT
- Do not create a pages/ directory (App Router project)
- Do not put logic in app/ route files -keep route files thin
- Do not create new top-level src/ folders without discussion

What to do after adding this file

Test it immediately. Ask Cursor: "Create a LoginForm component for the auth feature." Without the rules file, it would create src/components/LoginForm.tsx. With the rules file, it should create src/features/auth/components/LoginForm.tsx. If it still gets it wrong, be even more explicit -add a "When creating a component for a specific feature, always put it in src/features/[feature]/components/." line.

Generate complete folder structure rules for your project

standarx generates a .cursor/rules setup that encodes your exact folder structure, naming conventions, and file placement rules.

Generate my rules file