Hikari Architecture

Hikari Architecture

This document provides an overview of the Hikari project architecture, including package relationships, design patterns, technology choices, and future roadmap.

Table of Contents

Overview

Hikari is a modular Rust UI framework built around Tairitsu, following a workspace-based architecture. The project is organized into several focused packages, each with a specific responsibility:

mermaid

Design Philosophy

Hikari follows three core design principles:

  1. Modularity - Each package has a single, well-defined responsibility
  2. Composability - Packages can be used independently or combined
  3. Type Safety - Leverage Rust's type system for compile-time guarantees

Architecture Principles

1. Separation of Concerns

Each package handles a specific aspect of the framework:

  • hikari-palette: Color data and palette generation (no UI dependencies)
  • hikari-theme: Theme management and CSS variables (depends on palette)
  • hikari-components: UI components (depends on palette and theme)
  • hikari-animation: Animation engine, easing, state machine (depends on tairitsu)
  • hikari-icons: MDI icon integration (depends on animation)

2. Dependency Inversion

Packages depend on abstractions, not concrete implementations:

mermaid

This creates a clear dependency hierarchy and prevents circular dependencies.

3. Library over Framework

Hikari is designed as a library, not a framework:

  • No mandatory build steps
  • No code generation required
  • Use only what you need
  • Easy to integrate incrementally

Package Architecture

Dependency Graph

mermaid

Package Responsibilities

hikari-palette

Purpose: Color system foundation

Responsibilities:

  • Define color data structures
  • Provide a 660+ color catalog across curated collections
  • Generate pre-defined palettes
  • Serialize/deserialize colors

Dependencies: None (foundation package)

Exports:

rust
1
2
pub use colors::*;
pub use palettes::*;

hikari-theme

Purpose: Theme management and CSS generation

Responsibilities:

  • Theme context provider
  • CSS variable definitions
  • SCSS mixins and utilities
  • Theme switching logic

Dependencies:

  • hikari-palette (for color data)

Exports:

rust
1
2
pub use context::*;
pub use provider::*;

hikari-components

Purpose: Core UI component library (rendered components)

Responsibilities:

  • Basic components (Button, Input, Card, Badge)
  • Feedback components (Alert, Toast, Tooltip, Modal, Drawer)
  • Navigation components (Menu, Tabs, Breadcrumb)
  • Data components (Table, Tree, Pagination)
  • Display components (Tag, Skeleton, Calendar, Timeline, UserGuide, ZoomControls)
  • Layout components (Header, Aside, Grid, Flex)
  • Entry components (NumberInput, Search, Cascader, Transfer)
  • Production components (AudioPlayer, VideoPlayer, CodeHighlight, RichTextEditor)
  • Theme provider and portal system

Design approach: Tairitsu rsx! macro-based rendered components with reactive hooks (use_signal, use_effect), StyledComponent trait for CSS embedding, and typed CSS class enums from hikari-palette.

Dependencies:

  • hikari-palette (for color types and utility classes)
  • hikari-theme (for theming)
  • hikari-icons (for MDI icon components)
  • hikari-animation (for animation hooks)

Exports:

rust
1
2
3
4
5
6
7
8
pub use basic::*;
pub use feedback::*;
pub use navigation::*;
pub use data::*;
pub use display::*;
pub use layout::*;
pub use entry::*;
pub use production::*;

hikari-extra-components (retired)

Status: Removed. The package held framework-agnostic data models (DragLayerState, TimelineState, ZoomControlsState, the node-graph model, rich-media state models) beside the rendered components. Nothing in the workspace depended on it, its types duplicated same-named components (TimelinePosition, GuideStep, …), and the node-graph model was referenced only by its own tests. Use hikari-components instead — display::{Timeline, DragLayer, UserGuide, ZoomControls} and production::{VideoPlayer, RichTextEditor, CodeHighlight}.

hikari-animation

Purpose: Animation engine and presets

Responsibilities:

  • State machine animation engine
  • Easing functions (30+)
  • Tween interpolation and timelines
  • Animation presets (glow, neon, tech, transitions)

Dependencies:

  • tairitsu-vdom (for Platform trait)

Exports:

rust
1
2
3
pub use presets::*;
pub use core::{AnimationEngine, Tween, TweenId};
pub use easing::EasingFunction;

hikari-icons

Purpose: Material Design Icons integration

Responsibilities:

  • MDI icon fetching and caching
  • SVG AST rendering
  • Icon name validation

Dependencies:

  • hikari-animation (for icon animations)

Exports:

rust
1
2
pub use Icon;
pub use IconSize;

Technology Stack

