1 min read

Nest component hierarchy

Component hierarchy is an architectural pattern that organizes UI elements in a structured, parent-child relationship. Unlike atomization which focuses on breaking things down, hierarchy focuses on how components are composed together. This structured approach helps AI systems better understand the relationships between components, their data flow patterns, and their role within the larger application structure, enabling more accurate code analysis and generation.

šŸ’”
A structured component hierarchy helps AI understand how parts of your app connect and share data. Organizing components systematically creates a codebase that both AI and developers can easily navigate.

Example

Feature-based folder structure groups components by their feature rather than their type.

components/
ā”œā”€ā”€ Catalog/           # Feature
ā”‚   ā”œā”€ā”€ Products/      # Sub-feature
ā”‚   ā”‚   ā”œā”€ā”€ List/      # Feature module
ā”‚   ā”‚   ā”‚   ā”œā”€ā”€ Grid   # Component
ā”‚   ā”‚   ā”‚   ā””ā”€ā”€ List
ā”‚   ā”‚   ā””ā”€ā”€ Filters/
ā”‚           ā”œā”€ā”€ Category
ā”‚           ā””ā”€ā”€ Price
ā””ā”€ā”€ Checkout/
    ā””ā”€ā”€ Cart/
        ā”œā”€ā”€ Summary/
        ā”‚   ā”œā”€ā”€ Items
        ā”‚   ā””ā”€ā”€ Total
        ā””ā”€ā”€ Actions/
            ā”œā”€ā”€ Quantity
            ā””ā”€ā”€ Remove

Recommendation

To implement this effectively, organize your components in directories that reflect their relationships, with parent components in root directories and child components in nested subdirectories. Follow consistent naming conventions and file structures throughout your project. Large components should focus on composition and data flow, while nested components handle specific UI elements or functionality. Document this hierarchical structure in your architectural guidelines to maintain consistency across the project.

Subscribe to our newsletter.

Be the first to know - subscribe today