Skip to main content

Architecture

Relevant source files

Purpose 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

Sources: README.md62-89 README.md105-168 src/components/README.md9-19

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. Implementation Details: Sources: README.md81-103 src/core/ui/ src/components/README.md23-92

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. Prop Forwarding Pattern:
Sources: README.md105-145 src/components/ui/ src/components/README.md94-177

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. Content Hooks Pattern: The LayoutBlock component demonstrates the content hooks pattern for dynamic rendering:
Sources: README.md147-168 src/layouts/DashLayout.tsx src/layouts/LayoutBlock.tsx src/layouts/SplitBlock.tsx

Architectural Principles

Atomic Design Alignment

The three-layer structure maps directly to atomic design methodology: This alignment ensures components are organized by complexity and reusability, making the codebase predictable and maintainable. Sources: README.md62-79 .devin/wiki.json4

Minimalism Philosophy

The library achieves its minimalist goal through three key constraints:
  1. 15 composite components provide 95% coverage of UI needs: README.md370-386
  2. 12 reusable variants eliminate 80% of custom classes: README.md170-217
  3. 5 core primitives serve as universal building blocks: README.md81-103
This constraint-based design reduces bundle size, development time, cognitive load, and CSS complexity. Sources: README.md388-403 .devin/wiki.json8-9

Prop Forwarding Pattern

All Layer 2 components inherit variant props from their base primitives through explicit prop forwarding:
This pattern enables:
  • 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
Sources: src/components/README.md9-19 .devin/wiki.json12-13

Semantic HTML and Data Attributes

Every component renders semantic HTML5 elements and includes data-class attributes for identification: Example from Card component:
Sources: README.md14 src/components/README.md223-235

Component Relationships and File Structure

Directory Organization

Sources: README.md1-453 package.json1-50

Component Import and Export Flow

Entry Points: The main entry point src/index.ts re-exports all public APIs:
Sources: src/index.ts package.json30-36

Composition Patterns

The library supports five distinct composition patterns for different architectural needs:
Pattern Details:
  1. Direct Primitive: Use Box or Block with component prop for semantic HTML
  2. Compound Components: Use structured components like Card.Header, enables flexible composition
  3. Prop Forwarding: Composite components merge their own variants with inherited base variants
  4. Layout Composition: Templates orchestrate multiple components into application structures
  5. Content Hooks: Layouts accept render functions for dynamic content injection
Sources: src/components/GUIDE_CREATE_FORM.md10-13 src/layouts/LayoutBlock.tsx15-22 src/layouts/DashLayout.tsx72-99

Variant System Architecture

CVA Integration

The variant system is powered by class-variance-authority, providing type-safe, composable styling utilities. All variants are defined in src/core/variants/ and applied through core primitives. 12 Variant Categories: Sources: README.md170-217 src/core/variants/

Variant Application Pipeline

Pipeline Stages:
  1. Prop Input: Developer provides variant props (e.g., p='lg')
  2. Variant Resolution: CVA engine resolves props to Tailwind classes using variant definitions
  3. Class Generation: Produces className string (e.g., 'p-8 rounded-xl shadow-md')
  4. Whitelist Validation: Generated classes validated against src/lib/core-classes.json (618 classes)
  5. Tailwind Processing: Tailwind CSS applies utility classes, using whitelist as safelist to prevent purging
  6. DOM Output: Final className applied to rendered element
Sources: README.md98-124 src/lib/core-classes.json1-619 scripts/cva-extractor.ts223-260

Class Whitelist Generation

The build-time cva-extractor.ts script scans all variant definitions to generate the class whitelist: Extractor Workflow:
Generated Class Categories:
  • 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.
Sources: scripts/cva-extractor.ts1-260 src/lib/core-classes.json617-619

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

Build Commands: Sources: scripts/cva-extractor.ts1-260 package.json19-25

Runtime Systems

Runtime Dependencies: Sources: package.json42-56 src/themes/providers/ThemeProvider.tsx1-109

Distribution and Module System

Package Configuration

The package.json defines multiple entry points and export patterns: Main Entry Points:
Export Pattern:
  • 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
Sources: package.json30-42

Integration Methods

Integration Comparison: Sources: README.md252-277 src/registry.json2-244

Component Registry Structure

The src/registry.json file provides metadata for tooling automation: Registry Schema:
Example Entry:
This metadata enables:
  • Per-component installation via buildy-ui CLI
  • Automatic dependency resolution
  • Programmatic component discovery
  • Build tool integration
Sources: src/registry.json1-244 README.md251-276

Cross-Cutting Concerns

TypeScript Configuration

The TypeScript setup balances strict type safety with developer ergonomics: Key Settings from tsconfig.json: Path Aliases:
For detailed TypeScript configuration, see TypeScript Configuration. Sources: tsconfig.json1-30 package.json19-25

Theme System

The theme system provides dark mode support with automatic persistence: ThemeProvider Architecture:
Usage Pattern:
For detailed theme implementation, see Dark Mode. Sources: src/themes/providers/ThemeProvider.tsx1-109 README.md219-249

Accessibility Features

The library implements accessibility through semantic HTML and ARIA patterns: Accessibility Strategies:
  1. Semantic HTML5 elements: <Block component="section">, <Block component="nav">
  2. Heading hierarchy: <Title order={1}> renders <h1>, ensuring proper document outline
  3. Keyboard navigation: Interactive components support Tab, Enter, Space
  4. ARIA attributes: Accordion and Sheet components include proper ARIA labels
  5. Focus management: Focus visible states and logical tab order
  6. Color contrast: Design system colors meet WCAG AA standards
Sources: README.md14 src/components/ui/

Subsection References

This architecture overview provides the foundation for understanding the library’s structure. For detailed information on specific subsystems, see the following pages: For API documentation of specific components and their props, see API Reference. For development workflows and usage examples, see Development Guide. Sources: .devin/wiki.json45-133 README.md1-453