Frontend

  • Tairitsu: React-like UI framework for Rust
    • Virtual DOM
    • Component-based architecture
    • Hooks for state management
    • WebAssembly compilation
  • WASI (wasm32-wasip2): WebAssembly System Interface
    • Native WASM Component Model runtime
    • WIT contract + JS host implementation: the guest component declares its browser capabilities as WIT interfaces and the JavaScript host implements them

Styling

  • Grass: SCSS compiler for Rust
    • Compile SCSS to CSS at build time
    • Full SCSS feature support
    • Fast compilation
  • SCSS: Stylesheet language
    • Variables and mixins
    • Nesting and inheritance
    • Functions and operations

Server (for SSR in examples)

  • Axum 0.8: Web framework
    • Tower-based middleware
    • Async handlers
    • Type-safe routing
  • Tokio: Async runtime
    • Futures executor
    • Networking and I/O

Build System

  • Cargo: Rust package manager
    • Workspace support
    • Dependency management
    • Build profiles
  • Just: Command runner
    • Task automation
    • Build scripts
    • Development workflows

Tooling

  • Python 3.11+: Development tooling
    • Code formatting
    • Linting
    • Pre-commit hooks

Design Patterns

1. Builder Pattern

Used extensively for configuration:

rust
1
2
3
4
5
let app = HikariSsrPlugin::new()
    .static_assets("./dist")
    .add_route("/api/health", get(health))
    .state("app_name", "Hikari App")
    .build()?;

Benefits:

  • Fluent API
  • Optional parameters
  • Clear configuration flow
  • Type-safe

2. Component Pattern

Tairitsu components follow React-like patterns:

rust
1
2
3
4
5
6
#[component]
fn Button(props: ButtonProps) -> Element {
    rsx! {
        button { class: "{props.class}", {props.children} }
    }
}

Benefits:

  • Reusable UI elements
  • Composable
  • Props-based configuration
  • Clear lifecycle

3. Context Pattern

Theme and state management:

rust
1
2
3
4
5
6
rsx! {
    ThemeProvider { initial_palette: "hikari",
        // All children have access to theme
        Button { "Themed Button" }
    }
}

Benefits:

  • Global state sharing
  • Avoid prop drilling
  • Dynamic updates
  • Type-safe access

4. Module Pattern

Component organization:

mermaid

Benefits:

  • Clear separation
  • Easy to navigate
  • Encapsulated functionality
  • Testable modules

5. Provider Pattern

Theme provision to component tree:

rust
1
2
3
4
5
6
7
8
9
#[component]
pub fn ThemeProvider(props: ThemeProviderProps) -> Element {
    rsx! {
        div {
            "data-theme": "{props.palette}",
            {props.children}
        }
    }
}

Benefits:

  • Centralized configuration
  • Automatic propagation
  • Easy theme switching
  • No manual prop passing

Data Flow

Component Data Flow

mermaid

Theme Data Flow

mermaid

SSR Data Flow (moved to the tairitsu packager)

Hikari ships no HTTP/SSR entry point of its own: the flow below now lives in the tairitsu packager (tairitsu-packager / tairitsu-ssr), which hosts hikari-components.

mermaid

Component Architecture

Component Hierarchy

mermaid

Component Lifecycle

  1. Mount: Component is created and added to DOM
  2. Update: Props or state change triggers re-render
  3. UnMount: Component is removed from DOM

State Management

  • Local State: use_signal for component-local state
  • Shared State: Context providers for global state
  • Server State: Axum state for SSR applications

Theme System Architecture

Theme Structure

mermaid

Theme Application

  1. Rust Side: ThemeProvider sets data-theme attribute
  2. CSS Side: CSS variables scoped to [data-theme="..."]
  3. Component Side: Components use CSS variables

Build and Bundle System

Cargo Workspace

toml
1
2
3
4
5
6
7
8
[workspace]
members = [
    "packages/palette",
    "packages/theme",
    "packages/animation",
    "packages/components",
    "packages/icons",
]

Benefits:

  • Shared dependencies
  • Unified compilation
  • Easy inter-package development
  • Consistent versioning

Build Profiles

toml
1
2
3
4
5
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = true

Benefits:

  • Optimized WASM output
  • Small bundle sizes
  • Fast runtime performance

Just Commands

makefile
1
2
3
4
5
build:        # Build all packages
test:         # Run tests
fmt:          # Format code
clippy:       # Run linter
dev:          # Start dev server

Benefits:

  • Consistent commands
  • Easy to remember
  • Cross-platform
  • Documented workflows

Testing Strategy

Unit Tests

Package-level unit tests:

