# yaserrar/ya-router architecture

> Architecture diagram of the GitHub repository yaserrar/ya-router, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yaserrar/ya-router
- Repository: https://github.com/yaserrar/ya-router

## Overview

Key Components to Include:

##### Core Architecture Components
- Navigation Provider (Higher Order Component)
- Navigator Component
- Navigation Store (Zustand)
- Navigation Hook Interface

##### Main Layer Structure (Top to Bottom)

**┌─ Application Layer (Consumer Code) ─────────────┐**

- User Components <─> useNavigation Hook         │

- ┤

- NavigationProvider                  │
- ↓                           │
- Navigator Component               │
- ↓                           │
- Zustand Store Layer                 │

- ┘

##### Specific Elements

a. Data Flow Representation:
- User Action → useNavigation Hook → Store Update → Navigator Re-render

b. Type System Integration:
- Routes Definition <─> TypeScript Types <─> Navigation Methods

##### Key Interactions to Highlight

- Route Registration Flow
- Navigation State Updates
- Screen Rendering Process
- History Management

##### Implementation Details
- How the store.ts connects to provider.tsx
- How navigator.tsx consumes store state
- Demonstrate how index.ts exports public API

Special Considerations:

##### Type Safety Layer
- A separate section showing TypeScript integration
- Demonstrate how route types flow through the system

##### State Management
- Zustand store structure
- State update patterns

##### Component Hierarchy
- Provider pattern
- Screen mounting/unmounting flow

**🔷 Core Component**
**🔶 Public API**
**⚡ State Update**
**↔️ Two-way Binding**
**🔒 Type Safety Check**

Level of Detail:

1. Navigation State Flow
2. Type System Integration
3. Screen Lifecycle

This approach will give other engineers a clear understanding of both the architecture and the practical usage of the library.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        UserComponents["User Components"]
        NavHook["useNavigation Hook"]:::api
    end

    subgraph "Core Navigation Layer"
        Provider["Navigation Provider"]:::core
        Navigator["Navigator Component"]:::core
        Store["Navigation Store"]:::store
    end

    subgraph "Type System"
        TypeDefs["Route Definitions"]:::types
        TSTypes["TypeScript Types"]:::types
        NavMethods["Navigation Methods"]:::types
    end

    %% Main Flow
    UserComponents --> NavHook
    NavHook --> Store
    Store --> Navigator
    Provider --> Navigator
    Navigator --> Store

    %% Type System Relations
    TypeDefs <--> TSTypes
    TSTypes <--> NavMethods
    NavMethods --> NavHook

    %% State Flow
    Store -- "State Updates" --> Navigator
    Navigator -- "Screen Rendering" --> UserComponents
    NavHook -- "Navigation Actions" --> Store

    %% Legend
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef store fill:#4CAF50,stroke:#388E3C,color:white
    classDef api fill:#FF9800,stroke:#F57C00,color:white
    classDef types fill:#9E9E9E,stroke:#616161,color:white

    %% Click Events
    click Provider "https://github.com/yaserrar/ya-router/blob/main/src/provider.tsx"
    click Navigator "https://github.com/yaserrar/ya-router/blob/main/src/navigator.tsx"
    click Store "https://github.com/yaserrar/ya-router/blob/main/src/store.ts"
    click NavHook "https://github.com/yaserrar/ya-router/blob/main/src/index.ts"
    click TSTypes "https://github.com/yaserrar/ya-router/blob/main/tsconfig.json"

    %% Legend Nodes
    LegendCore["🔷 Core Component"]:::core
    LegendAPI["🔶 Public API"]:::api
    LegendStore["⚡ State Store"]:::store
    LegendTypes["🔒 Type System"]:::types
```
