file-organization
Skill4 starsChanged 9 months agoMITView on GitHub
Guide file and directory organization for maintainable codebases. Use when the user creates new files, asks where to put code, plans project structure, or when a file exceeds 400 lines. Apply when scaffolding new projects or refactoring large files into smaller modules.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- neilghosh/skillstheir own version, first seen Sep 27, 2026
- sherifican/Agent-FleetOpstheir own version, first seen Sep 17, 2026
- nimadorostkar/Claude-Skills-collectiontheir own version, first seen Jul 14, 2026
- autohandai/community-skillstheir own version, first seen Mar 9, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- sherifican/Agent-FleetOps★ 34same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- autohandai/community-skills★ 11same name
- neilghosh/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository78 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/claude-initial-setup.mdcCursor rule
- parallel-task-executionSkill
- subagent-patternsSkill
- task-coordinationSkill
- agent-communicationSkill
- context-managementSkill
- multi-agent-orchestrationSkill
- deploy-strategiesSkill
- github-actions-guideSkill
- pipeline-patternsSkill
- anthropic-sdk-guideSkill
- prompt-engineeringSkill
- tool-use-patternsSkill
- automated-review-setupSkill
- pr-standardsSkill
- review-checklistSkill
- immutability-patternsSkill
- naming-conventionsSkill
- branching-strategySkill
- commit-conventionsSkill
- pr-workflowSkill
- migration-patternsSkill
- query-optimizationSkill
- schema-design-guideSkill
- error-tracingSkill
- log-analysisSkill
- systematic-debuggingSkill
- django-admin-customizationSkill
- django-orm-masterySkill
- drf-api-patternsSkill
- docker-compose-guideSkill
- dockerfile-best-practicesSkill
- multi-stage-buildsSkill
- express-error-handlingSkill
- middleware-patternsSkill
- rest-api-nodeSkill
- async-fastapiSkill
- dependency-injection-fastapiSkill
- pydantic-validationSkill
- concurrency-patterns-goSkill
- error-handling-goSkill
- idiomatic-goSkill
- automation-triggersSkill
- hook-recipesSkill
- pre-post-hooksSkill
- junit-testingSkill
- maven-gradle-guideSkill
- spring-boot-patternsSkill
- mcp-resource-patternsSkill
- mcp-server-creationSkill
- mcp-tool-designSkill
- context-optimizationSkill
- knowledge-persistenceSkill
- memory-patternsSkill
- caching-strategiesSkill
- lazy-loading-patternsSkill
- profiling-guideSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 119
Use barrel exports to simplify imports, but keep them thin:
- Distinctive: line 136
Keep related files close together.
- Very specific: line 197
Empty wrapper files: Do not create index.ts that just re-exports a single file.
- Very specific: line 199
Premature abstraction: Do not create a shared/ module for code used by only one feature.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
File Organization
Structure codebases with many small, focused files organized by feature or domain. Target 200-400 lines per file, with 800 as a hard maximum.
When to Use
- Creating a new project or feature module
- A file exceeds 400 lines and needs splitting
- Deciding where to place new code
- Reviewing project structure for maintainability
- Setting up barrel exports or index files
Core Patterns
Feature-Based Organization (Preferred)
Group files by feature/domain, not by type. Each feature folder contains everything it needs:
src/
auth/
components/
LoginForm.tsx
SignupForm.tsx
hooks/
useAuth.ts
useSession.ts
services/
auth.service.ts
token.service.ts
types.ts
constants.ts
index.ts # barrel export
users/
components/
UserProfile.tsx
UserList.tsx
hooks/
useUser.ts
services/
user.service.ts
types.ts
index.ts
shared/ # Cross-cutting concerns only
components/
Button.tsx
Modal.tsx
hooks/
useDebounce.ts
utils/
format.ts
validation.tsCompare with the type-based approach (avoid this):
# BAD: Type-based organization
src/
components/ # 50+ files, mixed concerns
LoginForm.tsx
UserProfile.tsx
Button.tsx
OrderTable.tsx
hooks/ # Hard to find related code
useAuth.ts
useUser.ts
useOrders.ts
services/
auth.service.ts
user.service.tsFile Size Guidelines
| Lines | Action |
| < 100 | Fine, but check if the file is too granular |
| 100-400 | Ideal range for most files |
| 400-600 | Consider splitting if multiple concerns |
| 600-800 | Split into smaller modules |
| > 800 | Must refactor — file is too large |
Extract when you see:
- Multiple classes or major type groups in one file
- Utility functions unrelated to the file's primary purpose
- Sections separated by comment banners (
// ===== Section =====) - More than 5 exported functions from a single file
// BEFORE: 600-line user.service.ts
export class UserService {
// ... 200 lines of CRUD operations
// ... 150 lines of validation logic
// ... 100 lines of email notifications
// ... 150 lines of permission checks
}
// AFTER: Split by responsibility
// user.service.ts (~200 lines) — CRUD operations
// user.validation.ts (~150 lines) — Input validation
// user.notifications.ts (~100 lines) — Email logic
// user.permissions.ts (~150 lines) — AuthorizationBarrel Exports (index.ts)
Use barrel exports to simplify imports, but keep them thin:
// src/auth/index.ts — barrel export
export { LoginForm } from "./components/LoginForm";
export { SignupForm } from "./components/SignupForm";
export { useAuth } from "./hooks/useAuth";
export { useSession } from "./hooks/useSession";
export { AuthService } from "./services/auth.service";
export type { User, Session, AuthConfig } from "./types";
// Consumer imports cleanly
import { LoginForm, useAuth } from "@/auth";Colocation Principle
Keep related files close together. Tests, styles, and stories live next to the code they describe:
src/auth/components/
LoginForm.tsx
LoginForm.test.tsx
LoginForm.module.css
LoginForm.stories.tsx
# NOT separated by type
__tests__/
components/
LoginForm.test.tsx # Far from the component
styles/
LoginForm.module.css # Far from the componentBackend Project Structure
src/
modules/
auth/
auth.controller.ts
auth.service.ts
auth.repository.ts
auth.routes.ts
auth.middleware.ts
auth.types.ts
auth.test.ts
index.ts
users/
users.controller.ts
users.service.ts
users.repository.ts
users.routes.ts
users.types.ts
users.test.ts
index.ts
common/
middleware/
error-handler.ts
rate-limiter.ts
utils/
logger.ts
config.ts
types/
api.ts
app.ts # App setup
server.ts # Server entry pointAnti-Patterns
What NOT to Do
- God files: A single
utils.tsorhelpers.tsthat grows to 1000+ lines with unrelated functions. Split by domain. - Deeply nested barrels: Barrel files re-exporting from other barrel files create circular dependencies and slow builds.
- Empty wrapper files: Do not create
index.tsthat just re-exports a single file. Only use barrels when a folder has 3+ exports. - Organizing by layer globally:
controllers/,services/,models/at the top level forces developers to jump between distant directories for a single feature. - Premature abstraction: Do not create a
shared/module for code used by only one feature. Move to shared only when genuinely used by 3+ features.
# BAD: God file
src/utils.ts # 1200 lines, 40 exports
# GOOD: Split by purpose
src/shared/utils/
format.ts # Date, currency, string formatting
validation.ts # Input validation helpers
math.ts # Numeric utilitiesQuick Reference
File Size Targets:
Ideal: 200-400 lines
Acceptable: 100-600 lines
Refactor: 600-800 lines
Must split: > 800 lines
Organization Priority:
1. Feature-based (preferred)
2. Domain-driven (for large apps)
3. Type-based (only for very small projects)
Colocation Rules:
- Tests next to source files
- Styles next to components
- Types in same feature folder
- Move to shared/ only when used by 3+ features
Barrel Export Rules:
- One index.ts per feature folder
- Export only the public API
- No barrel-of-barrels chains
- Skip barrel for folders with < 3 exports
Split Signals:
- Comment banners separating sections
- Multiple unrelated export groups
- Scrolling past 400 lines regularly
- File name is too generic (utils, helpers, misc)Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

