From fdc522cff77ef2c44c0b8e1e4a864ba2982959d0 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 00:04:14 +1300 Subject: [PATCH 1/4] Blog draft: a Laravel Rust starter kit for a production SaaS --- .../content/blog/laravel-rust-starter-kit.md | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 server/frontend/content/blog/laravel-rust-starter-kit.md diff --git a/server/frontend/content/blog/laravel-rust-starter-kit.md b/server/frontend/content/blog/laravel-rust-starter-kit.md new file mode 100644 index 00000000..5010ce29 --- /dev/null +++ b/server/frontend/content/blog/laravel-rust-starter-kit.md @@ -0,0 +1,117 @@ +--- +title: A Laravel Rust starter kit for a production SaaS +description: VisualCI is open source, and its server is a Laravel Rust app that runs in production. Clone it, delete the visual testing, and you start with sign-in, organizations, invitations, credit billing on Stripe, transactional email, an MCP server with OAuth, live updates, background jobs with heartbeats, and the tests and CI around them. +date: 2026-12-04 +author: Nathan Broadbent +draft: true +--- + +VisualCI is built in public. The whole product is in one repository, [github.com/DocSpring/visualci](https://github.com/DocSpring/visualci), under the Apache-2.0 licence: the server, the web app, the CLI, the renderers, the docs and this blog. What runs in production is what's in the repo. + +The server [moved to Laravel Rust](/blog/laravel-rust-rewrite/) this week. That makes the repo a working example of a full SaaS on Laravel Rust, with the parts every SaaS needs and nobody wants to build twice: accounts, organizations, billing, email, an API and an MCP server. You can use it as a starter kit. Clone it, have your coding agent delete the visual testing, and build your own product on what's left. + +## What Laravel Rust gives you + +The framework covers what you'd expect from Laravel. VisualCI uses: + +- routing with `web` and `api` groups, middleware, CSRF protection, encrypted cookies and trusted proxies +- `#[model]` models, query builders, transactions and migrations +- typed config sections read from environment variables +- session auth, and social sign-in with a GitHub driver (we added GitLab) +- queued jobs, the scheduler (`on_one_runner`, `without_overlapping`), events and listeners, and console commands +- request validation, an HTTP client with fakes, and `#[laravel::test]` +- sessions, cache and the queue in Postgres, so one database is all the state there is + +One image runs `serve`, `queue:work`, `schedule:work` and `migrate`. + +## What the repo adds + +The rest of this post is what we built on top. Paths are in the repo, so you or your agent can read the code behind each line. + +### Sign-in and accounts + +- **GitHub and GitLab sign-in** (`app/src/auth/sign_in.rs`). It links identities to one user and matches accounts by verified email. +- **Safe return-to links.** After sign-in we only send people back to a page on our own site: no `//` or `\` tricks, no control characters, and never to an API, auth or MCP URL. One of the reviews found an open redirect here before launch, and the fix is in. +- **A waitlist.** One setting turns sign-ups off and puts new people on a `waitlist` table with a page that says so. Production won't start unless the setting is given explicitly, so a missing value can't open sign-ups by accident. +- **Sign-in for a CLI** (`app/src/auth/device.rs`). The device-code flow: the CLI shows a code, you approve it in the browser on a page built to resist phishing, and you get an email saying a CLI signed in. Requests are limited per address, and a daily job clears old codes. +- **API tokens** (`app/src/auth/tokens.rs`). Personal tokens and tokens scoped to one project, stored hashed, with a prefix you can recognise in logs and a "last used" time. One extractor, `Principal`, accepts a session, an OAuth token or a bearer token. +- **Account settings.** Notification preferences, a billing email, the OAuth apps you've connected (with revoke) and a "how did you hear about us" question. +- **Staff pages.** A `staff` flag on users opens pages for sign-ups, the email outbox (retry or dismiss a failed send) and feedback. + +### Organizations + +- **Organizations and roles** (`app/src/auth/orgs.rs`). Every new user gets a personal organization. Members have one of three roles: read, member or admin. +- **Invitations** (`app/src/auth/invitations.rs`). Invite by email address or GitHub login. The invitee accepts or declines in the app, sends are capped per day, and an organization can't lose its last admin. +- **A setup checklist** (`app/src/auth/setup.rs`) whose steps tick themselves off from what has actually happened, not from clicks. The steps are ours; the mechanism is yours to reuse. + +### Billing with credits and Stripe + +- **Plans** (`app/src/billing/mod.rs`): Free, a paid Team plan, and an unlimited plan for your own organizations. Each plan includes credits every month. +- **Credit packs and auto-reload.** Paid plans can buy packs of credits, or reload them automatically when they run low, capped at 50 reloads a month. +- **A credit ledger** (`app/src/domain/credits.rs`): a balance on each organization and a row in `credit_transactions` for every change. +- **Stripe** (`app/src/billing/`): Checkout, the customer portal, payment methods and invoices. The webhook handler is idempotent, handles events arriving out of order, and checks live mode, and production refuses to start with test keys. +- **Running out.** When credits run out, auto-reload tries first. If that fails, the work stops with a clear `OUT_OF_CREDITS` error and admins get an email, at most once a month. + +VisualCI charges credits per snapshot. Those rates are set in a few places that call the ledger, so swapping in your own unit (per API call, per document, per seat-month) means changing those call sites, not the billing code. + +### Transactional email + +- **A typed list of emails** (`app/src/notify/`). Welcome, invited, added to or removed from an organization, CLI signed in, token created, credits low, credits ran out, credits bought, plan changed and more, each a variant of one enum. +- **An outbox table.** Every email is written to the database first, with a dedupe key, so the same email can't go to the same person twice. A job sends it through Postmark, tries five times, and then shows the failure on the staff page. + +### An MCP server with OAuth + +- **The MCP server** (`app/src/mcp/`) uses rmcp over Streamable HTTP, stateless, at `/mcp` on its own host. Tools are plain functions with `#[tool]`, and helpers turn their arguments into JSON Schema. A few tools are general (who am I, organizations, tokens, sending feedback, reading the docs as skills); the rest are ours. +- **OAuth 2.1 for MCP clients**, through our [oauth-provider-laravel](https://crates.io/crates/oauth-provider-laravel) package: PKCE, dynamic client registration and token revocation. The issuer is the MCP host and the consent page is on the app host, where people are signed in, and the server checks at startup that the two agree. + +### The API and the hosts + +- **Separate hosts** (`app/src/http/hosts.rs`) for the marketing site, the app, the API and MCP. Each serves only its own paths. +- **Security headers** (`app/src/http/security.rs`): a Content-Security-Policy built at startup from hashes of the page's inline scripts, plus nosniff and no framing. +- **Errors** in one JSON shape, `{"error", "description"}`. When the database is too busy to take a request, the API answers 503 with `Retry-After` straight away, rather than leaving the request to time out. +- **A status endpoint** (`app/src/http/status.rs`) that reports the deployed commit and how much background work is waiting, for an uptime checker to read. + +### Background work and live updates + +- **Heartbeats** (`app/src/heartbeat.rs`). Every scheduled job pushes a heartbeat to an uptime checker when it finishes, so a job that stops running raises an alert. The repo's rules for coding agents require a heartbeat for every background process. +- **A demo reset** that rebuilds a public demo every night through the real code paths. +- **Live updates** (`app/src/live.rs`) without WebSockets: Postgres `LISTEN`/`NOTIFY` reaches every replica, and each process streams server-sent events to whoever is watching. A notification only says "look again", so it never carries data a viewer mightn't be allowed to see. Each process checks its own listener every minute and restarts it when it has gone quiet. + +### Storage + +- **S3-compatible storage** (`app/src/storage/blobs.rs`), content-addressed by SHA-256, with presigned upload and download links so large files skip the server. It works with S3, R2, MinIO and RustFS. + +### Tests + +- **A database per test** (`app/src/testing.rs`), each test inside a transaction that's rolled back. +- **Golden JSON tests** (`app/tests/golden/`) for every API and MCP answer, with one variable to rewrite them after a change you meant to make. +- **Browser screenshots** of the site and the app, reviewed in VisualCI on every pull request, and browser journeys (sign in, open the app, sign out, MCP) on a copy of production: four hosts behind Caddy with TLS, database sessions and a GitHub stand-in. + +### Docs, blog and site + +- **Docs that double as agent skills.** Pages with `skill:` front matter are turned into skills for coding agents, and the MCP server can hand them out. +- **llms.txt and llms-full.txt**, generated and checked on every build. +- **This blog**, from Markdown files, with an Atom feed. +- The marketing site and docs are static files on a Cloudflare Worker. + +### CI and deploys + +- **GitHub Actions** for lint, tests, the screenshot build, the browser journeys, the images and the deploy. +- **The deploy** commits each new image digest to an infrastructure repository that ArgoCD applies. +- **`AGENTS.md`**, the rules our coding agents work by: every change through a pull request, a merge lock so agents don't keep sending each other's pull requests back through CI, tests that never skip quietly, and a health check for everything that runs in the background. + +## What it doesn't have yet + +To save you looking: there's no email-and-password or magic-link sign-in (GitHub and GitLab only), no way to delete an account, and no general rate limiting, only limits on the features that need them. The database schema is one initial migration, so you'll prune it by hand. + +## Deleting our parts + +Most of what's VisualCI-specific is easy to find: the snapshot, build and diff code in `app/src/domain/`, the forge code in `app/src/forge/`, the jobs, most of the MCP tools, the renderers and the CLI in `crates/`, and the client libraries in `clients/`. + +Two places need more care. Organization memberships are kept in step with repository permissions on GitHub and GitLab, so sign-in has to keep the identity linking and lose the repository sync. Project tokens and the credit ledger assume a "project", which you'll rename to whatever your product's main resource is. + +This is the kind of work coding agents are good at. A prompt to start from: + +> Clone github.com/DocSpring/visualci. Read AGENTS.md and docs/design.md. Keep the Laravel Rust app in `app/` and the React app in `server/frontend/`, and delete everything specific to visual testing: snapshots, builds, diffs, baselines, renderers, forge sync, the CLI and the client libraries. Keep sign-in, organizations, invitations, tokens, billing, email, the MCP server and OAuth, live updates, heartbeats, host routing and the test setup. Rename "project" to "workspace". Prune the initial migration to match. Keep the tests passing as you go, and keep the Apache-2.0 licence notice. + +Then build your product on what's left. If you do, [tell us](mailto:support@visualci.com) what you made. From 6592bb8ef03f0573f9eeb936f6d5b79e503aad4f Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 01:14:03 +1300 Subject: [PATCH 2/4] Blog: publish the starter kit post; live updates did make the cutover --- server/frontend/content/blog/laravel-rust-rewrite.md | 2 +- server/frontend/content/blog/laravel-rust-starter-kit.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/frontend/content/blog/laravel-rust-rewrite.md b/server/frontend/content/blog/laravel-rust-rewrite.md index 00c39987..bf61582f 100644 --- a/server/frontend/content/blog/laravel-rust-rewrite.md +++ b/server/frontend/content/blog/laravel-rust-rewrite.md @@ -81,7 +81,7 @@ Both pull requests are still open. Until they merge, VisualCI uses the workaroun ### Live updates without Laravel Cloud -The review page and the CLI's `--wait` follow a build as it's processed. Laravel Rust's bundled WebSocket server, Reverb, runs in a single process and is meant for local development. In production its docs point to managed Reverb on Laravel Cloud. VisualCI runs on our own Kubernetes cluster, so live updates will use the framework's server-sent events, with Postgres `LISTEN`/`NOTIFY` to reach every replica. They didn't make the cutover, and they're next. +The review page and the CLI's `--wait` follow a build as it's processed. Laravel Rust's bundled WebSocket server, Reverb, runs in a single process and is meant for local development. In production its docs point to managed Reverb on Laravel Cloud. VisualCI runs on our own Kubernetes cluster, so live updates use the framework's server-sent events, with Postgres `LISTEN`/`NOTIFY` to reach every replica. The CLI's `--wait` already follows builds this way; the review page in the browser is next. ## What the tests didn't catch diff --git a/server/frontend/content/blog/laravel-rust-starter-kit.md b/server/frontend/content/blog/laravel-rust-starter-kit.md index 5010ce29..ccaa10ea 100644 --- a/server/frontend/content/blog/laravel-rust-starter-kit.md +++ b/server/frontend/content/blog/laravel-rust-starter-kit.md @@ -3,7 +3,7 @@ title: A Laravel Rust starter kit for a production SaaS description: VisualCI is open source, and its server is a Laravel Rust app that runs in production. Clone it, delete the visual testing, and you start with sign-in, organizations, invitations, credit billing on Stripe, transactional email, an MCP server with OAuth, live updates, background jobs with heartbeats, and the tests and CI around them. date: 2026-12-04 author: Nathan Broadbent -draft: true +draft: false --- VisualCI is built in public. The whole product is in one repository, [github.com/DocSpring/visualci](https://github.com/DocSpring/visualci), under the Apache-2.0 licence: the server, the web app, the CLI, the renderers, the docs and this blog. What runs in production is what's in the repo. From 5892e086bda9f7a2a0584a7fff01abd0c3727780 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 01:14:40 +1300 Subject: [PATCH 3/4] Blog: live updates are the transport only; the SSE streams are in #94; keep the rewrite post's sentence --- server/frontend/content/blog/laravel-rust-rewrite.md | 2 +- server/frontend/content/blog/laravel-rust-starter-kit.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/frontend/content/blog/laravel-rust-rewrite.md b/server/frontend/content/blog/laravel-rust-rewrite.md index bf61582f..00c39987 100644 --- a/server/frontend/content/blog/laravel-rust-rewrite.md +++ b/server/frontend/content/blog/laravel-rust-rewrite.md @@ -81,7 +81,7 @@ Both pull requests are still open. Until they merge, VisualCI uses the workaroun ### Live updates without Laravel Cloud -The review page and the CLI's `--wait` follow a build as it's processed. Laravel Rust's bundled WebSocket server, Reverb, runs in a single process and is meant for local development. In production its docs point to managed Reverb on Laravel Cloud. VisualCI runs on our own Kubernetes cluster, so live updates use the framework's server-sent events, with Postgres `LISTEN`/`NOTIFY` to reach every replica. The CLI's `--wait` already follows builds this way; the review page in the browser is next. +The review page and the CLI's `--wait` follow a build as it's processed. Laravel Rust's bundled WebSocket server, Reverb, runs in a single process and is meant for local development. In production its docs point to managed Reverb on Laravel Cloud. VisualCI runs on our own Kubernetes cluster, so live updates will use the framework's server-sent events, with Postgres `LISTEN`/`NOTIFY` to reach every replica. They didn't make the cutover, and they're next. ## What the tests didn't catch diff --git a/server/frontend/content/blog/laravel-rust-starter-kit.md b/server/frontend/content/blog/laravel-rust-starter-kit.md index ccaa10ea..324e667a 100644 --- a/server/frontend/content/blog/laravel-rust-starter-kit.md +++ b/server/frontend/content/blog/laravel-rust-starter-kit.md @@ -75,7 +75,7 @@ VisualCI charges credits per snapshot. Those rates are set in a few places that - **Heartbeats** (`app/src/heartbeat.rs`). Every scheduled job pushes a heartbeat to an uptime checker when it finishes, so a job that stops running raises an alert. The repo's rules for coding agents require a heartbeat for every background process. - **A demo reset** that rebuilds a public demo every night through the real code paths. -- **Live updates** (`app/src/live.rs`) without WebSockets: Postgres `LISTEN`/`NOTIFY` reaches every replica, and each process streams server-sent events to whoever is watching. A notification only says "look again", so it never carries data a viewer mightn't be allowed to see. Each process checks its own listener every minute and restarts it when it has gone quiet. +- **Live updates between replicas** (`app/src/live.rs`) without WebSockets: Postgres `LISTEN`/`NOTIFY` reaches every replica, and a notification only says "look again", so it never carries data a subscriber mightn't be allowed to see. Each process checks its own listener every minute and restarts it when it has gone quiet. The server-sent event streams that carry these to the browser and the CLI are in review ([#94](https://github.com/DocSpring/visualci/pull/94)). ### Storage From 88f65876ee05c9b7dcf65aec961536201be92e6b Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 01:46:20 +1300 Subject: [PATCH 4/4] Blog: the starter kit's description doesn't promise live updates yet --- server/frontend/content/blog/laravel-rust-starter-kit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/frontend/content/blog/laravel-rust-starter-kit.md b/server/frontend/content/blog/laravel-rust-starter-kit.md index 324e667a..1f48b2a9 100644 --- a/server/frontend/content/blog/laravel-rust-starter-kit.md +++ b/server/frontend/content/blog/laravel-rust-starter-kit.md @@ -1,6 +1,6 @@ --- title: A Laravel Rust starter kit for a production SaaS -description: VisualCI is open source, and its server is a Laravel Rust app that runs in production. Clone it, delete the visual testing, and you start with sign-in, organizations, invitations, credit billing on Stripe, transactional email, an MCP server with OAuth, live updates, background jobs with heartbeats, and the tests and CI around them. +description: VisualCI is open source, and its server is a Laravel Rust app that runs in production. Clone it, delete the visual testing, and you start with sign-in, organizations, invitations, credit billing on Stripe, transactional email, an MCP server with OAuth, background jobs with heartbeats, and the tests and CI around them. date: 2026-12-04 author: Nathan Broadbent draft: false