Coding Standards (Patinas)
These standards aim to keep the codebase reliable, readable, and evolvable.
Language and tooling
- Rust 2021 edition, nightly features discouraged.
cargo fmt,cargo clippy -- -D warnings, andcargo testrequired pre-PR.- No crate-level
#![allow(clippy::all)]. Use targeted#[allow(clippy::lint_name)]only when strictly necessary, with a comment explaining why. - CI enforces fmt + clippy
-D warningsacross all crates and targets.
Architecture principles
- Hexagonal (Ports & Adapters). Stable contracts in
patinas-ports; domain inpatinas-core; tech adapters inpatinas-adapters-*; composition inapps/*. - Dependency inversion: code against traits; apps wire concrete adapters.
- Feature flags to keep binaries lean per target (
inproc,udp-net,quinn-net, etc.).
Naming and APIs
- Descriptive names; avoid abbreviations and 1–2 letter identifiers.
- Public APIs and traits must be documented with Rustdoc.
- Prefer small, cohesive traits; avoid god-traits.
Concurrency and backpressure
- Use Tokio. Prefer bounded channels; never block producers indefinitely.
- Explicit drop strategies on queue overflow.
- Use
select!and cancellation-aware design for long-running tasks.
Error handling
- Use
anyhowfor app/adapter layers; map errors at boundaries. - Avoid panics in library code; prefer
Result. - Include context via
.with_context(|| ...)for operational clarity.
Observability
- Use
MetricsPortfor counters/histograms. Keep label order stable. - Use
tracingJSON logs with useful context (stream_id, component, file/line). - Prefer histograms for latency-like metrics with meaningful buckets.
Configuration and security
- Use
ConfigPort(TOML + ENV overrides). Validate and freeze settings at composition. - No secrets in logs; avoid secrets in env in production; use files under
/etc/patinas. - mTLS (when available) with CA pinning. Support runtime reload (SIGHUP) for rotation.
Testing
- Unit tests for algorithms and invariants in
patinas-core. - Integration tests for publish/subscribe paths and metrics exposure.
- Property-style tests when possible (e.g., FEC encode/decode integrity).
Documentation
- Keep
docs/architecture/ARCHITECTURE_DETAILED.mdcurrent. - Each crate: module-level Rustdoc describing purpose, responsibilities, and extension points.
- Code comments should explain "why"; avoid redundant "what".