Skip to content

Admin panel ​

The admin panel is a single-page application that lists, shows and edits the records of your resources, like a Filament panel. It is embedded in your binary: running it never requires Node. Use it for your team's back office; build your public site or API next to it.

The demo's panel: sidebar groups, the dashboard and its resource cardsThe demo application: the panel's shell with its Content and Settings groups.

Quick start ​

A new application (rustcms new) already has a panel. Its provider lives in src/providers/admin_panel_provider.rs:

rust
use rustcms::prelude::*;

pub fn provider() -> AdminProvider {
    AdminProvider::new()
        .brand("Blog")
        // rustcms:resources
        // rustcms:pages
        // rustcms:extensions
        // Labels in Vietnamese (`rustcms lang:missing vi` lists what is missing).
        .translations("vi", include_str!("../../lang/vi.toml"))
}

rustcms make:resource Post --generate adds .resource::<PostResource>() at the // rustcms:resources marker. Providers are registered in src/bootstrap/providers.rs, the authentication provider first (the panel uses its session guard) and the storage provider before the panel when you use the media library:

rs
pub fn register(app: &mut AppBuilder, api: &ApiRoutes, admin: &AdminRoutes) {
    app.provider(providers::auth_service_provider::provider(api, admin));
    // Uploads under `storage/app` (see `[storage]`); the panel's media library uses them.
    app.provider(rustcms::storage::StorageProvider);
    app.provider(rustcms::mail::MailProvider);
    app.provider(providers::admin_panel_provider::provider());
    app.provider(providers::app_service_provider::AppServiceProvider);
}

Run rustcms permission:sync after adding a resource, then sign in at /admin with a user whose role has its permissions.

Full example ​

The demo's panel: resources, settings groups, a dashboard, custom pages, a slot, extensions and translations.

rs
pub fn provider() -> AdminProvider {
    AdminProvider::new()
        .brand("demo")
        // The site's name, once set in Settings → Site (runtime branding).
        .branding(crate::admin::branding::SiteBranding)
        .media()
        .media_hook(crate::admin::media_hooks::MediaChanges)
        // Collections sort the library: files uploaded through a field that
        // names one go into it (`Field::collection`).
        .media_collection("post-covers", "Post covers")
        .media_collection("post-content", "Post content")
        .media_collection("branding", "Branding")
        // Elements a post's content may hold (rich text version 3): a keyboard
        // shortcut inside text, drawn by the React extension below, and a
        // reference to a note as a block, shown as a placeholder.
        .rich_text_node(
            RichTextNode::inline_atom("app.kbd")
                .label("Keyboard shortcut")
                .attr("keys", Attr::text().min(1).max(40))
                .text(|attrs| attrs.text("keys").to_owned()),
        )
        .rich_text_node(
            RichTextNode::block_atom("app.note_ref")
                .label("Note reference")
                .attr("number", Attr::integer().range(1..=999))
                .attr("tone", Attr::one_of(["info", "warn"]).default("info"))
                .text(|attrs| format!("Note {}", attrs.integer("number").unwrap_or_default())),
        )
        .resource::<CategoryResource>()
        .resource::<PostResource>()
        .resource::<TagResource>()
        .resource::<crate::admin::resources::integration_resource::IntegrationResource>()
        // rustcms:resources
        .settings::<crate::settings::site_settings::SiteSettings>()
        .mail_settings()
        .dashboard(
            rustcms::admin::dashboard::Dashboard::new()
                .widget(rustcms::admin::dashboard::Widget::stat("posts", "posts").label("Posts"))
                .widget(
                    rustcms::admin::dashboard::Widget::chart("posts_per_week", "posts", "published_at")
                        .label("Published per week")
                        .per(rustcms::admin::dashboard::Bucket::Week)
                        .last(8)
                        .span(2),
                )
                // The latest posts, shown as their list shows them (dates formatted).
                .widget(
                    rustcms::admin::dashboard::Widget::recent("latest_posts", "posts")
                        .label("Latest posts")
                        .columns(&["published_at"])
                        .sort("-published_at"),
                ),
        )
        .page::<crate::admin::pages::post_stats_page::PostStatsPage>()
        .page::<crate::admin::pages::live_page::LivePage>()
        .page::<crate::admin::pages::react_page::ReactPage>()
        // rustcms:pages
        .slot::<crate::admin::slots::post_summary_slot::PostSummarySlot>()
        // The `demo/color` widget of the category form.
        .extension_script("demo-color", include_str!("../../resources/admin/js/demo/color.js"))
        .extension_style("demo-color", include_str!("../../resources/admin/css/demo/color.css"))
        // The live page (`LivePage`, server-sent events).
        .extension_script("demo-live", include_str!("../../resources/admin/js/demo/live.js"))
        // The React demo page and the categories' swatch entry (v2, built by
        // `npm run build` in resources/admin).
        .extension_script_v2(
            "demo-react",
            include_str!("../../resources/admin/js/demo/react.js"),
            Requires { react: "19.3", react_query: "5.104", ui: 6 },
        )
        .extension_style("demo-react", include_str!("../../resources/admin/css/demo/react.css"))
        // rustcms:extensions
        // Vietnamese labels (`cargo run -- lang:missing vi` lists what is missing).
        .translations("vi", include_str!("../../lang/vi.toml"))
}

AdminProvider ​

MethodDoes
new()an empty panel
brand(name)the name the panel shows (default "rustcms")
resource::<R>()adds a resource
media()the media library (register StorageProvider first)
settings::<T>(), mail_settings()settings groups, and the mail settings
dashboard(Dashboard)dashboard widgets
page::<P>(), home(slug)custom pages; the home page
slot::<S>()a slot beside records
theme(Theme), branding(source)the theme, runtime branding
extension_script(name, js), extension_style(name, css)extension scripts and styles
extension_script_v2(name, js, requires)a script built with the SDK (React pages)
extension_timeout(duration)how long the panel waits for each extension script: 1 to 60 seconds, default 10
translations(locale, toml)your labels in another language (i18n)

