# inertiajs/inertia-laravel architecture

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

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

## Overview

##### Main Components

a) Core Components:
- Inertia Middleware Layer
- Response Handler
- SSR (Server-Side Rendering) System
- Props Management System
- Testing Infrastructure

b) Integration Points:
- Laravel Application
- Frontend Framework (Vue.js, React, or Svelte)
- Server-Side Rendering Node.js Server

**┌─────────────────────────────────────────────────────────┐**
- Client (Browser)                        │
- ┬─────────────────────────────┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Inertia Middleware                      │
- ┬─────────────────┬────────────────────┤
- Props System   │ Response Handler │    SSR System      │

- AlwaysProp    │ - Response      │ - Gateway          │
- DeferProp     │ - Controller    │ - BundleDetector   │
- LazyProp      │                 │ - HttpGateway      │
- MergeProp     │                 │                     │
- ┴─────────────────┴────────────────────┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Laravel Application                     │
- ┘

##### Important Elements to Highlight

a) Middleware Flow:
- How requests flow through the Inertia middleware
- Where props are processed and transformed
- Demonstrate SSR decision points

b) Props System:
- Different types of props (Always, Defer, Lazy, Merge)
- How props are processed and passed to the frontend

c) SSR Architecture:
- Node.js SSR server
- Communication between Laravel and the SSR server
- BundleDetector's role

##### Implementation Details

Use standardized UML or C4 model notation:
- Diamonds for composition relationships

- Middleware-centric nature of the system
- Clear boundaries between Inertia, Laravel, and the frontend
- SSR system's architecture as it's a complex subsystem
- Testing infrastructure as it's a significant part of the codebase

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Browser/Frontend Framework"]
    end

    subgraph InertiaMiddleware["Inertia Middleware Layer"]
        Middleware["Middleware"]:::core
        EncryptHistory["Encrypt History Middleware"]:::core
        click Middleware "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Middleware.php"
        click EncryptHistory "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/EncryptHistoryMiddleware.php"
    end

    subgraph PropsSystem["Props Management System"]
        direction TB
        Always["Always Props"]:::props
        Defer["Defer Props"]:::props
        Lazy["Lazy Props"]:::props
        Merge["Merge Props"]:::props
        Optional["Optional Props"]:::props
        MergesProps["Merges Props"]:::props
        click Always "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/AlwaysProp.php"
        click Defer "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/DeferProp.php"
        click Lazy "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/LazyProp.php"
        click Merge "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/MergeProp.php"
        click Optional "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/OptionalProp.php"
        click MergesProps "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/MergesProps.php"
    end

    subgraph ResponseHandler["Response Handler"]
        Response["Response"]:::handler
        ResponseFactory["Response Factory"]:::handler
        Controller["Controller"]:::handler
        click Response "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Response.php"
        click ResponseFactory "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/ResponseFactory.php"
        click Controller "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Controller.php"
    end

    subgraph SSRSystem["SSR System"]
        Gateway["Gateway"]:::ssr
        HttpGateway["HTTP Gateway"]:::ssr
        BundleDetector["Bundle Detector"]:::ssr
        SSRResponse["SSR Response"]:::ssr
        click Gateway "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Ssr/Gateway.php"
        click HttpGateway "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Ssr/HttpGateway.php"
        click BundleDetector "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Ssr/BundleDetector.php"
        click SSRResponse "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Ssr/Response.php"
    end

    subgraph Testing["Testing Infrastructure"]
        AssertableInertia["Assertable Inertia"]:::test
        TestResponse["Test Response Macros"]:::test
        TestingConcerns["Testing Concerns"]:::test
        click AssertableInertia "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Testing/AssertableInertia.php"
        click TestResponse "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Testing/TestResponseMacros.php"
        click TestingConcerns "https://github.com/inertiajs/inertia-laravel/tree/2.x/src/Testing/Concerns/"
    end

    subgraph LaravelIntegration["Laravel Integration"]
        ServiceProvider["Service Provider"]:::laravel
        Directive["Blade Directive"]:::laravel
        Config["Configuration"]:::laravel
        click ServiceProvider "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/ServiceProvider.php"
        click Directive "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Directive.php"
        click Config "https://github.com/inertiajs/inertia-laravel/blob/2.x/config/inertia.php"
    end

    subgraph CLI["Command Line Tools"]
        CreateMiddleware["Create Middleware"]:::cli
        StartSSR["Start SSR"]:::cli
        StopSSR["Stop SSR"]:::cli
        click CreateMiddleware "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Commands/CreateMiddleware.php"
        click StartSSR "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Commands/StartSsr.php"
        click StopSSR "https://github.com/inertiajs/inertia-laravel/blob/2.x/src/Commands/StopSsr.php"
    end

    Browser <--> InertiaMiddleware
    InertiaMiddleware <--> ResponseHandler
    ResponseHandler <--> PropsSystem
    ResponseHandler <--> SSRSystem
    InertiaMiddleware <--> LaravelIntegration
    LaravelIntegration <--> CLI
    Testing --> ResponseHandler
    Testing --> InertiaMiddleware

    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef props fill:#4CAF50,stroke:#2E7D32,color:white
    classDef handler fill:#FF9800,stroke:#EF6C00,color:white
    classDef ssr fill:#E91E63,stroke:#C2185B,color:white
    classDef test fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef laravel fill:#607D8B,stroke:#455A64,color:white
    classDef cli fill:#795548,stroke:#5D4037,color:white
```
