Multi-tenant application: organization-scoped routes in Axum
Multi-tenancy sounds like a simple idea - reuse the same application across multiple organizations. Usually, you put the organization identifier somewhere in the URL, like a subdomain or a path parameter. You quickly realize that making sure that identifier is carried through and validated with every request is not as easy as it sounds. You have requests, queries, redirects, webhooks, forms, emails, and all kinds of checks that must never cross tenant boundaries.
Those kinds of problems I have been wrestling with recently through Featherboard, which is a self-hosted customer feedback management board written in Rust with Axum, Askama, HTMX, and SQLite.
Organization slug is the first parameter of every route
Featherboard constructs the path in the following way:
/{org-slug}/ideas /{org-slug}/roadmap /{org-slug}/settings/site /{org-slug}/settings/user
Enter fullscreen mode
Exit fullscreen mode
The organization identifier is located in the…