The "Golden Path" represents the most effective, idiomatic way to build applications with MontRS. Following these patterns ensures your app remains deterministic, testable, and agent-friendly.
Before writing any logic, define the data shape. Use #[derive(Schema)] for all inputs and outputs.
#[derive(Schema, Serialize, Deserialize)]
pub struct CreateTodoInput {
#[schema(min_len = 1)]
pub title: String,
}Instead of mixing data fetching and mutations randomly, use the Route trait to unify everything related to a URL path.
- Params: Define what inputs the URL accepts.
- Loader: Fetch side-effect free state for the view.
- Action: Handle validation, persistence, and mutation results.
- View: Define the visual representation.
Group related routes into a Plate. If the functionality is reusable across projects, package it as a standalone crate.
impl Plate<AppConfig> for TodoPlate {
fn register_routes(&self, router: &mut Router<AppConfig>) {
router.register(TodoListRoute);
router.register(TodoCreateRoute);
}
}Use montrs-test to write tests that are fast and reliable. Avoid external dependencies in unit tests by using our built-in mocks and fixtures.
Always provide a description() for your loaders and actions. This small effort pays off significantly when an agent needs to understand or modify your code.
Rely on montrs build, montrs serve, and montrs test instead of raw cargo commands. The CLI handles framework-specific optimizations and context updates.
When errors occur, implement AgentError. This provides the agent (and you) with structured data to resolve issues quickly.