The Fundamental Principle
The Scope Rule is the architectural foundation that all Scope Rule Architects enforce:“Scope determines structure”Code placement is not based on technical categories, but on actual usage patterns.
The Rule
The Scope Rule consists of two simple, non-negotiable directives:2+ Features Rule
Code used by 2 or more features MUST go in global/shared directories
1 Feature Rule
Code used by only 1 feature MUST stay local within that feature
No Exceptions
The consistency provided by this rigid enforcement is what makes the architecture work at scale.Real Examples from Frameworks
Next.js Structure
From the Next.js Scope Rule Architect:product-list.tsxis only used in the shop page → stays local inshop/_components/cart-item.tsxis only used in the cart page → stays local incart/_components/product-card.tsxis used in shop, cart, AND wishlist → goes toshared/components/
Angular Structure
From the Angular Scope Rule Architect:product-list.tscontains shop-specific filtering logic → stays inshop/components/cart-item.tshas cart-specific quantity controls → stays incart/components/product-card.tsdisplays products across multiple features → goes toshared/components/
Astro Structure
From the Astro Scope Rule Architect:blog-card.astroonly displays blog content → stays inblog/components/add-to-cart.tsxonly handles shop cart actions → stays inshop/components/Newsletter.tsxappears in blog sidebar AND footer → goes tocomponents/islands/
Making Decisions
When placing a new component, service, or utility:Count Usage
Count exactly how many features currently use this code. Be precise—don’t guess or plan for future usage.
Apply the Rule
- If count = 1 → Place locally within that feature
- If count ≥ 2 → Place in shared/global directories
Benefits of the Scope Rule
Perfect Traceability
Know exactly where to find code based on what uses it. No more searching through massive shared directories.
Screaming Architecture
Structure immediately communicates functionality. New developers understand the codebase by looking at the file tree.
Scalable Organization
As your application grows, the structure grows naturally. No reorganization needed.
Zero Architectural Debt
Prevents the “everything in components/” anti-pattern where shared folders become dumping grounds.
Clear Ownership
Teams know which code belongs to which feature, making collaboration smoother.
Easier Refactoring
Move features as complete units. Everything related is co-located.
Common Questions
What if I think a component might be shared in the future?
What if I think a component might be shared in the future?
What about utilities that 'feel' like they should be shared?
What about utilities that 'feel' like they should be shared?
Can I create sub-categories within shared directories?
Can I create sub-categories within shared directories?
What counts as a 'feature'?
What counts as a 'feature'?
A feature is a cohesive unit of functionality from the user’s perspective. In Next.js, route groups like
(shop) or (auth) are features. In Angular, feature modules or standalone feature components. In Astro, top-level page directories like blog/ or shop/. If it delivers value independently, it’s a feature.What if refactoring to shared is too much work right now?
What if refactoring to shared is too much work right now?
Anti-Patterns to Avoid
Further Reading
Screaming Architecture
Learn how the Scope Rule enables architecture that communicates intent
Co-location
Understand the benefits of keeping related code together
