121 releases

Uses new Rust 2024

new 0.19.4 Jan 21, 2026
0.19.1 Nov 25, 2025
0.18.12 Jul 26, 2025
0.18.2 Mar 31, 2025
0.11.0 Jul 3, 2023

#48 in Configuration

Download history 4182/week @ 2025-10-03 3999/week @ 2025-10-10 3289/week @ 2025-10-17 2727/week @ 2025-10-24 1059/week @ 2025-10-31 832/week @ 2025-11-07 972/week @ 2025-11-14 1082/week @ 2025-11-21 984/week @ 2025-11-28 1111/week @ 2025-12-05 1256/week @ 2025-12-12 765/week @ 2025-12-19 643/week @ 2025-12-26 1050/week @ 2026-01-02 1093/week @ 2026-01-09 1047/week @ 2026-01-16

3,947 downloads per month
Used in 23 crates (15 directly)

MIT license

240KB
6K SLoC

Schematic

Schematic is a library that provides:

  • A layered serde-driven configuration system with support for merge strategies, validation rules, environment variables, and more!
  • A schema modeling system that can be used to generate TypeScript types, JSON schemas, and more!

Both of these features can be used independently or together.

cargo add schematic

Get started: https://moonrepo.github.io/schematic

Configuration

  • Supports JSON, TOML, YAML, Pkl, RON, and more formats via serde.
  • Load sources from the file system or secure URLs.
  • Source layering that merge into a final configuration.
  • Extend additional files through an annotated setting.
  • Field-level merge strategies with built-in merge functions.
  • Aggregated validation with built-in validate functions (provided by garde).
  • Environment variable parsing and overrides.
  • Beautiful parsing and validation errors (powered by miette).
  • Generates schemas that can be rendered to TypeScript types, JSON schemas, and more!

Define a struct or enum and derive the Config trait.

use schematic::Config;

#[derive(Config)]
struct AppConfig {
	#[setting(default = 3000, env = "PORT")]
	port: usize,

	#[setting(default = true)]
	secure: bool,

	#[setting(default = vec!["localhost".into()])]
	allowed_hosts: Vec<String>,
}

Then load, parse, merge, and validate the configuration from one or many sources. A source is either a file path, secure URL, or code block.

use schematic::ConfigLoader;

let result = ConfigLoader::<AppConfig>::new()
	.code("secure: false", "config.yml")?
	.file("path/to/config.yml")?
	.url("https://ordomain.com/to/config.yaml")?
	.load()?;

result.config;
result.layers;

Schemas

Define a struct or enum and derive or implement the Schematic trait.

use schematic::Schematic;

#[derive(Schematic)]
struct Task {
	command: String,
	args: Vec<String>,
	env: HashMap<String, String>,
}

Then generate output in multiple formats, like JSON schemas or TypeScript types, using the schema type information.

use schematic::schema::{SchemaGenerator, TypeScriptRenderer};

let mut generator = SchemaGenerator::default();
generator.add::<Task>();
generator.generate(output_dir.join("types.ts"), TypeScriptRenderer::default())?;

Dependencies

~8–27MB
~269K SLoC