Runique Admin

Admin setup

Step-by-step guide to enable the admin interface in an existing Runique project.

Prerequisites

  • A working Runique project with a configured database
  • A users model with is_staff and is_superuser fields (generated by model!)
  • The runique binary installed (cargo install runique or cargo build from the workspace)

Step 1 β€” Create `src/admin.rs`

This file declares administrable resources via the admin! macro:

// src/admin.rs
use crate::entities::{users, articles};
use crate::forms::{RegisterForm, ArticleForm};

admin! {
    users: users::Model => RegisterForm {
        title: "Users",
        permissions: ["admin"]
    },
    articles: articles::Model => ArticleForm {
        title: "Articles",
        permissions: ["admin"]
    }
}

Step 2 β€” Generate `src/admins/` with the daemon

runique start

The daemon reads src/admin.rs, generates src/admins/ and launches cargo run. The src/admins/ folder is created automatically β€” do not edit it manually.

src/admins/
  β”œβ”€β”€ README.md
  β”œβ”€β”€ mod.rs
  └── admin_panel.rs

If src/admins/ already exists from a previous generation, runique start regenerates it.


Step 3 β€” Declare the module in `src/main.rs`

mod admin;
mod admins;  // module generated by runique start

Step 4 β€” Wire `.with_admin()` in the builder

use runique::app::builder::RuniqueAppBuilder as builder;

builder::new(config)
    .routes(url::routes())
    .with_database(db)
    .with_admin(|a| {
        a.site_title("Administration")
         .auth(RuniqueAdminAuth::new())
         .routes(admins::routes("/admin"))
         .with_state(admins::admin_state())
    })
    .build()
    .await?
    .run()
    .await?;
MethodRole
.prefix("/admin")Admin route prefix (default: /admin)
.site_title("…")Title displayed in the interface
.auth(RuniqueAdminAuth::new())Admin authentication (default)
.routes(admins::routes("/admin"))Mounts CRUD routes under /admin
.with_state(…)Shared state generated by the daemon
.no_robots_txt()Disables the automatic /robots.txt

Automatic robots.txt β€” When the admin panel is active, Runique automatically serves a /robots.txt route containing Disallow: /admin/ to exclude the interface from search engines. The prefix configured via .prefix() is respected. Use .no_robots_txt() if you want to manage this file yourself.


Step 5 β€” Create a superuser

runique create-superuser

Follows an interactive wizard to create the first admin account (is_superuser = true).


Accessing the interface

Once the server is running, the interface is available at:

http://localhost:{PORT}/admin/

The /admin/login page redirects to the dashboard if credentials are valid.