← Choosing a web framework

Runique vs Loco

Contents

CLI

CommandLocoRunique
Installcargo install lococargo install runique --features sqlite --locked
Create a projectloco new (wizard: app type, database, worker)runique new name
Migrations (generate)cargo loco generate model / generate migrationrunique makemigrations
Migrations (apply)cargo loco db migraterunique migration up
Migrations (roll back)cargo loco db downrunique migration down -n 1
Migration statuscargo loco db statusrunique migration status
Regenerate entitiescargo loco db entities— (model!{} generates them at compile time)
Code generatorsmodel, controller, scaffold, worker, mailer, task, scheduler, deployment—
List routescargo loco routes—
List middlewarescargo loco middleware—
Diagnosticscargo loco doctor—
Create a superuser—runique create-superuser
Startcargo loco startcargo run
Code reloadcargo loco watch (with cargo-watch)—

Routing

FeatureLocoRunique
Route declarationRoutes::new().prefix("notes").add("/", get(list))url.rs with the urlpatterns!{} macro
Dynamic routes.add("/{id}", get(get_one))"/users/{id}" in urlpatterns!
Reverse URL—{% link "view_name" %}
Path parameterAxum Path extractorAxum Path or request.get_path_as::<i32>("id")
Query stringQueryValidate<T> or an Axum extractorrequest.query::<MyStruct>()?
Application prefixAppRoutesRouter::new().nest("/prefix", ...)

Views / Handlers

FeatureLocoRunique
Handlerasync fn hello() -> Result<Response>async fn my_view(mut request: Request) -> AppResult<Response>
Database accessState(ctx): State<AppContext>, then ctx.dbrequest.engine.db
Renderingformat::render().view(&v, "home/hello.html", data)request.render("template.html")
JSON responseformat::json(res)Axum's Json
Redirectformat::redirect("/url")Redirect::to("/url")
Flash messages—success!, error!, info!, warning! macros
Secondary connectionsMultiDbInitializer, named connections.with_custom_db(client)

Forms

FeatureLocoRunique
Definition#[derive(Deserialize, Validate)] struct (validator crate)#[form(schema = blog, fields = [...])] or a manual RuniqueForm
Reading and validationFormValidate<T>, JsonValidate<T>, QueryValidate<T> extractorsValidationForm::try_form(form, &request).await
HTML rendering—{% form.form_name %} or {% form.form_name.field %}
Built-in CSRF—automatic, injected before the first field
Savingmodel code (SeaORM)validated.save(&db).await, the form carries its entity (FormEntity)
Cross-field validationValidatorTraitasync clean(), with database access
FilesAxum's Multipart, configurable storageFileField and MediaField: type, size, content signature for images, audio and video
Storagedisk, memory, S3, GCP, AzureMEDIA_ROOT folder

Templates

FeatureLocoRunique
EngineTera, replaceable engine (ViewRenderer)Tera
Locationassets/views/templates/
Static filesstatic middleware (assets/static){% static "file" %}, with SRI in production
Media files—{% media "file" %}
Reverse URL—{% link "name" %}
CSRF—{% csrf %}
Messages—{% messages %}
Self-contained binaryembedded_assets feature—

ORM / Database

FeatureLocoRunique
ORMSeaORMSeaORM
EnginesSQLite, PostgreSQL (default features)SQLite, PostgreSQL, MySQL, one engine per build
Model definitionentities generated from the migrationsmodel!{} macro
Migrationsloco_rs::schema DSL, written or generatedrunique makemigrations compares with the last snapshot
Queriesquery::condition() and SeaORMsearch! and SeaORM
Paginationquery::paginateSeaORM's .paginate(...)
TransactionsSeaORMrequest.db_atomic() and SeaORM
Multi-tenantmulti-tenancy feature—
Extending a framework table—extend!{} on the eihwaz_* tables

Authentication

FeatureLocoRunique
Login / Logoutgenerated /api/auth/* routesauthenticate_user() + login(), logout()
JWTauth::JWT, auth::JWTWithUser<T>—
API keyfind_by_api_key—
Sessionssigned or encrypted cookie, database and Redis stores (auth_session feature)tower-sessions (memory + database fallback)
OAuth2 / OIDCauth_oauth feature—
Brute-force protection—LoginGuard
Password hashingArgon2id (hash::hash_password)Argon2 by default
Password resetgenerated forgot and reset routestokens hashed in the database, single-use, with an expiry
Permissions—ranks, and admins' permissions per account

Security

FeatureLocoRunique
CSRF—always on
CSP and headerssecure_headers to turn on, github and owasp presetson by default, nonce per request
Rate limitinga tower layer chosen by the projectRateLimiter, declared per route
CORScors middleware.with_cors(...)
Allowed hosts—.with_allowed_hosts(...)
Open redirect—middleware always on
Real IP behind a proxyremote_ip middleware.with_trusted_proxies(...)

Admin panel

FeatureLocoRunique
Setup—typed ModelAdmin builder + AdminSite.register(...)
CRUD, search, filters—built in
Permissions—ranks, admins' permissions per account (table and column)
History—built in

Background tasks

FeatureLocoRunique
WorkersWorker trait, Redis, PostgreSQL, SQLite or thread queues—
Schedulercargo loco scheduler, cron expressions—
One-off taskscargo loco task—
Cachememory, Redis, database—

Email

FeatureLocoRunique
Sendingmailers sent by a workerEmail::new().send()
Templatessubject.t, html.t, text.t (Tera)Tera templates via .template(&tera, "emails/my.html", ctx.into())
SMTP backendconfig/*.yaml files.env
Dev backend (console)—EMAIL_BACKEND=console

Observability / Logging

FeatureLocoRunique
Logging configlogger keys in YAMLRuniqueLog tree, per domain
Foundationtracingtracing
Formatscompact, pretty, jsonstdout, JSON or text file, LogSink
PriorityRUST_LOGRUST_LOG

Tests

FeatureLocoRunique
Commandcargo testrunique test
HTTP requestsrequest::<App, _, _>(), TestServerreqwest or tower::ServiceExt::oneshot
Database isolationrequest_with_create_db, #[serial]runique_test, one transaction per test

Deployment

AspectLocoRunique
Configurationconfig/*.yaml, LOCO_ENV.env, RUNIQUE_ENV
Delivery<package>-cli binarybinary
GeneratorsDocker, nginx, AWS Lambda—
Automatic TLS—acme feature
LicenseApache-2.0MIT

What's coming in Runique