colocate-related-code
Installation
SKILL.md
Summary
Place code as close as possible to where it is relevant. If a utility, style, or test is only used by a specific component or feature, put it in that component's directory. Avoid generic "global" buckets like /utils, /styles, or /types unless the content is truly shared across the entire application.
Rationale
- Maintainability: When you delete a component/feature, you can delete its entire directory and know you've cleaned up everything. (No "zombie code" left in global folders).
- Discoverability: You don't have to hunt through a massive
/utilsfolder to find the helper used byUserProfile. It's right there inUserProfile/utils.ts. - Scalability: As the app grows, global folders become dumping grounds. Colocated feature folders stay self-contained.
Guidance
- Directory Structure:
- Bad: Separating by technology (
/controllers,/views,/models). - Good: Separating by feature (
/user-profile,/shopping-cart).
- Bad: Separating by technology (
- What to Colocate:
- Tests:
MyComponent.test.tsnext toMyComponent.ts. - Styles:
MyComponent.module.cssnext toMyComponent.ts. - Types:
types.tsinside the feature folder if only used there. - Utils:
helpers.tsinside the feature folder if only used there.
- Tests: