How thihathit/rutter works
Main Components
• Core Router Engine:
– Modules found in the “core” directory (index.ts, normalizers.ts, router.ts, types.ts) encapsulate the primary routing logic such as route parsing, URL normalization, and state management.
– This is where the CreateHistory class is defined, which acts as the entry point to handle routes, URL changes, and reactive state.
• Bindings / Integration Layers:
– The “dev” folder contains sample applications (e.g., App.tsx, main.tsx, router.ts) demonstrating how to integrate the core into different frameworks.
– The README shows usage samples and implementation patterns for React, Vue, Svelte, and plain JavaScript. These represent lightweight adapters connecting framework-specific state management or reactivity to the router’s core.
• Utility Modules:
– The “utility” directory contains helper functions (functions.ts, url.ts) that might be used for additional processing, URL utilities, or common operations.
• Supporting Infrastructure:
– Directories like “docs” (with logos and other documentation material) and “scripts” (for build/package info generation) support development and release processes.
– The configuration files (.eslintrc, .prettierrc, tsconfig.json, etc.) are used for development and build tooling but are less central to the runtime architecture.
Relationships and Interactions
• The central router engine (CreateHistory instance) maintains the current state of routes (routeState and summaryState) and exposes helper functions (redirect, on, onOneOf, watchRouteState, watchSummaryState) to interact with the browser’s navigation APIs.
• The adapters or binding layers (as seen in the dev examples) subscribe to changes from the core router using the watch functions. They then update the UI state accordingly – this is typically achieved by React’s useState, Vue’s reactive utilities, or Svelte’s readable/derived stores.
• External consumers (applications using Rutter) interact with the router by invoking functions like redirect and by reading state updates communicated via reactive signals — this interaction loop ensures that navigation changes are propagated throughout the application.
Architectural Patterns and Design Principles
• Separation of Concerns:
– The core library is separate from its framework-specific bindings. This clean separation ensures that the routing logic remains framework-agnostic.
• Observer/Reactive Pattern:
– The library relies on reactive primitives (from Signals or framework-specific reactive utilities) to notify subscribed components when the routing state changes.
• API Abstractions:
– The design abstracts browser-native APIs (URLPattern, History) behind its own API (CreateHistory, on, redirect) to provide a unified interface for developers regardless of how they choose to integrate it.
Relevant Technologies, Frameworks, and Libraries
• Browser APIs: URLPattern and History for routing.
• React, Vue, and Svelte: Examples provided in the README show how the router is adapted for these frameworks.
• Utility Libraries: For example, lodash-es is used in Vue and Svelte binding examples.
• Prettier, ESLint, and other build and configuration tools support development.
Summary
• The central routing core that abstracts browser-native APIs and manages route state.
• The framework-specific binding layers that subscribe to the core’s reactive state changes and expose them in a way that is idiomatic to each target framework.
• The flow of data and user interactions: from route configuration through to state updates and reactive UI rendering.
• Extra development and tooling assets to give context to the project’s overall setup and quality measures.