# kaiofelps/inertia-rust architecture

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

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

## Overview

##### Project Type and Purpose
- inertia-rust is a **server-side adapter library** (Rust crate) for Inertia.js v2.
- Its goal is to let any Rust web framework (e.g., Actix, Rocket) interoperate with Inertia.js by implementing:
- HTTP request/response plumbing
- Shared “page” payloads
- Template‐resolver hooks
- Optional SSR via a Node subprocess

##### File Structure
- Top‐level:
- src/               → core library modules
- src/providers/     → framework‐specific adapters (e.g., actix_provider)
- src/features/      → pluggable features (validators, template_resolvers)
- src/macros.rs      → procedural macros (DSL)
- node_process.rs    → SSR orchestration
- examples/actix_ssr: a sample Actix-Web app demonstrating integration, SSR, routing, domain logic, front-end assets (React + Vite).
- docs/: user guides; tests/: end-to-end and unit tests.

##### README for Additional Insights
- Confirms flexible, multi-framework support via “providers.”
- Highlights documentation site, examples, and v2 compatibility.

##### Core Components & Interactions
1. Client (Browser / Inertia.js)
2. Web Framework Provider (e.g., Actix Provider)
3. Inertia-Rust Core
– Facade, Inertia trait, Macros
– Features (validator, template_resolver)
– NodeProcess (SSR)
4. Template Engine(s)
– Handlebars, HBS, custom, Vite server
5. Data Layer / Domain (example tasks service)
6. Front-end Assets (React/Vite)
7. Tests & Docs (not in runtime, but part of system)

b. Relationships & Data Flow
1. Client makes an HTTP request (X-Inertia header)
2. Framework Provider Middleware intercepts → constructs a Facade request
3. Inertia-Rust Core:
- Parses request, handles shared props
- Runs validators (feature)
- Invokes developer’s route handler / controller
- Gathers page component name + props
4. Template Resolver (feature) selects template by name
5. Rendering:
– Server-side template engine (e.g., Handlebars) → HTML
– Or SSR via NodeProcess: spawn Node/Vite to render React → HTML
6. Provider wraps HTML in proper HTTP response (JSON or full page)
7. Client receives payload, rehydrates/updates view

c. Architectural Patterns
– **Adapter Pattern** for framework providers
– **Feature-based modularity** (pluggable traits for validation, templates)
– **Facade Pattern** to unify request/response handling
– **Strategy Pattern** for template resolution & SSR vs. CSR
– **Hexagonal Architecture**: core logic isolated from frameworks & engines

d. Key Technologies
– Rust + Cargo (crate)
– actix-web (example)
– Handlebars/hbs, Vite, React (example)
– Node.js subprocess for SSR
– Docker (optional, not in tree)

