# erhathaway/router-primitives architecture

> Architecture diagram of the GitHub repository erhathaway/router-primitives, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erhathaway/router-primitives
- Repository: https://github.com/erhathaway/router-primitives

## Overview

##### Core Router Management Layer
- Manager (Central Controller)
- Router Base
- Action Executor
- Router Templates
- State Management

##### Router Primitives Layer
- Scene Router
- Stack Router
- Feature Router
- Data Router

##### State Management Layer
- Router State
- Router Cache
- Serialization/Deserialization
- History Management

##### Integration Layer
- Platform Bindings (React, Mobx)
- URL Management
- State Predicates
- Router Links

##### Top Level (Platform Integration)
**[Platform Bindings (React/Mobx)] <---> [Router Manager] <---> [URL/Location Management]**

##### Core Layer
**[Router Manager]**

- [Router Base]
- [Action Executor]

- [Router Templates]
- Scene
- Stack
- Feature
- Data

- [State Management]
- Router State
- Router Cache
- History

##### State Flow
**[URL/Location] ──► [Serializer/Deserializer] ──► [Router State Tree] ──► [Application]**

Important Elements to Highlight:

##### Special Notations
- A "State Predicates" component connected to Router State
- Router Links mechanism
- Cache management flow

Key Architectural Principles to Emphasize:

##### One-way Data Flow
- Location → Router State tree → Application
- Clear indication of state propagation

##### Modularity
- Separate primitive types
- Platform-agnostic core
- Pluggable template system

##### State Management
- URL as source of truth
- Caching mechanism
- History tracking

##### Integration Points
- Framework bindings
- Custom primitive creation
- Action handling

Additional Considerations:

##### Relationship between
- Router declaration objects
- Generated router instances
- URL structure

##### Animation integration
- State predicates
- Transition hooks
- Platform-specific animation bindings

- Nested components
- Clear text labels
- Proper grouping of related components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Platform["Platform Integration"]
        React["React/Mobx Bindings"]
        URL["URL/Location Management"]
    end

    subgraph Core["Core Router Layer"]
        Manager["Router Manager"]:::core
        RouterBase["Router Base"]:::core
        ActionExec["Action Executor"]:::core
    end

    subgraph Templates["Router Templates"]
        Scene["Scene Router"]:::template
        Stack["Stack Router"]:::template
        Feature["Feature Router"]:::template
        Data["Data Router"]:::template
    end

    subgraph State["State Management"]
        RouterState["Router State"]:::state
        RouterCache["Router Cache"]:::state
        History["History Management"]:::state
    end

    subgraph Serialization["State Serialization"]
        Serializer["Serializer"]:::serial
        Deserializer["Deserializer"]:::serial
        Store["Platform Storage"]:::serial
    end

    %% Core Relationships
    React --> Manager
    Manager --> URL
    Manager --> RouterBase
    RouterBase --> ActionExec
    
    %% Template Connections
    Manager --> Templates
    RouterBase --> Scene
    RouterBase --> Stack
    RouterBase --> Feature
    RouterBase --> Data

    %% State Management Flow
    Manager --> RouterState
    RouterState --> RouterCache
    RouterState --> History
    
    %% Serialization Flow
    URL --> Deserializer
    Deserializer --> RouterState
    RouterState --> Serializer
    Serializer --> Store
    Store --> URL

    %% Styling
    classDef core fill:#2374ab
    classDef template fill:#7952b3
    classDef state fill:#28a745
    classDef serial fill:#fd7e14

    %% Click Events
    click Manager "https://github.com/erhathaway/router-primitives/blob/master/src/manager.ts"
    click RouterBase "https://github.com/erhathaway/router-primitives/blob/master/src/router_base.ts"
    click ActionExec "https://github.com/erhathaway/router-primitives/blob/master/src/action_executor.ts"
    click Scene "https://github.com/erhathaway/router-primitives/blob/master/src/router_templates/scene.ts"
    click Stack "https://github.com/erhathaway/router-primitives/blob/master/src/router_templates/stack.ts"
    click Feature "https://github.com/erhathaway/router-primitives/blob/master/src/router_templates/feature.ts"
    click Data "https://github.com/erhathaway/router-primitives/blob/master/src/router_templates/data.ts"
    click RouterState "https://github.com/erhathaway/router-primitives/blob/master/src/all_router_state.ts"
    click RouterCache "https://github.com/erhathaway/router-primitives/blob/master/src/all_router_cache.ts"
    click Serializer "https://github.com/erhathaway/router-primitives/blob/master/src/serialized_state/serializer.ts"
    click Deserializer "https://github.com/erhathaway/router-primitives/blob/master/src/serialized_state/deserializer.ts"
    click Store "https://github.com/erhathaway/router-primitives/blob/master/src/serialized_state/browser_store.ts"
```
