UI Architecture Overview
Comprehensive guide to UI folder organization, component hierarchy, and integration with the core architecture for consistent frontend development.
UI Architecture Overview
Overview
This document provides a comprehensive guide to our UI architecture, explaining how the ui/ folder integrates with our core architecture to create a scalable, maintainable, and AI-collaboration-friendly component system. It establishes the foundation for consistent UI development across all frontend projects.
Purpose & Scope
This guide helps developers and AI collaborators understand:
- How UI components fit within our overall architecture
- The relationship between foundation, patterns, and business components
- Integration patterns with domains, features, and shared utilities
- Design token usage and theming strategies
- Component development workflows for maximum consistency
UI Architecture Philosophy
Design Principles
Our UI architecture follows these core principles:
- Separation of Concerns: Clear boundaries between presentation, behavior, and business logic
- Atomic Composition: Build complex interfaces from simple, reusable components
- Design Token Integration: Consistent theming through centralized design tokens
- AI-Friendly Structure: Predictable patterns that enable seamless AI collaboration
- Feature Integration: Smooth integration with our feature-based architecture
Three-Layer Architecture (Canonical Definition)
Single Source of Truth: This is the canonical definition of our three-layer UI architecture. All other documents should reference this section rather than duplicating the explanation.
Our UI system is organized into three distinct layers, each with specific responsibilities and clear boundaries. This architecture ensures maximum reusability, maintainability, and clarity in component organization.
Foundation Layer
The Foundation Layer contains atomic UI building blocks that form the base of our design system.
Characteristics:
- Single Responsibility: Each component has one clear purpose
- No Business Logic: Pure presentation components with no domain knowledge
- Design Token Driven: All styling comes from centralized design tokens
- Highly Reusable: Used across multiple patterns and features
- Accessibility First: Built with WCAG compliance as a core requirement
Examples:
Button- Primary action componentInput- Text input fieldsText- Typography componentCard- Content containerIcon- Icon display component
Import Pattern:
Patterns Layer
The Patterns Layer combines foundation components to create complex, reusable UI patterns.
Characteristics:
- Composed Architecture: Built exclusively from foundation components
- Complex Behavior: Handle sophisticated user interactions
- Reusable Patterns: Common UI patterns used across features
- No Domain Logic: Generic and not tied to specific business entities
- Configurable: Flexible through props and composition
Examples:
Modal- Overlay dialogs using Card, Button, and TextForm- Complete form wrapper with validationDataTable- Data grid with sorting/filteringSearchBox- Search input with suggestionsToast- Notification messages
Import Pattern:
Business Layer
The Business Layer contains domain-aware components that understand business entities and logic.
Characteristics:
- Domain Aware: Work with specific business entities (Product, User, Order)
- Feature Shared: Used across multiple features
- Business Logic: Handle domain-specific calculations and rules
- API Integration: May use domain hooks for data fetching
- Context Sensitive: Behavior changes based on business context
Examples:
ProductCard- Product display with pricing logicUserAvatar- User profile with role indicatorsOrderStatus- Order state with business rulesPaymentMethod- Payment display with validationAddToCart- Shopping cart integration
Import Pattern:
Layer Dependencies
The architecture enforces strict dependency rules:
Dependency Rules:
- Foundation components can only import from design tokens and shared utilities
- Patterns can import from Foundation but not from Business
- Business can import from both Foundation and Patterns
- Features can import from all three layers
- Never import across features or from features into UI layers
Decision Framework
When creating a new component, ask these questions:
-
Does it have business logic or domain knowledge?
- Yes → Business Layer
- No → Continue to question 2
-
Is it composed of multiple other components?
- Yes → Patterns Layer
- No → Foundation Layer
-
Is it used in only one feature?
- Yes → Keep it in the feature folder
- No → Move to appropriate UI layer
This three-layer approach ensures:
- Clear separation of concerns
- Maximum component reusability
- Predictable component locations
- Easy onboarding for new developers
- Efficient AI collaboration
UI Folder Structure Deep Dive
Complete UI Organization
Component Hierarchy and Dependencies
Foundation Layer Architecture
Purpose and Characteristics
Foundation components are the atomic building blocks of our design system:
- Single Responsibility: Each component has one clear purpose
- No Business Logic: Pure presentation components
- Design Token Driven: All styling comes from
core/shared/styles/ - Highly Reusable: Used across multiple patterns and features
- Accessible: Built with accessibility as a core requirement
Foundation Component Categories
Core Interactive Elements
Form Elements
Display Elements
Layout Elements
Foundation Component Example
For a complete implementation example of a foundation component, including all variants, states, accessibility features, and testing patterns, see the Button Component.
Foundation components like Button demonstrate key principles:
- Single responsibility (action triggering)
- Design token usage for all styling
- Comprehensive prop interfaces
- Built-in accessibility
- No business logic
Patterns Layer Architecture
Purpose and Characteristics
Pattern components combine foundation components to create complex, reusable UI patterns:
- Composed Architecture: Built from foundation components
- Complex Behavior: Handle sophisticated user interactions
- Reusable Patterns: Common UI patterns used across features
- No Domain Logic: Generic, not tied to specific business entities
- Configurable: Flexible through props and composition
Pattern Component Categories
Navigation Patterns
Data Display Patterns
Feedback Patterns
Form Patterns
Pattern Component Example
For a comprehensive pattern component example showing how to compose foundation components into complex UI patterns, see the Modal Pattern.
Pattern components like Modal demonstrate:
- Composition of multiple foundation components
- Complex interaction handling
- Flexible configuration through props
- Accessibility management
- No domain-specific logic
Business Layer Architecture
Purpose and Characteristics
Business components understand domain entities and contain business logic:
- Domain Aware: Work with business entities (Product, User, Order)
- Feature Shared: Used across multiple features
- Business Logic: Handle domain-specific calculations and rules
- API Integration: May use domain hooks for data fetching
- Context Sensitive: Behavior changes based on business context
Business Component Categories
Entity Display Components
Status and State Components
Interactive Business Components
Business Component Example
Design Token Integration
Token Usage Hierarchy
Token Categories and Usage
Color Tokens
Typography Tokens
Spacing Tokens
Integration with Core Architecture
Domain Integration Patterns
Business components can integrate with domains through hooks:
Feature Integration Patterns
Features compose UI components to create complete user experiences:
AI Collaboration Benefits
Predictable Structure
The three-layer architecture provides clear guidelines for AI:
Consistent Prompting
Standardized AI prompts ensure consistency:
Migration and Adoption Strategy
Existing Project Migration
-
Audit Current Components
- Categorize existing components
- Identify dependencies and usage patterns
-
Create UI Folder Structure
- Set up foundation/patterns/business folders
- Move components to appropriate locations
-
Implement Design Token Integration
- Replace hardcoded values with tokens
- Update styling patterns
-
Update Import Paths
- Fix all component imports
- Add barrel exports for clean imports
New Project Setup
-
Initialize UI Structure
- Create folder hierarchy
- Set up barrel export files
-
Implement Core Foundation Components
- Start with Button, Text, Card basics
- Build up component library gradually
-
Establish Patterns
- Create common patterns as needed
- Document usage examples
-
Add Business Components
- Build domain-aware components
- Integrate with domain hooks
Related Documents
- UI Architecture Standards - Mandatory development standards
- AI Collaboration Guide for UI Development - AI consistency patterns
- Foundation Components Guide - Component development patterns
- Component Development Workflow - Step-by-step development process
- Core Architecture - Overall system architecture
- Domain Architecture Guide - Domain integration patterns
- Project Structure - File organization standards
- Communication Patterns - Cross-feature integration
- Shared Utilities Guide - Shared code organization