# inertiajs/inertia architecture

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

- Interactive diagram: https://gitdiagram.com/inertiajs/inertia
- Repository: https://github.com/inertiajs/inertia

## Overview

##### Main Components

a. Core Layer
- Router Module (router.ts)
- Page Manager (page.ts)
- Request/Response Handlers (request.ts, response.ts)
- Event System (events.ts)
- Progress Tracking (progress.ts)

b. Framework Adapters
- Create three parallel adapter components:
- React Adapter
- Vue3 Adapter
- Svelte Adapter

c. Server-Side Integration
- Controller Integration
- Middleware Processing
- Response Formation

##### Component Relationships

a. Data Flow
- Server → Core → Framework Adapters
- Framework Adapters → Core → Server

b. State Management
- A "State Management" component showing:
- Page State
- Form State
- Remember State
- Navigation State

##### Key Features to Highlight

- Form Handling (useForm)
- Page Management (usePage)
- Polling System (usePoll)
- Prefetching (usePrefetch)
- Memory Management (useRemember)

##### Implementation Details

Annotations showing:
- TypeScript implementation
- Framework-specific bindings
- Server-side requirements
- Client-side routing mechanism

##### Architecture Patterns

Architectural patterns with labeled sections:
- Adapter Pattern (for framework integration)
- Observer Pattern (for events)
- Middleware Pattern (for request/response handling)

##### Integration Points

Clear connection points for:
- Backend Framework Integration
- Frontend Framework Mounting
- State Synchronization
- Route Management

- The seamless integration between server and client
- The framework-agnostic core
- The adapter-based architecture for multiple frontend frameworks
- The unified state management approach

Use a hierarchical layout with:
##### Supporting Features (sides)

This will create a comprehensive visualization of Inertia.js's architecture while maintaining clarity about its primary purpose of enabling server-driven SPA development.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#2196F3,color:white
    classDef adapter fill:#4CAF50,color:white
    classDef server fill:#FF9800,color:white
    classDef state fill:#9C27B0,color:white
    classDef feature fill:#FFD700,color:black
    
    %% Server Layer
    subgraph Server
        SI[Controller Integration]:::server
        MP[Middleware Processing]:::server
        RF[Response Formation]:::server
    end

    %% Core Layer
    subgraph Core
        RM[Router Module]:::core
        PM[Page Manager]:::core
        RH[Request Handler]:::core
        RSH[Response Handler]:::core
        ES[Event System]:::core
        PT[Progress Tracking]:::core
    end

    %% State Management
    subgraph State
        PS[Page State]:::state
        FS[Form State]:::state
        RS[Remember State]:::state
        NS[Navigation State]:::state
    end

    %% Features
    subgraph Features
        FH[Form Handling]:::feature
        PGM[Page Management]:::feature
        PLS[Polling System]:::feature
        PF[Prefetching]:::feature
        MM[Memory Management]:::feature
    end

    %% Framework Adapters
    subgraph Adapters
        RA[React Adapter]:::adapter
        VA[Vue3 Adapter]:::adapter
        SA[Svelte Adapter]:::adapter
    end

    %% Relationships
    SI --> RM
    MP --> RH
    RF --> RSH
    
    RM <--> PM
    PM <--> RH
    RH <--> RSH
    ES <--> PT
    
    Core <--> State
    Core <--> Features
    Core <--> Adapters

    %% Click Events
    click RM "https://github.com/inertiajs/inertia/blob/master/packages/core/src/router.ts"
    click PM "https://github.com/inertiajs/inertia/blob/master/packages/core/src/page.ts"
    click RH "https://github.com/inertiajs/inertia/blob/master/packages/core/src/request.ts"
    click RSH "https://github.com/inertiajs/inertia/blob/master/packages/core/src/response.ts"
    click ES "https://github.com/inertiajs/inertia/blob/master/packages/core/src/events.ts"
    click PT "https://github.com/inertiajs/inertia/blob/master/packages/core/src/progress.ts"
    
    click RA "https://github.com/inertiajs/inertia/tree/master/packages/react/src/"
    click VA "https://github.com/inertiajs/inertia/tree/master/packages/vue3/src/"
    click SA "https://github.com/inertiajs/inertia/tree/master/packages/svelte/src/"
    
    click FH "https://github.com/inertiajs/inertia/blob/master/packages/react/src/useForm.ts"
    click PGM "https://github.com/inertiajs/inertia/blob/master/packages/react/src/usePage.ts"
    click PLS "https://github.com/inertiajs/inertia/blob/master/packages/react/src/usePoll.ts"
    click PF "https://github.com/inertiajs/inertia/blob/master/packages/react/src/usePrefetch.ts"
    click MM "https://github.com/inertiajs/inertia/blob/master/packages/react/src/useRemember.ts"
```
