Import Path Standards
Canonical import patterns for consistent, maintainable code across the entire codebase
Import Path Standards
Overview
This guide establishes canonical import paths for all modules in our project. By following these standards, we ensure consistency across documentation, examples, and actual code implementation.
Why canonical imports matter: They reduce cognitive load, speed up development, and eliminate the "which import should I use?" decision fatigue. When everyone uses the same import patterns, code reviews focus on logic rather than style choices.
Core Principle
Single Source of Truth: Each module has ONE canonical import path used consistently across:
- Code implementation
- Documentation examples
- Type definitions
- Test files
Canonical Import Patterns
Theme Management
Domain Logic (Cross-Feature Business Logic)
Feature Logic (Feature-Specific Logic)
UI Components
Shared Utilities
Architecture Decision Guide
Understanding when to use domain vs feature imports is crucial for maintainable architecture:
Domain Logic (@/core/domains/[domain])
Use when your code:
- Is used by 3+ features
- Represents core business entities (User, Product, Order)
- Contains cross-cutting business rules
- Needs to be highly reusable and stable
Examples:
Real-world scenarios:
- User profile data accessed from navigation, settings, and checkout
- Product information displayed in lists, details, and cart
- Order status shown in checkout confirmation and order history
Import Structure Requirements
Path Alias Standards
All imports must use the @/ prefix for consistency:
Barrel Exports Required
Every module directory must have an index.ts that exports the public API:
Import Order Convention
Follow this order for clean, predictable imports:
Documentation Standards
Code Examples in Documentation
All documentation examples must use canonical import paths:
Cross-References
When linking to other guides, reference the canonical source rather than duplicating information:
Migration Strategies
Updating Existing Code
When refactoring imports to follow these standards:
Automated Tools
Consider these tools for maintaining import consistency:
- ESLint rules for import path validation
- Pre-commit hooks for import checking
- IDE settings for auto-import configuration
Benefits
Following these import standards provides:
- Consistent Learning: Developers learn one import pattern
- Easier Refactoring: Changes only need updates in one place
- Clear Dependencies: Import paths show architectural relationships
- Reduced Confusion: No guessing which import to use
- Better Tooling: IDEs provide better autocomplete and navigation
Common Patterns Reference
| Code Type | Location | Import Pattern | Example |
|---|---|---|---|
| Theme | Core Shared | @/core/shared/styles | useTheme |
| Domain Logic | Core Domains | @/core/domains/[domain] | useProducts |
| Feature Logic | Features | @/features/[feature]/hooks | useCart |
| Foundation UI | UI Foundation | @/ui/foundation/[component] | Button |
| Pattern UI | UI Patterns | @/ui/patterns/[component] | Modal |
| Business UI | UI Business | @/ui/business/[component] | ProductCard |
| Shared Utils | Core Shared | @/core/shared/utils | formatCurrency |
Pro tip: Bookmark this reference table! Most import decisions can be made quickly by checking the code type and following the corresponding pattern.
Troubleshooting
Common Issues
Import not found errors:
- Verify the barrel export exists in the target module's
index.ts - Check that the
@/prefix is included - Ensure the path matches the actual directory structure
Multiple ways to import the same thing:
- Always choose the canonical pattern from this guide
- When in doubt, use the most general path (barrel export over specific file)
IDE not suggesting correct imports:
- Configure your IDE's auto-import settings to prefer canonical paths
- Update
tsconfig.jsonpath mappings if necessary
For additional guidance, see the Feature Implementation Decision Tree for architectural placement decisions.
Why Standards Matter
Understanding the fundamental importance of coding standards, rules, and consistency in software development.
AI Coding Standards
Comprehensive guidelines for maintaining code quality, security, and team productivity when using AI coding assistants like GitHub Copilot, Claude, and ChatGPT.