The panel itself is written in English (en) and Vietnamese (vi); a locale in app.locales outside these stops the boot.

Paths ​

The panel is served under auth.admin_path (default /admin):

PathServes
/adminthe dashboard, or the home page
/admin/login, /admin/forgot-password, /admin/reset-password, /admin/invitationsigning in, password reset, accepting an invitation
/admin/r/<slug>a resource's list; …/create, …/records/<key>, …/records/<key>/edit; …/import for importable resources
/admin/p/<slug>, /admin/p/<slug>/…a custom page and its sub-paths
/admin/settings/<group>a settings group
/admin/system/users, …/users/create, …/users/<id>users
/admin/system/roles, …/roles/create, …/roles/<id>roles
/admin/system/audit, /admin/system/queue, /admin/system/schedulesthe audit log, the queue, the schedules
/admin/accountthe user's own account
/admin/assets/…the panel's JS and CSS
/admin/assets/ext/…your extension scripts and styles
/admin/assets/brand/{theme.css,logo,favicon}?v=…the theme's stylesheet and images; also logo-dark with runtime branding
/admin/api/…the panel's JSON API (Admin API); /admin/api/panel describes the panel for the signed-in user

System pages and the Settings group appear as the user's permissions allow. Every user has their own Account page.

Resources the user may list (view_any) appear in the sidebar, grouped by ResourceMeta::group, with ResourceMeta::icon:

rust
ResourceMeta::new("Post").plural("Posts").group("Content").icon("file-text")

Icons (also for pages): activity, bell, box, calendar, chart, cloud, container, cpu, dashboard, database, file-code, file-text, folder, gauge, git-branch, globe, hard-drive, history, home, image, key, layers, link, lock, logs, mail, network, package, rocket, server, settings, shield, shopping-cart, tag, terminal, users, workflow. Any other name shows a generic icon.

Order ​

By default, resources come in registration order (.media() where it is called), then custom pages in registration order, resources first in a group. The dashboard's resource cards follow the same order. .sort(n) on ResourceMeta or PanelPageMeta (default 0) changes it:

  • entries are ordered by sort, then by that default order;
  • groups are ordered by the smallest sort among their entries, then by first appearance;
  • System and Settings always come last.
rust
PanelPageMeta::new("Templates").permission("templates.view").sort(1)
ResourceMeta::new("Project").group("Docker").sort(10)

Hiding a resource ​

ResourceMeta::navigation(false) removes the sidebar entry and the dashboard card. The resource keeps its routes, record pages, API, relations and breadcrumbs, for example when your own React pages replace its list. This is only presentation: listing still needs view_any, and record pages and writes keep their own ability checks (view, update, …).

Home page ​

AdminProvider::home("dashboard") makes /admin open the custom page dashboard instead of the default dashboard, with that page as the first sidebar entry. Users who may not open it see the default dashboard. An unknown slug stops the boot.

What users get ​

  • Lists (tables): search, sortable columns, filters and pagination, kept in the URL; row and bulk actions; a trash for resources with soft deletes.
  • Forms (forms): built for the operation and the user. Only fields the user may write are editable, edits send changed fields only, and server validation messages appear under each input. A write whose outcome is unknown (a timeout, a cut connection) pauses further writes on that resource, and creates and actions can be retried safely.
  • Record pages (resources) with their actions, relations, slots and history.
  • Languages: English and Vietnamese, chosen per user (i18n).
  • Roles (System → Roles): permissions by area with a search box, the labels and presets the application declares (The Roles page).
  • Someone who may update a record but not view it gets an empty edit form; records outside a user's scope show "Not found", forbidden pages "Access denied".

The color scheme is the app's ColorScheme (default System: follows the operating system) until a user chooses Light, Dark or System for themselves (theme). The layout works from phones to wide screens and from the keyboard.

The demo's posts list on a phone, with the sidebar foldedThe demo application at phone width.

Commands ​

The panel adds these commands to your application:

CommandDoes
idempotency:prunedeletes expired idempotency receipts (serve does it hourly)
media:prunedeletes queued media files and abandoned uploads (only with .media())
lang:missing <locale>lists the labels missing in a translation
admin:brandingshows where the panel's branding comes from and loads it once (changes nothing)

Security ​

  • Every request is authorized on the server: see Authorization for the rules.
  • Content Security Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'. connect-src also names the ws:// or wss:// form of the panel's origins, for sockets. Nothing else is ever added: extensions must follow it (no inline scripts or styles).
  • X-Frame-Options: DENY, X-Content-Type-Options: nosniff and Referrer-Policy: same-origin; the reset-password and invitation pages send Referrer-Policy: no-referrer, since their URL carries a token.
  • The session cookie is HttpOnly, SameSite=Lax, scoped to the admin path; writes need the CSRF token and an allowed origin (Authentication).
  • Signing out (or a 401, or signing out in another tab) clears every cached record, schema and form. Panel API responses are private, no-store.
  • After sign-in the user returns to the page they asked for, never outside the panel.

Pitfalls ​

  • Register AuthProvider before AdminProvider, and StorageProvider before a panel with .media(): otherwise the boot stops with register AuthProvider before AdminProvider or register StorageProvider before AdminProvider::media().
  • Resources are checked when the application starts. A misconfiguration (an unknown column, an input for a field that does not exist, a filter on a field that is not filterable) stops the boot with a message naming the resource and the fix.

RustCMS 0.17.0 · source cfb82fa33fab · MIT OR Apache-2.0