How kaiofelps/inertia-rust works
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)