A Laravel Rust starter kit for a production SaaS

· Nathan Broadbent

VisualCI is built in public. The whole product is in one repository, 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 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 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 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. This transport is on main; the server-sent event streams that carry it to the browser and the CLI come next.

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 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 what you made.