File Organization
π«
Critical Rule: AI defaults to putting files at project root. Fight this constantly.
The Standard Structure
project/
βββ docs/ # Documentation only
βββ scripts/ # Utility scripts
βββ tests/ # All test files
βββ src/ # Source code
β βββ components/ # UI components
β βββ utils/ # Helper functions
β βββ services/ # Business logic
β βββ hooks/ # React hooks
β βββ types/ # TypeScript types
β βββ lib/ # Third-party wrappers
βββ public/ # Static assets
βββ .gitignore
βββ README.mdThe Right Way to Prompt
β Good: Specify the path
"Create the UserService class in `/src/services/UserService.ts`"β Bad: Let AI decide
"Create the UserService class"AI will likely put it at root or in a random location.
Creating Folders First
Before asking AI to create files, create the folders:
mkdir -p src/services src/components src/utilsThen prompt:
"Create a new service in
/src/services/for handling payments"
Fixing Misplaced Files
When AI puts a file in the wrong place:
- Stop immediately β Don't continue building on wrong structure
- Move the file β Use your IDE or terminal
- Tell AI β "From now on, all services go in
/src/services/"
Import Path Discipline
Bad AI output often has broken imports:
// AI might generate:
import { User } from '../../../models/User' // Fragile relative path
// Better:
import { User } from '@/models/User' // Path aliasSet up path aliases in tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}The Rule
Every file has ONE correct location. Know it. Enforce it. Don't let AI decide.