rust
1
2
3
4
5
6
7
8
9
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_color_rgb() {
        assert_eq!(石青.rgb, (23, 89, 168));
    }
}

Integration Tests

Cross-package integration:

rust
1
2
3
4
#[tokio::test]
async fn test_theme_provider() {
    // Test theme provider with components
}

Example Tests

Example applications serve as integration tests:

mermaid

Future Roadmap

Phase 4: hikari-components (Current)

  • [x] Basic components (Button, Input, Card, Badge)
  • [x] Feedback components (Alert, Toast, Tooltip)
  • [x] Navigation components (Menu, Tabs, Breadcrumb)
  • [x] Data components (Table, Tree)
  • [x] Comprehensive component testing (275+ tests)
  • [x] Component documentation

Phase 5: hikari-extra-components (retired)

  • [x] Node graph system (with serialization, history, plugins)
  • [x] Advanced utilities (DragLayer, Collapsible, ZoomControls)
  • [ ] ~~Performance optimization~~
  • [ ] ~~Use case examples~~

The package was removed; the rendered components it shadowed live on in hikari-components.

Phase 6: Examples

  • [ ] Complete demo-app
  • [ ] Individual component demos
  • [x] SSR in example website
  • [ ] Performance benchmarks

Phase 7: Documentation

  • [ ] API documentation
  • [ ] Migration guides
  • [ ] Best practices
  • [ ] Video tutorials

Phase 8: Ecosystem

  • [ ] CLI tooling
  • [ ] Starter templates
  • [ ] VS Code extension
  • [ ] Community components

Long-term Vision

  • Design System: Complete design system specification
  • Component Library: 50+ production-ready components
  • Tooling: Developer tools and debugging
  • Community: Plugin ecosystem and contribution guidelines
  • Performance: Best-in-class WASM performance

Architectural Decisions

Single-Package Component Architecture

Hikari ships its components in one package, hikari-components: rsx! rendered components with reactive hooks, typed class enums from hikari-palette, and StyledComponent CSS.

An earlier dual-layer split kept framework-agnostic data models in a second package (hikari-extra-components) next to the rendered components. It was retired:

  • No crate in the workspace depended on it, and the node-graph model was referenced only by its own tests.
  • Same-named types lived in both packages with different semantics (e.g. TimelinePosition defaulted to Left in one and Alternate in the other), so importing the wrong one was silent.
  • The rendered components it duplicated were already complete here: display::{Timeline, DragLayer, UserGuide, ZoomControls}, production::{VideoPlayer, RichTextEditor, CodeHighlight}.

Why Tairitsu?

  • Rust Native: No JavaScript required for logic
  • Type Safety: Compile-time guarantees
  • Performance: Efficient virtual DOM
  • WASM: Native browser support
  • React-like: Familiar patterns

Why Axum?

  • Tower: Ecosystem compatibility
  • Type Safety: Route and state safety
  • Async: Modern async/await
  • Performance: Fast and efficient
  • Ergonomic: Clean API design

Why SCSS?

  • Features: Variables, mixins, nesting
  • Ecosystem: Large community and tools
  • Compilation: Fast with Grass
  • Adoption: Industry standard
  • Maintainability: Organized styles

Why Workspace?

  • Monorepo: Unified development
  • Sharing: Code reuse between packages
  • Versioning: Consistent versions
  • CI/CD: Simplified pipelines
  • Documentation: Co-located docs

Performance Considerations

WASM Optimization

  • LTO: Link-time optimization enabled
  • Codegen Units: Single unit for better optimization
  • Strip: Remove debug symbols
  • Opt-level: Maximum optimization

Runtime Performance

  • Virtual DOM: Efficient updates
  • Signals: Fine-grained reactivity
  • Lazy Loading: Component code splitting
  • Caching: Static asset caching

Bundle Size

  • Tree Shaking: Unused code elimination
  • Compression: Gzip enabled
  • WASM Opt: Size optimization
  • Minimal Dependencies: Few external deps

Security Considerations

Static Files

  • Path Sanitization: Prevent directory traversal
  • MIME Types: Proper content types
  • Cache Headers: Controlled caching
  • File Limits: Size restrictions

SSR

  • State Isolation: Request-scoped state
  • Error Handling: Graceful failures
  • Validation: Input validation
  • Logging: Audit trails

Conclusion

Hikari's architecture is designed to be:

  • Modular: Clear package boundaries
  • Composable: Use what you need
  • Performant: Optimized WASM output
  • Type-Safe: Leverage Rust's type system
  • Maintainable: Clean code organization
  • Extensible: Easy to add features

The architecture supports the project's goals of providing a modern, type-safe UI library whose single design system serves Vue 3 and Rust/WASM alike.