##### Detailed Checklist
– [ ] Frontend: Browser + Inertia.js
– [ ] Web Framework Provider (Actix Provider)
– [ ] Inertia-Rust Core: Facade, Macros, Inertia trait
– [ ] Feature Plugins: Validators, Template Resolvers
– [ ] Template Engine(s) & NodeProcess (SSR)
– [ ] Example Domain & Routing (tasks service)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Client["Browser / Inertia.js"]:::example
    click Client "https://github.com/kaiofelps/inertia-rust/tree/v2/examples/actix_ssr/www"

    %% Provider Layer
    subgraph "Web Framework Provider"
        direction TB
        ActixProvider["Actix Provider Middleware"]:::provider
    end
    click ActixProvider "https://github.com/kaiofelps/inertia-rust/tree/v2/src/providers/actix_provider"

    %% Core Library
    subgraph "Inertia-Rust Core Library"
        direction TB
        Lib["lib.rs (Entry Point)"]:::core
        Facade["facade.rs (Facade)"]:::core
        InertiaTrait["inertia.rs (Inertia Trait)"]:::core
        Macros["macros.rs (Procedural Macros)"]:::core
        subgraph "HTTP Plumbing & Enums"
            direction TB
            HTTPMethod["http_method.rs"]:::core
            ReqType["req_type.rs"]:::core
            Props["props.rs"]:::core
            Page["page.rs"]:::core
        end
        subgraph "Utilities & Errors"
            direction TB
            Utils["utils.rs"]:::core
            Error["error.rs"]:::core
        end
        TemplateResolverTrait["template_resolver.rs"]:::core
    end
    click Lib "https://github.com/kaiofelps/inertia-rust/blob/v2/src/lib.rs"
    click Facade "https://github.com/kaiofelps/inertia-rust/blob/v2/src/facade.rs"
    click InertiaTrait "https://github.com/kaiofelps/inertia-rust/blob/v2/src/inertia.rs"
    click Macros "https://github.com/kaiofelps/inertia-rust/blob/v2/src/macros.rs"
    click HTTPMethod "https://github.com/kaiofelps/inertia-rust/blob/v2/src/http_method.rs"
    click ReqType "https://github.com/kaiofelps/inertia-rust/blob/v2/src/req_type.rs"
    click Props "https://github.com/kaiofelps/inertia-rust/blob/v2/src/props.rs"
    click Page "https://github.com/kaiofelps/inertia-rust/blob/v2/src/page.rs"
    click Utils "https://github.com/kaiofelps/inertia-rust/blob/v2/src/utils.rs"
    click Error "https://github.com/kaiofelps/inertia-rust/blob/v2/src/error.rs"
    click TemplateResolverTrait "https://github.com/kaiofelps/inertia-rust/blob/v2/src/template_resolver.rs"

    %% Features Layer
    subgraph "Feature Plugins"
        direction TB
        Validators["Validators"]:::feature
        TemplateResolvers["Template Resolvers"]:::feature
    end
    click Validators "https://github.com/kaiofelps/inertia-rust/tree/v2/src/features/validators"
    click TemplateResolvers "https://github.com/kaiofelps/inertia-rust/tree/v2/src/features/template_resolvers"

    %% Rendering Engines
    subgraph "Rendering Engines & SSR"
        direction TB
        TemplateEngine["Template Engines (Handlebars, HBS, Custom)"]:::external
        NodeProcess["NodeProcess (SSR via Node)"]:::external
    end
    click NodeProcess "https://github.com/kaiofelps/inertia-rust/blob/v2/src/node_process.rs"

    %% Example Application
    subgraph "Example App (Actix-SSR)"
        direction TB
        Domain["Tasks Service (Domain Logic)"]:::example
        DTOs["DTOs"]:::example
        Routes["routes.rs"]:::example
        Middlewares["Middlewares"]:::example
        Config["Config (Inertia & Vite)"]:::example
        FrontendAssets["Front-end Assets (React/Vite)"]:::example
    end
    click Domain "https://github.com/kaiofelps/inertia-rust/tree/v2/examples/actix_ssr/src/domain/tasks"
    click DTOs "https://github.com/kaiofelps/inertia-rust/tree/v2/examples/actix_ssr/src/dtos"
    click Routes "https://github.com/kaiofelps/inertia-rust/blob/v2/examples/actix_ssr/src/routes.rs"
    click Middlewares "https://github.com/kaiofelps/inertia-rust/tree/v2/examples/actix_ssr/src/middlewares"
    click Config "https://github.com/kaiofelps/inertia-rust/tree/v2/examples/actix_ssr/src/config"
    click FrontendAssets "https://github.com/kaiofelps/inertia-rust/tree/v2/examples/actix_ssr/www/pages"

    %% Data Flow
    Client -->|"HTTP Request (X-Inertia)"| ActixProvider
    ActixProvider -->|"Constructs Facade Request"| Lib
    Lib --> Facade
    Facade --> InertiaTrait
    Facade --> HTTPMethod
    Facade --> ReqType
    Facade --> Props
    Facade --> Page
    Facade --> Validators
    Facade --> TemplateResolvers
    TemplateResolvers --> TemplateResolverTrait
    TemplateResolverTrait --> TemplateEngine
    Facade -->|"SSR Option"| NodeProcess
    NodeProcess -->|"Rendered HTML"| Facade
    Facade --> ActixProvider
    ActixProvider -->|"HTTP Response (JSON/HTML)"| Client

    %% Example Integration
    Facade --> Domain
    Domain --> DTOs
    ActixProvider --> Routes
    Routes --> Middlewares
    Routes --> Config
    FrontendAssets --> NodeProcess

    %% Styling
    classDef core fill:#bbdefb,stroke:#000
    classDef provider fill:#c8e6c9,stroke:#000
    classDef external fill:#fff9c4,stroke:#000
    classDef example fill:#e0e0e0,stroke:#000
    classDef feature fill:#b3e5fc,stroke:#000
```
