System Architecture Overview
The Hikari framework adopts a modular design, consisting of multiple independent packages, each responsible for specific functional domains.
Core Systems
1. Palette System (hikari-palette)
Rust implementation of the traditional Chinese color system.
Responsibilities:
- Provides 660+ traditional Chinese color definitions
- Theme palette management
- Utility class generator
- Opacity and color blending
Core Features:
use ;
// Use traditional colors
let red = Cinnabar;
let blue = Azurite;
// Opacity handling
let semi_red = opacity;
// Theme system
let theme = default;
println!;
Design Philosophy:
- Cultural Confidence: Using traditional color names
- Type Safety: Compile-time color value checking
- High Performance: Zero-cost abstractions
2. Theme System (hikari-theme)
Theme context and style injection system.
Responsibilities:
- Theme provider component
- Theme context management
- CSS variable generation
- Theme switching
Core Features:
use ThemeProvider;
rsx!
Supported Themes:
- Hikari (Light) - Light theme
- Primary: Pink (#FFB3A7)
- Secondary: Dark Green (#519A73)
- Accent: Turmeric (#FFC773)
- Tairitsu - Dark theme
- Primary: Duck Blue (#144A74)
- Secondary: Dark Green (#519A73)
- Accent: Turmeric (#FFC773)
3. Animation System (hikari-animation)
High-performance declarative animation system.
Responsibilities:
- Animation builder
- Animation context
- Easing functions
- Preset animations
Core Features:
use ;
use CssProperty;
// Static animation
new
.add_style
.apply_with_transition;
// Dynamic animation (mouse following)
new
.add_style_dynamic
.apply_with_transition;
Architecture Components:
- builder - Animation builder API
- context - Runtime animation context
- style - Type-safe CSS operations
- easing - 30+ easing functions
- tween - Interpolation system
- timeline - Timeline control
- presets - Preset animations (fade, slide, scale)
- spotlight - Spotlight effect
Performance Features:
- WASM optimization
- Debounced updates
- requestAnimationFrame integration
- Minimized reflows and repaints
4. Icon System (hikari-icons)
Icon management and rendering system.
Responsibilities:
- Icon enum definitions
- SVG content generation
- Icon size variants
- Material Design Icons integration
Core Features:
use ;
rsx!
Icon Sources:
- Material Design Icons (7000+ icons)
- Extensible custom icons
- Multiple size support
5. Component Library (hikari-components)
Complete UI component library.
Responsibilities:
- Basic UI components
- Layout components
- Style registry
- Responsive hooks
Component Categories:
- 1Basic Components (feature: "basic")
- Button, Input, Card, Badge
- 1Feedback Components (feature: "feedback")
- Alert, Toast, Tooltip, Spotlight
- 1Navigation Components (feature: "navigation")
- Menu, Tabs, Breadcrumb
- 1Layout Components (always available)
- Layout, Header, Aside, Content, Footer
- 1Data Components (feature: "data")
- Table, Tree, Pagination
Modular Design:
Style System:
- SCSS source
- Type-safe utility classes
- Component-level style isolation
- CSS variable integration
6. Icon Build System
Compile-time code generation and SCSS compilation.
Responsibilities:
- SCSS compilation (using Grass)
- Component discovery
- Code generation
- Resource bundling
Build Process:
Usage:
// build.rs
Generated Files:
- public/styles/bundle.css - Compiled CSS
7. Render Service (tairitsu-packager)
Server-side rendering and static asset serving.
Responsibilities:
- HTML template rendering
- Style registry
- Router builder
- Static asset service
- Axum integration
Core Features:
use HikariRenderServicePlugin;
let app = new
.component_style_registry
.static_assets
.add_route
.build?;
Architecture Modules:
- html - HTML service
- registry - Style registry
- router - Router builder
- static_files - Static file service
- styles_service - Style injection
- plugin - Plugin system
8. Extra Components Library (hikari-extra-components)
Advanced UI components for complex interaction scenarios.
Responsibilities:
- Advanced utility components
- Drag and zoom interactions
- Collapsible panels
- Animation integration
Core Components:
- 1Collapsible - Collapsible panel
- Left/right slide in/out animation
- Configurable width
- Expanded state callback
- 1DragLayer - Drag layer
- Boundary constraints
- Drag event callbacks
- Custom z-index
- 1ZoomControls - Zoom controls
- Keyboard shortcut support
- Configurable zoom range
- Multiple positioning options
Core Features:
use ;
// Collapsible panel
Collapsible
// Drag layer
DragLayer
// Zoom controls
ZoomControls
Architecture Principles
1. Modular Design
Each package is independent and can be used separately:
# Use only palette
[dependencies]
hikari-palette = "0.1"
# Use components and theme
[dependencies]
hikari-components = "0.1"
hikari-theme = "0.1"
# Use animation system
[dependencies]
hikari-animation = "0.1"
2. Layered Architecture
3. Unidirectional Data Flow
4. Type Safety
All APIs are type-safe:
- Compile-time checking
- IDE autocompletion
- Refactoring safety
5. Performance First
- WASM optimization
- Virtual scrolling
- Debouncing/throttling
- Minimized DOM manipulation
Build Process
Development Mode
Production Build
# 1. Build Rust code
# 2. Build system automatically compiles SCSS
# 3. Generate CSS bundle
# 4. Bundle static assets
WASM Build
Dependencies
Extensibility
Adding Custom Components
use ;
;
Adding Custom Themes
use ThemePalette;
;
Adding Custom Animation Presets
use ;
Performance Optimization
1. CSS Optimization
- SCSS compiled to optimized CSS
- Remove unused styles (tree-shaking)
- Minify production CSS
2. WASM Optimization
- wasm-opt optimization
- Lazy WASM module loading
- Linear memory optimization
3. Runtime Optimization
- Virtual scrolling (large data lists)
- Debounced animation updates
- requestAnimationFrame
4. Build Optimization
- Parallel compilation
- Incremental compilation
- Binary caching
Testing Strategy
Unit Tests
Each module has complete unit tests:
Integration Tests
Example applications in examples/ serve as integration tests
Visual Regression Testing
Use Percy or similar tools for UI snapshot testing
Next Steps
- Read Component Documentation for specific components
- View API Documentation for API details
- Browse Example Code to learn best practices