Skip to main content

modo/
lib.rs

1//! # modo
2//!
3//! A Rust web framework for small monolithic apps. Single crate, zero proc
4//! macros, built on [`axum`] 0.8 with [`libsql`](https://crates.io/crates/libsql)
5//! (SQLite) for persistence. Handlers are plain `async fn`, routes use
6//! [`axum::Router`] directly, services are wired explicitly in `main()`, and
7//! database queries use raw libsql.
8//!
9//! ## Quick start
10//!
11//! Add to `Cargo.toml`:
12//!
13//! ```toml
14//! [dependencies]
15//! modo = { package = "modo-rs", version = "0.10" }
16//!
17//! [dev-dependencies]
18//! modo = { package = "modo-rs", version = "0.10", features = ["test-helpers"] }
19//! ```
20//!
21//! Minimal application:
22//!
23//! ```rust,no_run
24//! use modo::{Config, Result};
25//! use modo::axum::{Router, routing::get};
26//!
27//! async fn hello() -> &'static str { "Hello, modo!" }
28//!
29//! #[tokio::main]
30//! async fn main() -> Result<()> {
31//!     let config: Config = modo::config::load("config/")?;
32//!     let app = Router::new().route("/", get(hello));
33//!     let server = modo::server::http(app, &config.server).await?;
34//!     modo::run!(server).await
35//! }
36//! ```
37//!
38//! Inside a handler module, pull in the common handler-time types with:
39//!
40//! ```ignore
41//! use modo::prelude::*;
42//! ```
43//!
44//! ## Key crate-level exports
45//!
46//! These items are re-exported at the crate root for convenience:
47//!
48//! - [`Error`] — the framework error type (HTTP status + message + optional source/code)
49//! - [`Result`] — `std::result::Result<T, Error>` alias
50//! - [`Config`] — top-level application configuration
51//! - [`run!`](crate::run) — macro that waits for SIGTERM/SIGINT then shuts down each
52//!   supplied [`Task`](crate::runtime::Task) in declaration order
53//!
54//! ## Virtual flat-index modules
55//!
56//! Three virtual modules re-export items across the crate so you don't have
57//! to remember which source module they live in:
58//!
59//! - [`middlewares`] — every public middleware constructor
60//! - [`extractors`] — every public request extractor
61//! - [`guards`] — every route-level gating layer applied via `.route_layer()`
62//!
63//! [`prelude`] bundles the extras a typical handler signature needs on top of
64//! those (`Error`, `Result`, `AppState`, `Session`, `Role`, `Flash`, `ClientIp`,
65//! `Tenant`, `TenantId`, `I18n`, `Translator`, and the `Validate` trio).
66//!
67//! ## Features
68//!
69//! Every module is always compiled — no cargo features gate production code.
70//! The only feature flag is `test-helpers`, which exposes in-memory backends
71//! and test harnesses ([`testing`]); enable it in your `[dev-dependencies]`.
72//!
73//! | Feature | Purpose |
74//! |---------|---------|
75//! | `test-helpers` | Enables [`testing`] module with `TestDb`, `TestApp`, `TestSession`, and all in-memory/stub backends |
76//!
77//! ## Dependency re-exports
78//!
79//! modo re-exports the four crates that appear in nearly every handler
80//! signature, so you don't need to pin matching versions yourself:
81//!
82//! - [`axum`] — router, extractors, responses
83//! - [`serde`] — `Serialize` / `Deserialize` derives
84//! - [`serde_json`] — JSON values and macros
85//! - [`tokio`] — runtime, tasks, sync primitives
86
87pub mod config;
88pub mod error;
89pub mod runtime;
90pub mod server;
91pub mod service;
92
93pub mod cache;
94pub mod db;
95pub mod storage;
96
97pub mod cookie;
98pub mod extractor;
99pub mod flash;
100pub mod ip;
101pub mod middleware;
102pub mod sse;
103
104pub mod auth;
105pub mod tenant;
106pub mod tier;
107
108pub mod cron;
109pub mod job;
110
111pub mod email;
112pub mod i18n;
113pub mod qrcode;
114pub mod template;
115pub mod webhook;
116
117pub mod audit;
118pub mod health;
119pub mod tracing;
120
121pub mod dns;
122pub mod embed;
123pub mod geolocation;
124
125pub mod encoding;
126pub mod id;
127pub mod sanitize;
128pub mod validate;
129
130#[cfg(feature = "test-helpers")]
131pub mod testing;
132
133pub mod extractors;
134pub mod guards;
135pub mod middlewares;
136pub mod prelude;
137
138pub use config::Config;
139pub use error::{Error, Result};
140
141pub use axum;
142pub use serde;
143pub use serde_json;
144pub use tokio;