Chuyển tới nội dung chính

Coding guidelines

Formatting and lints​

  • cargo fmt --all (edition 2021, max_width = 100).
  • cargo clippy --workspace --all-targets -- -D warnings must be clean. Workspace lints apply to every crate.
  • cargo test --workspace passes with RIVERBASE_DB_URL pointing at a disposable database.
  • Error codes stay unique across the workspace (see Errors).

Riverbase is distributed under the RFX JSC Proprietary License. Contributions are accepted under a separate written agreement with RFX JSC.

Errors​

  • Raise structured errors with an explicit XXX-NNN code at the point of failure. Never mint codes at runtime.
  • Declare each crate's codes once with declare_errors!. Every code and every message is unique.
  • Propagate with ?. Do not remap an error that is already a RiverbaseError.
  • New prefixes and codes go into the error registry. The validator rejects duplicates.

Architecture​

  • Dependencies point toward riverbase_core. A new edge between crates is an architecture change and needs review.
  • Domain code does not depend on axum, on cross-context dispatch, or on infrastructure adapters.
  • State changes only inside #[domain_action]. Side effects go through the outbox.
  • Every query resource declares a policy. Every extra route declares its RouteAccess.
  • Classify each new operation as a command, query or report, projection, or external effect before writing it.

Persistence​

  • Migrations are embedded per crate and tracked in that crate's schema.
  • Never edit a released migration; add a new one.
  • Tables backing framework rows use diesel_table_with_domain_fields!.

Tests​

  • Postgres-backed tests skip without a database locally and fail in CI.
  • Prefer testing through engines and HTTP over testing private helpers.