modum
It is a lint tool. It reports diagnostics. It doesn't rewrite code.
It analyzes parsed Rust source files. It doesn't expand macros, resolve include!, or prune #[cfg].
It centers namespace shape first, and it also nudges caller-facing boundary modeling when a public surface gets less truthful through flattened paths, raw scalars, or weak module structure.
Start Here
- Want the idea fast? Read Why It Exists and Mental Model.
- Want to try it? Jump to Quick Usage.
- Want to tune it for a real repo? Start with Configuration and the profile guide.
- Want the full lint catalog? See docs/lint-reference.md.
Why It Exists
modum exists to catch two common Rust namespace-shape problems:
- flattened imports that hide useful context at call sites
- redundant leaf names that repeat context the module path already provides
These call-site shapes are legal Rust, but they make signatures and public paths harder to scan:
These usually read more clearly:
The same pattern shows up in public API paths:
Repository
InvalidEmail
Error
instead of:
UserRepository
InvalidEmailError
Error
The central comparison is often this:
Repository
UserRepository
In the abstract, user::Repository is usually better than UserRepository.
Why:
- The domain lives in the path, which is where Rust already gives you structure.
- The leaf can stay generic and composable:
user::Repository,user::Service,user::Id. - It scales better across a crate than baking the domain into every type name.
That is also why user::Repository is usually better than user::UserRepository: once the path is doing the domain work, the leaf doesn't need to repeat it.
The main caveat is that this only holds when user is a real semantic module. If the parent path is weak or technical, then a longer leaf can still be better. UserRepository is often clearer than storage::Repository.
So the rule is:
- strong semantic parent: prefer
user::Repository - weak or technical parent: prefer the more descriptive leaf
modum checks that style across an entire workspace at the parsed-source level.
What It Is For
modum exists to make Rust code read through its paths and surfaces instead of compensating prefixes, suffixes, and flattened aliases.
- Put meaning in module paths when the path is where that meaning belongs.
- Keep leaves short when a strong parent path already carries the domain.
- Keep leaves specific when the parent path is weak or technical.
- Fix the actual structure instead of rewarding cosmetic renames that only silence a lint.
The target is clearer paths and a truer API shape, not one universal naming aesthetic and not shorter names for their own sake. A lint is only good when following it makes the path clearer and the surface more truthful.
That is also why owned code and external crates are treated differently. For code you own, modum can suggest a better parent surface that you could create, such as re-exporting domain::user::User as domain::User. For external crates, it stays conservative and only relies on surfaces that already exist.
Observation Model
modum reads Rust source files with syn and reports source-level heuristics from the parsed AST.
It doesn't observe:
- cfg-pruned items
- macro-expanded items
include!-generated items
When semantic-module family inference would depend on those constructs, modum skips api_candidate_semantic_module and emits api_candidate_semantic_module_unsupported_construct instead.
Mental Model
modum follows four rules:
- Keep namespace context visible at call sites.
- Prefer a strong semantic parent with a short leaf:
user::RepositoryoverUserRepository. - Keep a more descriptive leaf when the parent path is weak or technical.
- Use modules for domain boundaries, not file organization.
Quick Usage
cargo install modum installs both modum and the Cargo subcommand cargo-modum, so either of these is valid:
If you are developing modum itself:
Environment:
MODUM=off||
Default mode is deny.
Output
Text output groups diagnostics into Errors, Policy Diagnostics, and Advisory Diagnostics.
Use --show policy or --show advisory when you want to focus one side of the report without changing exit behavior. The exit code still reflects the full report.
Use --profile core, --profile surface, or --profile strict to choose how opinionated the lint set should be. strict is the default.
Use --ignore <code> for one-off opt-outs in local runs, and --write-baseline <path> plus --baseline <path> when you want to ratchet down an existing repo without fixing every warning at once.
Text output includes the diagnostic code profile, and direct rewrite-style fixes show a short fix: hint inline.
JSON output keeps the full diagnostic list and includes:
profile: the minimum lint profile that includes the diagnosticpolicy: whether the diagnostic counts as a policy violationfix: optional autofix metadata when the rewrite is a direct path replacement, such asresponse::ResponsetoResponse
You can explain any code without running analysis:
CI Usage
Use modum the same way you would use clippy or cargo-deny: run it as a normal command in CI, not from build.rs.
- run: cargo install modum
- run: cargo modum check --root .
For large repos that are adopting modum incrementally:
- run: cargo install modum
- run: cargo modum check --root . --baseline .modum-baseline.json
Editor Integration
For editor setup, see docs/editor-integration.md. The short version is:
- use
--mode warnso diagnostics don't fail the editor job - use
--format jsonfor stable parsing - resolve the workspace root explicitly if one editor session spans several crates
Exit Behavior
0: clean, or warnings allowed via--mode warn2: warning-level policy violations found indenymode1: hard errors, including parse/configuration failures and error-level policy violations such asapi_organizational_submodule_flatten
Configuration
Configure the lints in any workspace with Cargo metadata:
[]
= "strict"
= ["src", "crates/*/src"]
= ["examples/high-coverage"]
= ["Id", "Repository", "Service", "Error", "Command", "Request", "Response", "Outcome"]
= ["storage", "transport", "infra", "common", "misc", "helpers", "helper", "types", "util", "utils"]
= ["common", "misc", "helpers", "helper", "types", "util", "utils"]
= ["error", "errors", "request", "response"]
= ["auth", "command", "components", "email", "error", "http", "page", "partials", "policy", "query", "repo", "store", "storage", "transport", "infra"]
= ["widgets"]
= ["components"]
= ["mime"]
= ["url"]
= ["epoch"]
= ["port"]
= ["labels"]
= ["tags"]
= ["api_candidate_semantic_module"]
= ".modum-baseline.json"
Use [package.metadata.modum] inside a member crate to override workspace defaults for that package. Package settings inherit the workspace defaults first, then apply only the keys you set locally.
include and exclude are optional scan defaults. CLI --include overrides metadata include, and CLI --exclude adds to metadata exclude.
ignored_diagnostic_codes is additive across workspace, package, and CLI --ignore values. Use it for durable repo-level exceptions.
baseline is a repo-root-relative JSON file of existing coded diagnostics. Matching baseline entries are filtered out after normal analysis. A metadata baseline is optional until the file exists; an explicit CLI --baseline <path> requires the file to exist.
Profile guide:
core: internal namespace readability, including private type naming, type-alias hygiene, internal module-boundary rules, and glob/prelude pressure when imports flatten preserved namespacessurface:coreplus caller-facing path shaping and typed boundary nudges for public and shared crate-visible surfaces, including semantic scalar boundaries andanyhowleakagestrict:surfaceplus the heavier advisory heuristics, including semantic-module family suggestions, raw string error surfaces, raw ids, raw key-value bags, bool clusters, manual flag sets, and API-shape taste rules
Profile precedence:
- CLI
--profileoverrides package and workspace metadata [package.metadata.modum] profile = "..."overrides workspace metadata for that crate[workspace.metadata.modum] profile = "..."sets the workspace default- if no profile is set anywhere,
strictis used
Tuning guide:
generic_nouns: generic leaves likeRepository,Error, orRequestnamespace_preserving_modules: modules that should stay visible at call sites, such ashttp,email,partials, orcomponentsextra_namespace_preserving_modules/ignored_namespace_preserving_modules: additive tuning for preserve-module pressure when defaults are close but UI or domain modules likewidgets,components,page, orpartialsneed adjustmentorganizational_modules: modules that should not leak into the public API surface, such aserror,request, orresponseextra_semantic_string_scalars/ignored_semantic_string_scalars: token families for string-like boundary names such asemail,url,path, or your own repo-specific additions likemimeextra_semantic_numeric_scalars/ignored_semantic_numeric_scalars: token families for numeric boundary names such asduration,timestamp,ttl, or repo-specific numeric conceptsextra_key_value_bag_names/ignored_key_value_bag_names: token families for string bag names such asmetadata,headers,params, or repo-specific names likelabelsignored_diagnostic_codes: exact diagnostic codes to suppress, such asapi_candidate_semantic_modulebaseline: repo-root-relative path for a generated baseline file such as.modum-baseline.json
These tuning keys work on lowercase name tokens, not full paths.
Adoption workflow:
- start with
--profile coreor--mode warn - use
ignored_diagnostic_codesfor durable repo-specific exceptions - use
ignored_namespace_preserving_modules = ["components", "page", "partials"]when a UI aggregator repo intentionally flattens those modules and you don't want to replace the full preserve-module default set - generate a baseline with
modum check --write-baseline .modum-baseline.json - apply it in CI with
modum check --baseline .modum-baseline.jsonormetadata.modum.baseline = ".modum-baseline.json"
Lint Categories
The full catalog lives in docs/lint-reference.md. In the README, the important split is what each category is trying to protect:
- Import Style: keep namespace context visible at call sites and stop flattened imports or re-exports from erasing meaning that belongs in the path.
- Public API Paths: keep public surfaces honest by preferring strong semantic parents, avoiding repeated leaf context, and surfacing obvious parent aliases when a child module is doing too much naming work.
- Boundary Modeling: push caller-facing APIs away from raw strings, raw integers, raw id aliases, weak error surfaces, and other boundary shapes that leak semantics into primitives.
- Module Boundaries: catch weak catch-all modules and repeated path segments that usually signal structure drift.
- Structural Errors: block public paths like
partials::error::Errorwhen an organizational child module should be flattened back to the parent surface.
Use modum --explain <code> for one lint at a time, or open docs/lint-reference.md when you want the full category-by-category catalog.
What It Doesn't Check
Some naming-guide rules stay advisory because they are too semantic to lint reliably without compiler-grade context. api_candidate_semantic_module is also source-level only; if a scope relies on #[cfg], item macros, or include!, modum emits api_candidate_semantic_module_unsupported_construct instead of pretending the inferred family is complete.
Examples:
- choosing the best public path among several plausible domain decompositions
- deciding when an internal long name plus
pub use ... as ...is the right tradeoff - deciding whether a new module level adds real meaning or only mirrors the file tree in edge cases
Scope
Default discovery:
- package root: scans
<root>/src - workspace root: scans each member crate's
src
Override discovery with --include:
False Positives And False Negatives
The broader import-style lints only inspect module-scope use items. They don't scan local block imports inside functions or tight test scopes, because those scopes often benefit from flatter imports.
To reduce false negatives:
- extend
namespace_preserving_modulesfor domain modules likeuser,billing, ortenant - use
extra_namespace_preserving_modulesorignored_namespace_preserving_moduleswhen the default preserve-module set is close but not quite right for your repo - keep
generic_nounsaligned with the generic leaves your API actually uses - keep
organizational_modulesconfigured sopartials::error::Error-style paths stay blocked
Read Next
- docs/lint-reference.md: full lint catalog and category detail
- docs/editor-integration.md: Neovim setup and editor-facing JSON usage
- docs/naming-guide.md: naming rules that shape the tool's heuristics