Skip to content

Install and run ​

It's built on Laravel for Rust (beta).

Requirements ​

  • Rust 1.99 or later
  • Node.js 22.18+ or 24.11+
  • The Laravel CLI: curl -fsSL https://laravel.com/install.sh | sh

Two laravel commands

If the Composer laravel is already on your PATH, check after installing that laravel --version starts with Laravel CLI. To keep both, rename ~/.laravel/bin/laravel, for example to laravel-rust. You can also skip the CLI: every laravel <command> can be replaced by cargo run -- <command>.

Local development ​

bash
cp .env.example .env
bash
laravel key:generate
bash
npm install
bash
laravel migrate
bash
laravel dev

The database defaults to SQLite (storage/app/database.sqlite, created on first connection). To use PostgreSQL, replace the database-sqlite feature in Cargo.toml with database-postgres, then change DB_CONNECTION and DATABASE_URL in .env and src/config/database.rs.

Nothing happens in the browser?

Usually Vite isn't running or hasn't been built. laravel dev starts Vite too; to build on its own, run npm run build. The runtime is loaded by resources/js/site.js; without it, no data-* attribute gets bound.

APP_KEY

The render fragment and Linker POST routes sit under a site-specific prefix derived from APP_KEY (/{prefix}/render, /{prefix}/linker…), with the same algorithm as the PHP version. Every server for one site must use the same key, and pages that are already open need a reload after the key changes. See Deployment and operations.

Look at these pages first ​

RouteWhat to look at
/componentsComponents built from Rust (Badge::new(..).render()) and called from templates (cg_badge(..))
/runtimeRender fragments (auto-load, redraw on click, toast), a Stateful counter, a Stateless greeter
/Laravel's default Inertia + React welcome page; unrelated to cg-component, remove it if you don't need it

Linker on /runtime needs a login. With APP_DEBUG=true the page has a "log in with the demo account" button, which creates demo@cg-component.test and logs in (src/http/handlers/runtime_demo.rs).

Keep it open while you read the tutorials, and watch Network and the console in DevTools:

  • On load there's one POST /{prefix}/render (data-render-auto).
  • Click "re-render": click again within the same second and the response is "unchanged": true, with no html.
  • Each click on the counter adds one to the request's rev.

Project layout ​

PathPurpose
crates/cg-component/The component crate: Badge, Button, Icon, template functions
crates/cg-component/src/runtime/The server side of render fragments and Linker (endpoints, render tokens, Linker components, action table)
crates/cg-component/tests/php_parity.rsCompares HTML structure with the PHP snapshots
crates/cg-component/tests/fixtures/php/Snapshots copied from the PHP project
resources/css/cg-component.cssComponent CSS generated from PHP; don't edit by hand
resources/css/site.cssTailwind entry for server-rendered pages (loads cg-component.css)
resources/js/cg/The JavaScript runtime synced from PHP; don't edit by hand
resources/js/cg-lang.jsonTranslations the runtime uses; don't edit by hand
resources/js/site.jsJS entry for server-rendered pages; calls the runtime's boot()
resources/views/layouts/site.htmlLayout for server-rendered pages (cg_html_attrs(), cg_head())
src/cg/This project's fragments and Linker components, registered in register()
src/app.rsRegisters the template functions, calls cg::register(), adds share_head to the web middleware
src/routes/web.rscg_component::runtime::routes::<User>(route) registers the endpoints
scripts/sync-php-assets.pySyncs CSS, JS, translations and snapshots from the PHP project
tests/runtime.rsChecks the render fragment and Linker protocol over HTTP

Tests and checks ​

bash
cargo test --workspace
bash
cargo clippy --workspace --all-targets -- -D warnings
bash
npm run check

Tests need .env too

cargo test reads .env. Without one, the database config falls back to PostgreSQL and startup fails, so copy .env.example first. CI uses DATABASE_URL=sqlite::memory: so parallel tests don't fight over one SQLite file.

More commands are in Commands; how to write tests is in Testing.

This wiki ​

The wiki is a separate VitePress site in wiki/ and doesn't affect the main app's Vite config:

bash
cd wiki && npm install && npm run dev

Pushes to main deploy it to GitHub Pages through .github/workflows/wiki-pages.yml.

Next: Your first Linker component.