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.8" }
16//!
17//! [dev-dependencies]
18//! modo = { package = "modo-rs", version = "0.8", 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//! use modo::runtime::Task;
27//!
28//! async fn hello() -> &'static str { "Hello, modo!" }
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<()> {
32//!     let config: Config = modo::config::load("config/")?;
33//!     let app = Router::new().route("/", get(hello));
34//!     let server = modo::server::http(app, &config.server).await?;
35//!     modo::run!(server).await
36//! }
37//! ```
38//!
39//! Inside a handler module, pull in the common handler-time types with:
40//!
41//! ```ignore
42//! use modo::prelude::*;
43//! ```
44//!
45//! ## Key crate-level exports
46//!
47//! These items are re-exported at the crate root for convenience:
48//!
49//! - [`Error`] — the framework error type (HTTP status + message + optional source/code)
50//! - [`Result`] — `std::result::Result<T, Error>` alias
51//! - [`Config`] — top-level application configuration
52//! - [`run!`](crate::run) — macro that waits for SIGTERM/SIGINT then shuts down each
53//!   supplied [`Task`](crate::runtime::Task) in declaration order
54//!
55//! ## Virtual flat-index modules
56//!
57//! Three virtual modules re-export items across the crate so you don't have
58//! to remember which source module they live in:
59//!
60//! - [`middlewares`] — every public middleware constructor
61//! - [`extractors`] — every public request extractor
62//! - [`guards`] — every route-level gating layer applied via `.route_layer()`
63//!
64//! [`prelude`] bundles the extras a typical handler signature needs on top of
65//! those (`Error`, `Result`, `AppState`, `Session`, `Role`, `Flash`, `ClientIp`,
66//! `Tenant`, `TenantId`, and the `Validate` trio).
67//!
68//! ## Features
69//!
70//! Every module is always compiled — no cargo features gate production code.
71//! The only feature flag is `test-helpers`, which exposes in-memory backends
72//! and test harnesses ([`testing`]); enable it in your `[dev-dependencies]`.
73//!
74//! | Feature | Purpose |
75//! |---------|---------|
76//! | `test-helpers` | Enables [`testing`] module with `TestDb`, `TestApp`, `TestSession`, and all in-memory/stub backends |
77//!
78//! ## Dependency re-exports
79//!
80//! modo re-exports the four crates that appear in nearly every handler
81//! signature, so you don't need to pin matching versions yourself:
82//!
83//! - [`axum`] — router, extractors, responses
84//! - [`serde`] — `Serialize` / `Deserialize` derives
85//! - [`serde_json`] — JSON values and macros
86//! - [`tokio`] — runtime, tasks, sync primitives
87
88pub mod config;
89pub mod error;
90pub mod runtime;
91pub mod server;
92pub mod service;
93
94pub mod cache;
95pub mod db;
96pub mod storage;
97
98pub mod cookie;
99pub mod extractor;
100pub mod flash;
101pub mod ip;
102pub mod middleware;
103pub mod sse;
104
105pub mod auth;
106pub mod tenant;
107pub mod tier;
108
109pub mod cron;
110pub mod job;
111
112pub mod email;
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;