# Full-stack example: a bookshop An [axum](https://docs.rs/axum) server renders every page with Rust that ferrovue generated from Vue components, and a [Vite](https://vite.dev) build of the same components hydrates the parts of the page that need to run in the browser. Copy this directory to start an app of your own: outside this repository, depend on `ferrovue` from crates.io and npm, and replace the `*.workspace = true` keys in `Cargo.toml` with your own. ```text client/components/*.vue ──ferrovue──▶ src/generated/*.rs ──axum──▶ HTML ─┐ └──Vite────▶ dist/assets/main-*.js ──────────────┴─▶ browser hydrates ``` ## Running it From the repository root: ```sh pnpm install pnpm --filter ferrovue build # the ferrovue package itself (only inside this repo) pnpm --filter ferrovue-example-fullstack build # the client into dist/, and src/generated/ cargo run -p ferrovue-example-fullstack # http://localhost:3000 (PORT to change it, DIST_DIR for another client build) ``` While you work on the components, run Vite's dev server and point the Rust server at it. The ferrovue plugin regenerates `src/generated/` whenever a component, store or the routes change, and Vite hot-reloads the client: ```sh pnpm --filter ferrovue-example-fullstack dev # Vite on :5173 VITE_DEV_SERVER=http://localhost:5173 cargo run -p ferrovue-example-fullstack ``` That is the client half of hot reload. For the server half, run the Rust server under [bacon](https://dystroy.org/bacon/) in place of `cargo run`. bacon watches `src/`, which holds `src/generated/`, so each time the ferrovue plugin rewrites a module, it rebuilds the server and restarts it: ```sh VITE_DEV_SERVER=http://localhost:5173 bacon run-long -- -p ferrovue-example-fullstack ``` The plugin writes only the modules whose text changed, so an edit that changes no generated Rust restarts nothing. `tsconfig.json` names the `ferrovue/volar` plugin, so in VS Code with the Vue (Official) extension a component's errors are underlined as you edit it (see the quick start's "Diagnostics in your editor"). To see one page as the server renders it: ```sh cargo run -p ferrovue-example-fullstack -- --render /books/dune ``` ## What each part shows | File | Demonstrates | |---|---| | `ferrovue.config.json` | A `router` block (a folder of pages, `linkActiveClass`), a `stores` directory, output in `src/generated/`, `"scopeId": "filepath"` | | `vite.config.ts` | `@vitejs/plugin-vue` with `componentIdGenerator: "filepath"`, so the build and the dev server give scoped styles the ids the server writes | | `client/pages/` | The routes, from the pages' file names as vue-router's file-based routing reads them: `index.vue` (`/`), `books/[id].vue` (`/books/:id`), `picks.vue` and the catch-all `[...missing].vue`, named `/`, `/books/[id]`, `/picks` and `/[...missing]`. ferrovue builds the server's `route_table.rs` from them and compiles each page (`index.rs`, `books_id.rs`, `picks.rs`, `missing.rs`); the Vite plugin gives the client the same routes as `ferrovue/routes` | | `client/stores/basket.ts` | A Pinia option store with getters (`count`, `empty`) | | `client/components/Layout.vue` | ``, ``s by route name with params, the active-link class; `useHead` with a `titleTemplate` the pages' titles go into | | `client/components/BasketSummary.vue` | Reading the store (state and getters, `storeToRefs`) on the server; `