Architecture
Relevant source filesPurpose and Scope
This document describes the architectural design of@ui8kit/core, including its three-layer component hierarchy, variant system, build pipeline, and module organization. It explains the structural relationships between primitives, composite components, and layouts, along with the underlying mechanisms for styling, type safety, and distribution.
For detailed API documentation of individual components and their props, see API Reference. For installation and configuration instructions, see Getting Started. For development workflows and usage patterns, see Development Guide.
Three-Layer Architecture Overview
The library implements a three-layer architecture aligned with atomic design principles: atoms (core primitives), molecules (UI components), and organisms (layout templates). Each layer builds upon the previous one through composition and prop forwarding.Layer Hierarchy and Dependencies
Layer 1: Core Primitives
Five fundamental building blocks located in src/core/ui/ provide direct access to the CVA variant system. These primitives render as semantic HTML elements and serve as the foundation for all higher-level components.| Primitive | Base Element | Primary Use Case | Key Props |
|---|---|---|---|
Box | div | Generic container | component, all variants |
Block | section | Semantic blocks | component, all variants |
Grid | div | CSS Grid layouts | cols, gap, grid variants |
Flex | div | Flexbox layouts | direction, align, justify |
Stack | div | Vertical/horizontal stacking | gap, align, extends Flex |
- All primitives support
forwardReffor DOM access: src/core/ui/Box.tsx src/core/ui/Block.tsx - Polymorphic
componentprop enables semantic HTML tags: src/core/ui/Block.tsx10-15 - Direct variant application without intermediate abstraction: src/core/ui/Box.tsx20-30
Layer 2: UI Components
Fifteen composite components in src/components/ui/ extend core primitives through prop forwarding. These components add semantic structure, compound patterns, and specialized behavior while inheriting the full variant system.| Component | Extends | Compound Parts | Special Features |
|---|---|---|---|
Card | Block | Header, Content, Footer, Title, Description | Compound component pattern |
Button | Box | - | Loading state, sections (left/right) |
Badge | Box | - | Dot indicator, variant system |
Title | Box | - | Heading hierarchy (h1-h6) |
Text | Box | - | Semantic text elements (p, span, em, strong) |
Container | Block | - | Responsive max-width presets |
Group | Flex | - | Horizontal layout helper |
Icon | Box | - | SVG wrapper with size control |
Image | Box | - | Aspect ratio, object-fit |
Sheet | - | - | Drawer/sheet with transitions |
Accordion | - | Item, Trigger, Content | Expandable sections |
Layer 3: Layouts
Three layout templates in src/layouts/ orchestrate UI components into application structures. These templates handle complex composition patterns like resizable panels, grid systems, and responsive breakpoints.| Layout | Primary Use | Key Features | Dependencies |
|---|---|---|---|
DashLayout | Dashboard applications | Sidebar, header, resizable panels | react-resizable-panels |
LayoutBlock | Content sections | Grid layout, content hooks | Grid primitive |
SplitBlock | Two-column layouts | Responsive split, image/content | Container, Grid |
LayoutBlock component demonstrates the content hooks pattern for dynamic rendering:
Architectural Principles
Atomic Design Alignment
The three-layer structure maps directly to atomic design methodology:| Layer | Atomic Design Level | Complexity | Composition |
|---|---|---|---|
| Layer 1 (Core) | Atoms | Minimal | Direct variant application |
| Layer 2 (UI) | Molecules | Moderate | Extends atoms, prop forwarding |
| Layer 3 (Layouts) | Organisms | Complex | Composes molecules into templates |
Minimalism Philosophy
The library achieves its minimalist goal through three key constraints:- 15 composite components provide 95% coverage of UI needs: README.md370-386
- 12 reusable variants eliminate 80% of custom classes: README.md170-217
- 5 core primitives serve as universal building blocks: README.md81-103
Prop Forwarding Pattern
All Layer 2 components inherit variant props from their base primitives through explicit prop forwarding:- Type Safety: TypeScript validates all forwarded props
- Variant Inheritance: Components automatically gain new variants added to primitives
- Composition Flexibility: Multiple variant sources combine without conflict
Semantic HTML and Data Attributes
Every component renders semantic HTML5 elements and includesdata-class attributes for identification:
| Pattern | Purpose | Example |
|---|---|---|
| Semantic elements | Accessibility, SEO | <Block component="section">, <Block component="nav"> |
data-class attributes | DOM targeting, testing | <div data-class="card">, <div data-class="card-header"> |
| Polymorphic components | Flexible element types | component prop accepts any valid HTML tag |
Component Relationships and File Structure
Directory Organization
Component Import and Export Flow
Composition Patterns
The library supports five distinct composition patterns for different architectural needs:- Direct Primitive: Use
BoxorBlockwithcomponentprop for semantic HTML - Compound Components: Use structured components like
Card.Header, enables flexible composition - Prop Forwarding: Composite components merge their own variants with inherited base variants
- Layout Composition: Templates orchestrate multiple components into application structures
- Content Hooks: Layouts accept render functions for dynamic content injection
Variant System Architecture
CVA Integration
The variant system is powered byclass-variance-authority, providing type-safe, composable styling utilities. All variants are defined in src/core/variants/ and applied through core primitives.
12 Variant Categories:
| Category | Variants | Values | Purpose |
|---|---|---|---|
| Spacing | p, m, px, py, pt, pb, pl, pr, mx, my, mt, mb, ml, mr | none, xs, sm, md, lg, xl, 2xl, auto | Padding and margins |
| Colors | bg, c, borderColor | Design system colors | Background, text, border colors |
| Layout | w, h, minH, maxW, position | auto, full, screen, fit, min, max | Width, height, positioning |
| Typography | size, weight, align, leading | Font sizes and weights | Text styling |
| Effects | rounded, shadow, border | none, sm, md, lg, xl, 2xl, 3xl, full | Visual enhancements |
| Display | display | block, inline, flex, grid, none | Display modes |
| Flexbox | direction, align, justify, wrap | Flex properties | Flexbox layouts |
| Grid | cols, rows, gap | Grid properties | Grid layouts |
| Overflow | overflow, overflowX, overflowY | auto, hidden, scroll, visible | Overflow control |
| Cursor | cursor | pointer, default, move, etc. | Cursor styles |
| Opacity | opacity | 0 to 100 | Transparency |
| Z-Index | z | 0, 10, 20, 30, 40, 50 | Stacking order |
Variant Application Pipeline
- Prop Input: Developer provides variant props (e.g.,
p='lg') - Variant Resolution: CVA engine resolves props to Tailwind classes using variant definitions
- Class Generation: Produces className string (e.g.,
'p-8 rounded-xl shadow-md') - Whitelist Validation: Generated classes validated against src/lib/core-classes.json (618 classes)
- Tailwind Processing: Tailwind CSS applies utility classes, using whitelist as safelist to prevent purging
- DOM Output: Final className applied to rendered element
Class Whitelist Generation
The build-timecva-extractor.ts script scans all variant definitions to generate the class whitelist:
Extractor Workflow:
- Spacing:
p-0,p-1,p-2, …,p-96,m-0,m-1, …,m-96,mx-auto,my-auto - Rounded:
rounded-none,rounded-sm,rounded-md, …,rounded-full - Shadow:
shadow-none,shadow-sm,shadow-md, …,shadow-2xl - Colors: All design system color utilities
- Layout:
w-full,w-screen,h-full,h-screen, etc.
Build-Time vs Runtime Architecture
The system maintains strict separation between build-time tooling and runtime code to optimize bundle size and developer experience.Build-Time Systems
| Command | Tool | Output | Purpose |
|---|---|---|---|
bun scripts/cva-extractor.ts | Custom script | core-classes.json | Extract variant classes |
tsc -p tsconfig.json | TypeScript | dist/ directory | Compile to ES2022 modules |
eslint src --ext .ts,.tsx | ESLint | Console output | Code quality validation |
buildy-ui scan | buildy-ui CLI | registry.json | Component metadata |
Runtime Systems
| Dependency | Type | Usage | Components |
|---|---|---|---|
react | Peer | Component framework | All components |
react-dom | Peer | DOM rendering | All components |
class-variance-authority | Direct | Variant engine | Core primitives |
lucide-react | Direct | Icons | Sheet, Accordion |
react-resizable-panels | Direct | Resizable panels | DashLayout |
Distribution and Module System
Package Configuration
The package.json defines multiple entry points and export patterns: Main Entry Points:- Primary export (
.): All components, variants, and theme utilities - Registry export (
./registry.json): Component metadata for tooling - Classes export (
./core-classes.json): CSS class whitelist for Tailwind config
Integration Methods
Integration Comparison:
| Method | Installation | Updates | Bundle | Use Case |
|---|---|---|---|---|
| Full NPM install | npm install @ui8kit/core | npm update | Full library | Complete library needed |
| Per-component | npx buildy-ui add button card | Manual re-add | Minimal | Bundle optimization |
| Git submodule | git submodule add | git submodule update | Full source | Monorepo architecture |
| Direct source | Copy files manually | Manual sync | Custom | Custom modifications |
Component Registry Structure
The src/registry.json file provides metadata for tooling automation: Registry Schema:- Per-component installation via
buildy-uiCLI - Automatic dependency resolution
- Programmatic component discovery
- Build tool integration
Cross-Cutting Concerns
TypeScript Configuration
The TypeScript setup balances strict type safety with developer ergonomics: Key Settings from tsconfig.json:| Setting | Value | Purpose |
|---|---|---|
target | ES2022 | Modern JavaScript features |
module | ESNext | ES module support |
jsx | react-jsx | React 17+ JSX transform |
strict | true | Maximum type safety |
skipLibCheck | true | Faster compilation |
declaration | true | Generate .d.ts files |
declarationMap | true | Source map for types |
outDir | ./dist | Build output directory |
Theme System
The theme system provides dark mode support with automatic persistence: ThemeProvider Architecture:
Usage Pattern:
Accessibility Features
The library implements accessibility through semantic HTML and ARIA patterns: Accessibility Strategies:- Semantic HTML5 elements:
<Block component="section">,<Block component="nav"> - Heading hierarchy:
<Title order={1}>renders<h1>, ensuring proper document outline - Keyboard navigation: Interactive components support Tab, Enter, Space
- ARIA attributes: Accordion and Sheet components include proper ARIA labels
- Focus management: Focus visible states and logical tab order
- Color contrast: Design system colors meet WCAG AA standards
Subsection References
This architecture overview provides the foundation for understanding the library’s structure. For detailed information on specific subsystems, see the following pages:- Core Components - Detailed documentation of the 5 core primitives
- Variant System - Complete variant definitions and usage patterns
- UI Components - Extended component implementations and prop forwarding
- Layouts - Layout template patterns and composition strategies
- Package Structure - Module exports, entry points, and distribution setup
- Build System - TypeScript compilation, build scripts, and artifact generation
- Component Registry - Registry system, metadata format, and tooling integration
- TypeScript Configuration - Type system setup, path aliases, and compiler options