The Core Principle
“Scope determines structure” This fundamental rule drives all placement decisions:- Code used by 2+ features → MUST go in global/shared directories
- Code used by 1 feature → MUST stay local in that feature
- NO EXCEPTIONS - This rule is absolute and non-negotiable
Decision Framework
Count the Usage
Identify exactly how many features use the component. Be precise and systematic:
- Review all imports of the component
- Count unique feature directories that import it
- Don’t count multiple components within the same feature as separate uses
Apply the Scope Rule
Based on your count, apply the rule strictly:1 Feature = Local Placement2+ Features = Shared Placement
Validate Against Framework Patterns
Ensure your placement aligns with framework-specific best practices:
- Angular
- Next.js
- Astro
- React
- All components MUST be standalone (Angular 20+)
- Use
ChangeDetectionStrategy.OnPushfor all components - Leverage signals with
signal(),computed(), andeffect() - Place signal stores locally or globally based on scope
Real-World Examples
Example 1: Authentication Component
Scenario:SocialLogin component used in both login and register pages.
Analysis:
Example 2: UI Button Component
Scenario:Button component used throughout the application.
Analysis:
Example 3: Next.js Server Action
Scenario:productActions used only within shop feature.
Analysis:
Edge Cases and Special Considerations
What if I'm unsure about future usage?
What if I'm unsure about future usage?
Start local, refactor when needed.When uncertain:
- Place the component locally within the feature
- Add a comment noting potential for extraction
- When a second feature needs it, move to shared/
- Update all imports
How do I handle route-specific components in Next.js?
How do I handle route-specific components in Next.js?
Use private folders for co-location.Private folders (
_components) keep route-specific code co-located without polluting the routing system.When should Astro components be islands vs static?
When should Astro components be islands vs static?
Static by default, islands only when absolutely necessary.Use client islands when you need:Placement rule applies equally to both static components and islands.
- User interaction (forms, buttons that mutate state)
- Real-time updates (live chat, notifications)
- Client-side state management
How do I handle Angular signal stores?
How do I handle Angular signal stores?
Apply the same scope rule to state management.State management follows the same scoping rules as components.
What about utilities and helper functions?
What about utilities and helper functions?
Same rule applies to all code, not just components.
Quality Checklist
Before finalizing any placement decision, verify:- Scope verification: Have you correctly counted feature usage?
- Framework compliance: Are you using framework-specific best practices?
- Naming validation: Do component names follow conventions?
- Screaming test: Can someone understand the structure at a glance?
- Performance: Are you optimizing for bundle size and rendering?
- Future-proofing: Will this scale as the application grows?
Next Steps
Project Setup
Learn how to set up new projects with proper structure from the start
Migration Guide
Restructure existing projects to follow the Scope Rule
Best Practices
Quality checks and patterns for maintaining clean architecture
Agents Reference
Explore framework-specific agents for automated guidance
