Skip to main content

Crate anvilforge

Crate anvilforge 

Source
Expand description

Anvilforge — Laravel-equivalent Rust web framework.

ⓘ
use anvilforge::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let env_path = anvilforge::config::load_dotenv();
    anvilforge::tracing_init::init();
    if let Some(p) = env_path {
        tracing::info!(path = %p.display(), "loaded .env");
    }

    let app = Application::builder()
        .web(|r| r.get("/", |_: State<Container>| async { "hello" }))
        .build();
    app.serve("127.0.0.1:8080".parse()?).await?;
    Ok(())
}

Re-exports§

pub use anvil_test;
pub use bellows;
pub use boost;
pub use cast;
pub use forge;
pub use spark;
pub use spark_derive;

Modules§

app
Application builder. Mirrors Laravel 11’s bootstrap/app.rs.
assay
Pest-flavored testing prelude: use anvilforge::assay::*; in your tests for expect() + TestClient + rich HTTP assertions. The Pest-style prelude. use anvilforge::assay::*; or use anvil_test::assay::*; to bring in the testing surface.
async_trait
github crates-io docs-rs
auth
Auth: sessions, guards, policies. Argon2-backed.
axum
axum is a web application framework that focuses on ergonomics and modularity.
cache
Cache subsystem. Trait-object based, with Moka (in-memory) and Redis drivers.
cast_core
Cast — Eloquent-shaped ORM core on top of sqlx + sea-query.
config
Configuration loading. .env via dotenvy + typed config structs in config/*.rs.
container
The service container. Two layers:
embedded
Compile-time-embedded static assets — the runtime hook for the embed-assets feature.
error
Unified error type for Anvil. Implements IntoResponse so handlers ?-propagate freely.
event
Event bus. Typed pub/sub with sync and queued listeners.
facade
Facade-style ambient helpers.
forge
Forge runtime: stack buffer for @push/@stack, @vite asset helper, escape primitives.
futures
Abstractions for asynchronous programming.
mail
Mail. SMTP via lettre, with an in-memory fake driver for tests.
middleware
Named middleware registry. Strings like "auth", "throttle:60,1", "csrf" are resolved at app-init time to tower Layers.
migration
Migration runner. Each migration is a Rust value with up / down methods.
notification
Notifications. A notifiable can receive a notification via one or more channels.
prelude
queue
Queue subsystem. Jobs dispatched as serialized payloads; workers deserialize and run.
request
Request extras — re-exports and helpers around Axum extractors.
response
Response builders. View rendering, redirects, JSON helpers.
route
Routing DSL — a thin Laravel-shaped layer over Axum’s Router.
schedule
Scheduler. Cron-style expressions matched per tick from smith schedule:run.
seeder
Seeders and factories. Mirrors Laravel’s Illuminate\Database\Seeder + Illuminate\Database\Eloquent\Factories\Factory.
serde
Serde
serde_json
Serde JSON
server
Production HTTP serving: applies the ServerConfig to an axum::Router and starts it on the configured bind addr, with optional TLS via axum-server.
server_config
Production HTTP serving configuration — the NGINX-equivalent surface.
session
Session subsystem. Thin wrapper around tower-sessions.
shutdown
Graceful shutdown signal handling for smith serve and queue workers.
storage
Storage subsystem. Thin wrapper over object_store for local/S3/GCS.
tokio
A runtime for writing reliable network applications without compromising speed.
tracing
A scoped, structured logging and diagnostics system.
tracing_init
Tracing initialization. JSON output in prod, pretty in dev.
validation
Form request + validation. Wraps garde.
view
View rendering helpers. Wraps Forge templates as HTTP responses.

Macros§

migration
Closure-style migration — Laravel’s Schema::create('posts', function (Blueprint $t) { ... }) ported to Rust.
view
view! macro shortcut for handlers: returns a Result<ViewResponse, Error>.

Structs§

Application
Container
ContainerBuilder
EmbeddedAsset
A single embedded file’s payload + metadata. Mirrors what rust_embed::File exposes, but kept framework-owned so the runtime API stays stable if we later swap the embedder.
MiddlewareRegistry
NamedMiddleware
A named middleware: a function that takes a request, optionally consumes args, and returns a response.
Redirect
A redirect response.
RequestId
Typed wrapper for the per-request id, stored in Request::extensions by the request-id middleware. Handlers can pull it via req.extensions().get::<RequestId>() (or via the axum Extension<RequestId> extractor).
Route
A single named route declaration — mostly for route!() macros and named-route URL generation.
RouteInfo
Description of a single registered route. Captured at registration time so Application::routes() (and anvil routes) can list them without poking at Axum’s internals.
Router
ViewResponse
A response that carries a Forge-rendered view body.

Enums§

Error

Traits§

FromContainer
Trait for types that can be resolved from a Container reference.
Responder
Trait for “smart” responders — types that know how to render themselves. Implemented for the common types so handlers can Ok(json(...)) etc.

Functions§

register_embedded_assets
Register an embedded-asset fetcher for the given URL prefix (e.g. "/assets"). Call this from app bootstrap before serve() runs. Re-registering the same prefix replaces the previous fetcher — last writer wins.

Type Aliases§

EmbeddedAssetFetcher
Function pointer signature that backs an embedded mount. Takes a path relative to the mount root (foo/bar.css, no leading slash) and returns the file if it exists in the embedded set.
Result

Derive Macros§

FormRequest
Job
Migration
Seeder