Skip to main content

Crate adminx

Crate adminx 

Source
Expand description

§adminx

A framework-neutral admin-panel framework. This crate is a facade: it re-exports the neutral adminx_core plus whichever framework and storage adapters you enable via Cargo features, so you depend on a single crate.

# Axum + PostgreSQL/MySQL/SQLite:
adminx = { version = "2", features = ["axum", "seaorm"] }
# Actix + MongoDB:
adminx = { version = "2", features = ["actix", "mongo"] }

§Usage

use adminx::prelude::*;              // Resource, ReqCtx, ApiResponse, auth, ...

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    adminx::seaorm::init("postgres://localhost/mydb").await?;   // storage adapter
    register_resource(Box::new(UserResource));

    let app = axum::Router::new().nest("/adminx", adminx::axum::router());
    let l = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
    axum::serve(l, app).await?;
    Ok(())
}

The framework/storage integrations live under [self::actix] / self::axum and self::seaorm / self::mongo, each present only when its feature is enabled. Everything else (the Resource trait, prelude, auth, UI) comes straight from the core.

Re-exports§

pub use adminx_core as core;
pub use adminx_axum as axum;axum
pub use adminx_seaorm as seaorm;seaorm
pub use adminx_mongo as mongo;mongo
pub use adminx_rbac as rbac;rbac
pub use adminx_audit as audit;audit
pub use adminx_attachments as attachments;attachments
pub use adminx_search as search;search

Modules§

actions
attach
auth
authz
crud
csrf
error
export
filters
menu
mfa
prelude
Common imports for defining resources and wiring an app.
ratelimit
registry
request
resource
response
storage
ui

Structs§

ApiResponse
Attachment
One stored attachment, as the detail page and the serve route need it.
AuditEntry
One recorded change to one record.
AuthConfig
Claims
Authenticated principal, decoded from the auth cookie by auth::build_ctx.
CreateOutcome
Result of an insert. last_insert_id is backend-dependent (MySQL yields an autoincrement id; Postgres a RETURNING id when available).
CustomAction
Describes a custom action exposed by a resource.
FileField
A file field a resource exposes on its detail page. Declared from Resource::file_fields.
FilterField
A filter a resource exposes on its list page. Declare these from Resource::filterable_fields; the list UI and query builder do the rest.
FilterOption
One option in a Select filter.
ListPage
One page of rows plus the total count for pagination.
MenuItem
QueryOptions
Pagination + ordering + filters distilled from a request query string.
ReqCtx
UploadedFile
A file arriving on an upload request. The adapter builds this from the multipart body; bytes is the whole file held in memory (fine for the admin use-case — logos, avatars, small docs — a streaming path can come later).

Enums§

Action
The operation being authorized. Borrows so Custom carries a handler’s &str name without allocating; it’s Copy, and the lifetime elides to Action<'_> at every call site.
ApiBody
AuditEvent
What happened to a record.
CoreError
Framework-neutral error. Adapters map this onto their own response type.
FilterKind
The kind of input rendered for a filter, and how its value is matched.
MenuAction
StorageError

Constants§

VERSION

Traits§

Attachments
A pluggable attachment backend: stores the bytes somewhere and records the metadata so it can be listed and served back.
Auditor
A pluggable audit sink. Unlike Authorizer this is async and does I/O — it runs once per mutation, not several times per request.
Authorizer
A pluggable authorization policy. can is synchronous and called several times per request, so an implementation must not perform I/O here — a DB-backed one reads a pre-loaded in-memory cache.
Indexer
A pluggable search index. Keyed by index (a resource’s base_path()), so one backend serves every searchable resource. Async — it does I/O, once per mutation, not per request.
Resource
Storage

Functions§

all_resources
attachments
The registered backend, if any.
auditor
The registered auditor, if any.
authorizer
The registered authorizer, if any. None means the built-in role-list check is used.
get_registered_menus
Collect and group menus from every registered resource.
indexer
The registered indexer, if any.
register_resource
Register a resource globally.
seed
Seed the database by running a batch of raw statements against the active backend, in order, stopping at the first error. Write SQL when using a SeaORM backend, or JSON command documents when using Mongo — the same call works for both, you just author for whichever backend you registered.
set_attachments
Register the global attachment backend. Set-once, matching the other seams.
set_auditor
Register the global audit sink. Set-once, matching set_storage and set_authorizer.
set_authorizer
Register the global authorization policy. Set-once: a later call is ignored with a warning, matching set_storage.
set_indexer
Register the global search backend. Set-once, matching the other seams.
set_storage
Register the global storage backend. Call once during startup.
set_tailwind_src
Point the admin UI at a different Tailwind/CSS source (e.g. a self-hosted stylesheet you serve yourself) instead of the CDN default. Set once, before serving; the ADMINX_TAILWIND_SRC env var is honoured as a fallback.
storage
Access the global storage backend. Panics if never initialized.

Type Aliases§

ActionFuture
Boxed future returned by an action handler.
ActionHandler
An action handler receives the (cloned) request context, the target record id, and the JSON request body ({} when none was sent).