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 forexpect()+TestClient+ rich HTTP assertions. The Pest-style prelude.use anvilforge::assay::*;oruse 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.
.envvia dotenvy + typed config structs inconfig/*.rs. - container
- The service container. Two layers:
- embedded
- Compile-time-embedded static assets — the runtime hook for the
embed-assetsfeature. - error
- Unified error type for Anvil. Implements
IntoResponseso 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,@viteasset helper, escape primitives. - futures
- Abstractions for asynchronous programming.
- 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 towerLayers. - migration
- Migration runner. Each migration is a Rust value with
up/downmethods. - 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
ServerConfigto anaxum::Routerand starts it on the configured bind addr, with optional TLS viaaxum-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 serveand 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 aResult<ViewResponse, Error>.
Structs§
- Application
- Container
- Container
Builder - Embedded
Asset - A single embedded file’s payload + metadata. Mirrors what
rust_embed::Fileexposes, but kept framework-owned so the runtime API stays stable if we later swap the embedder. - Middleware
Registry - Named
Middleware - A named middleware: a function that takes a request, optionally consumes args, and returns a response.
- Redirect
- A redirect response.
- Request
Id - Typed wrapper for the per-request id, stored in
Request::extensionsby the request-id middleware. Handlers can pull it viareq.extensions().get::<RequestId>()(or via the axumExtension<RequestId>extractor). - Route
- A single named route declaration — mostly for
route!()macros and named-route URL generation. - Route
Info - Description of a single registered route. Captured at registration time so
Application::routes()(andanvil routes) can list them without poking at Axum’s internals. - Router
- View
Response - A response that carries a Forge-rendered view body.
Enums§
Traits§
- From
Container - Trait for types that can be resolved from a
Containerreference. - 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 beforeserve()runs. Re-registering the same prefix replaces the previous fetcher — last writer wins.
Type Aliases§
- Embedded
Asset Fetcher - 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