| name | file-organization |
| description | Organize project files and folders for maintainability and scalability. Use when structuring new projects, refactoring folder structure, or establishing conventions. Handles project structure, naming conventions, and file organization best practices. |
| allowed-tools | Read Write Glob Bash |
| metadata | {"tags":"file-organization, project-structure, folder-structure, naming-conventions","platforms":"Claude, ChatGPT, Gemini"} |
Project File Organization
When to use this skill
- New Projects: Initial folder structure design
- Project Growth: Refactoring when complexity increases
- Team Standardization: Establish consistent structure
Instructions
Step 1: React/Next.js Project Structure
src/
โโโ app/ # Next.js 13+ App Router
โ โโโ (auth)/ # Route groups
โ โ โโโ login/
โ โ โโโ signup/
โ โโโ (dashboard)/
โ โ โโโ layout.tsx
โ โ โโโ page.tsx
โ โ โโโ settings/
โ โโโ api/ # API routes
โ โ โโโ auth/
โ โ โโโ users/
โ โโโ layout.tsx
โ
โโโ components/ # UI Components
โ โโโ ui/ # Reusable UI (Button, Input)
โ โ โโโ Button/
โ โ โ โโโ Button.tsx
โ โ โ โโโ Button.test.tsx
โ โ โ โโโ index.ts
โ โ โโโ Input/
โ โโโ layout/ # Layout components (Header, Footer)
โ โโโ features/ # Feature-specific components
โ โ โโโ auth/
โ โ โโโ dashboard/
โ โโโ shared/ # Shared across features
โ
โโโ lib/ # Utilities & helpers
โ โโโ utils.ts
โ โโโ hooks/
โ โ โโโ useAuth.ts
โ โ โโโ useLocalStorage.ts
โ โโโ api/
โ โโโ client.ts
โ
โโโ store/ # State management
โ โโโ slices/
โ โ โโโ authSlice.ts
โ โ โโโ userSlice.ts
โ โโโ index.ts
โ
โโโ types/ # TypeScript types
โ โโโ api.ts
โ โโโ models.ts
โ โโโ index.ts
โ
โโโ config/ # Configuration
โ โโโ env.ts
โ โโโ constants.ts
โ
โโโ styles/ # Global styles
โโโ globals.css
โโโ theme.ts
Step 2: Node.js/Express Backend Structure
src/
โโโ api/ # API layer
โ โโโ routes/
โ โ โโโ auth.routes.ts
โ โ โโโ user.routes.ts
โ โ โโโ index.ts
โ โโโ controllers/
โ โ โโโ auth.controller.ts
โ โ โโโ user.controller.ts
โ โโโ middlewares/
โ โโโ auth.middleware.ts
โ โโโ errorHandler.ts
โ โโโ validation.ts
โ
โโโ services/ # Business logic
โ โโโ auth.service.ts
โ โโโ user.service.ts
โ โโโ email.service.ts
โ
โโโ repositories/ # Data access layer
โ โโโ user.repository.ts
โ โโโ session.repository.ts
โ
โโโ models/ # Database models
โ โโโ User.ts
โ โโโ Session.ts
โ
โโโ database/ # Database setup
โ โโโ connection.ts
โ โโโ migrations/
โ โโโ seeds/
โ
โโโ utils/ # Utilities
โ โโโ logger.ts
โ โโโ crypto.ts
โ โโโ validators.ts
โ
โโโ config/ # Configuration
โ โโโ index.ts
โ โโโ database.ts
โ โโโ env.ts
โ
โโโ types/ # TypeScript types
โ โโโ express.d.ts
โ โโโ models.ts
โ
โโโ __tests__/ # Tests
โ โโโ unit/
โ โโโ integration/
โ โโโ e2e/
โ
โโโ index.ts # Entry point
Step 3: Feature-Based Structure (Large-Scale Apps)
src/
โโโ features/
โ โโโ auth/
โ โ โโโ components/
โ โ โ โโโ LoginForm.tsx
โ โ โ โโโ SignupForm.tsx
โ โ โโโ hooks/
โ โ โ โโโ useAuth.ts
โ โ โโโ api/
โ โ โ โโโ authApi.ts
โ โ โโโ store/
โ โ โ โโโ authSlice.ts
โ โ โโโ types/
โ โ โ โโโ auth.types.ts
โ โ โโโ index.ts
โ โ
โ โโโ products/
โ โ โโโ components/
โ โ โโโ hooks/
โ โ โโโ api/
โ โ โโโ types/
โ โ
โ โโโ orders/
โ
โโโ shared/ # Shared across features
โ โโโ components/
โ โโโ hooks/
โ โโโ utils/
โ โโโ types/
โ
โโโ core/ # App-wide
โโโ store/
โโโ router/
โโโ config/
Step 4: Naming Conventions
File Names:
Components: PascalCase.tsx
Hooks: camelCase.ts (useAuth.ts)
Utils: camelCase.ts (formatDate.ts)
Constants: UPPER_SNAKE_CASE.ts (API_ENDPOINTS.ts)
Types: camelCase.types.ts (user.types.ts)
Tests: *.test.ts, *.spec.ts
Folder Names:
kebab-case: user-profile/
camelCase: userProfile/ (optional: hooks/, utils/)
PascalCase: UserProfile/ (optional: components/)
โ
Consistency is key (entire team uses the same rules)
Variable/Function Names:
const UserProfile = () => {};
function getUserById() {}
const API_BASE_URL = 'https://api.example.com';
class User {
private _id: string;
private _hashPassword() {}
}
const isAuthenticated = true;
const hasPermission = false;
const canEdit = true;
Step 5: index.ts Barrel Files
components/ui/index.ts:
export { Button } from './Button/Button';
export { Input } from './Input/Input';
export { Modal } from './Modal/Modal';
import { Button, Input } from '@/components/ui';
โ Bad example:
export * from './Button';
export * from './Input';
Output format
Project Template
my-app/
โโโ .github/
โ โโโ workflows/
โโโ public/
โโโ src/
โ โโโ app/
โ โโโ components/
โ โโโ lib/
โ โโโ types/
โ โโโ config/
โโโ tests/
โโโ docs/
โโโ scripts/
โโโ .env.example
โโโ .gitignore
โโโ .eslintrc.json
โโโ .prettierrc
โโโ tsconfig.json
โโโ package.json
โโโ README.md
Constraints
Required Rules (MUST)
- Consistency: Entire team uses the same rules
- Clear Folder Names: Roles must be explicit
- Max Depth: Recommend 5 levels or fewer
Prohibited (MUST NOT)
- Excessive Nesting: Avoid 7+ levels of folder depth
- Vague Names: Avoid utils2/, helpers/, misc/
- Circular Dependencies: Prohibit A โ B โ A references
Best practices
- Colocation: Keep related files close (component + styles + tests)
- Feature-Based: Modularize by feature
- Path Aliases: Simplify imports with
@/
tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/components/*": ["./src/components/*"],
"@/lib/*": ["./src/lib/*"]
}
}
}
Usage:
import { Button } from '../../../components/ui/Button';
import { Button } from '@/components/ui';
References
Metadata
Version
- Current Version: 1.0.0
- Last Updated: 2025-01-01
- Compatible Platforms: Claude, ChatGPT, Gemini
Tags
#file-organization #project-structure #folder-structure #naming-conventions #utilities
Examples
Example 1: Basic usage
Example 2: Advanced usage