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
cp .env.example .envlaravel key:generatenpm installlaravel migratelaravel devThe 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
| Route | What to look at |
|---|---|
/components | Components built from Rust (Badge::new(..).render()) and called from templates (cg_badge(..)) |
/runtime | Render 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 nohtml. - Each click on the counter adds one to the request's
rev.
Project layout
| Path | Purpose |
|---|---|
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.rs | Compares HTML structure with the PHP snapshots |
crates/cg-component/tests/fixtures/php/ | Snapshots copied from the PHP project |
resources/css/cg-component.css | Component CSS generated from PHP; don't edit by hand |
resources/css/site.css | Tailwind 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.json | Translations the runtime uses; don't edit by hand |
resources/js/site.js | JS entry for server-rendered pages; calls the runtime's boot() |
resources/views/layouts/site.html | Layout for server-rendered pages (cg_html_attrs(), cg_head()) |
src/cg/ | This project's fragments and Linker components, registered in register() |
src/app.rs | Registers the template functions, calls cg::register(), adds share_head to the web middleware |
src/routes/web.rs | cg_component::runtime::routes::<User>(route) registers the endpoints |
scripts/sync-php-assets.py | Syncs CSS, JS, translations and snapshots from the PHP project |
tests/runtime.rs | Checks the render fragment and Linker protocol over HTTP |
Tests and checks
cargo test --workspacecargo clippy --workspace --all-targets -- -D warningsnpm run checkTests 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:
cd wiki && npm install && npm run devPushes to main deploy it to GitHub Pages through .github/workflows/wiki-pages.yml.
Next: Your first Linker component.