Rustelo/client/src/lib.rs

214 lines
5.4 KiB
Rust
Raw Normal View History

2025-07-07 23:05:46 +01:00
//! # RUSTELO Client
//!
//! <div align="center">
//! <img src="../logos/rustelo_dev-logo-h.svg" alt="RUSTELO" width="300" />
//! </div>
//!
//! Frontend client library for the RUSTELO web application framework, built with Leptos and WebAssembly.
//!
//! ## Overview
//!
//! The RUSTELO client provides a reactive, high-performance frontend experience using Rust compiled to WebAssembly.
//! It features component-based architecture, state management, internationalization, and seamless server-side rendering.
//!
//! ## Features
//!
//! - **⚡ Reactive UI** - Built with Leptos for fast, reactive user interfaces
//! - **🎨 Component System** - Reusable UI components with props and state
//! - **🌐 Internationalization** - Multi-language support with fluent
//! - **🔐 Authentication** - Complete auth flow with JWT and OAuth2
//! - **📱 Responsive Design** - Mobile-first design with Tailwind CSS
//! - **🚀 WebAssembly** - High-performance client-side rendering
//!
//! ## Architecture
//!
//! The client is organized into several key modules:
//!
//! - [`app`] - Main application component and routing
//! - [`components`] - Reusable UI components including logos and forms
//! - [`pages`] - Individual page components (Home, About, etc.)
//! - [`auth`] - Authentication components and context
//! - [`state`] - Global state management and themes
//! - [`i18n`] - Internationalization and language support
//! - [`utils`] - Client-side utilities and helpers
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use client::app::App;
//! use leptos::prelude::*;
//!
//! // Mount the application
//! leptos::mount::mount_to_body(App);
//! ```
//!
//! ## Component Usage
//!
//! ### Logo Components
//!
//! ```rust,ignore
//! use client::components::{Logo, BrandHeader, NavbarLogo};
//! use leptos::prelude::*;
//!
//! // Basic logo
//! view! {
//! <Logo
//! orientation="horizontal".to_string()
//! size="medium".to_string()
//! show_text=true
//! dark_theme=false
//! />
//! }
//!
//! // Navigation logo
//! view! {
//! <NavbarLogo size="small".to_string() />
//! }
//!
//! // Brand header with logo and text
//! view! {
//! <BrandHeader
//! title="RUSTELO".to_string()
//! subtitle="Modular Rust Web Application Template".to_string()
//! logo_size="large".to_string()
//! />
//! }
//! ```
//!
//! ### Authentication Components
//!
//! ```rust,ignore
//! use client::auth::{AuthProvider, LoginForm};
//! use leptos::prelude::*;
//!
//! view! {
//! <AuthProvider>
//! <LoginForm />
//! </AuthProvider>
//! }
//! ```
//!
//! ### Form Components
//!
//! ```rust,ignore
//! use client::components::{ContactForm, SupportForm};
//! use leptos::prelude::*;
//!
//! view! {
//! <ContactForm />
//! <SupportForm />
//! }
//! ```
//!
//! ## State Management
//!
//! ### Theme Management
//!
//! ```rust,ignore
//! use client::state::theme::{ThemeProvider, use_theme_state, Theme};
//! use leptos::prelude::*;
//!
//! #[component]
//! fn MyComponent() -> impl IntoView {
//! let theme_state = use_theme_state();
//!
//! view! {
//! <button on:click=move |_| theme_state.toggle()>
//! "Toggle Theme"
//! </button>
//! }
//! }
//! ```
//!
//! ## Internationalization
//!
//! ```rust,ignore
//! use client::i18n::{I18nProvider, use_i18n};
//! use leptos::prelude::*;
//!
//! #[component]
//! fn MyComponent() -> impl IntoView {
//! let i18n = use_i18n();
//!
//! view! {
//! <p>{i18n.t("welcome_message")}</p>
//! }
//! }
//! ```
//!
//! ## WebAssembly Integration
//!
//! The client is designed to run efficiently in WebAssembly environments:
//!
//! - **Small Bundle Size** - Optimized for fast loading
//! - **Memory Efficient** - Careful memory management
//! - **Browser APIs** - Safe access to web APIs through web-sys
//! - **Error Handling** - Comprehensive error boundaries
//!
//! ## Development
//!
//! ### Building
//!
//! ```bash
//! # Development build
//! cargo build --target wasm32-unknown-unknown
//!
//! # Production build
//! cargo build --release --target wasm32-unknown-unknown
//!
//! # Using cargo-leptos
//! cargo leptos build
//! ```
//!
//! ### Testing
//!
//! ```bash
//! # Run tests
//! cargo test
//!
//! # Run tests in browser
//! wasm-pack test --headless --chrome
//! ```
//!
//! ## Performance
//!
//! Optimized for performance with:
//!
//! - **Lazy Loading** - Components loaded on demand
//! - **Virtual DOM** - Efficient rendering with fine-grained reactivity
//! - **Code Splitting** - Reduced initial bundle size
//! - **Caching** - Smart caching of static assets
//!
//! ## Browser Support
//!
//! - **Modern Browsers** - Chrome 80+, Firefox 72+, Safari 13.1+, Edge 80+
//! - **WebAssembly** - Required for optimal performance
//! - **JavaScript Fallback** - Graceful degradation where possible
//!
//! ## Contributing
//!
//! Contributions are welcome! Please see our [Contributing Guidelines](https://github.com/yourusername/rustelo/blob/main/CONTRIBUTING.md).
//!
//! ## License
//!
//! This project is licensed under the MIT License - see the [LICENSE](https://github.com/yourusername/rustelo/blob/main/LICENSE) file for details.
#![recursion_limit = "256"]
pub mod app;
pub mod auth;
pub mod components;
pub mod defs;
pub mod i18n;
pub mod pages;
pub mod state;
pub mod utils;
use crate::app::App;
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
console_error_panic_hook::set_once();
leptos::mount::hydrate_body(App);
}