code-quality
tursodatabase/turso
Production-grade correctness rules for Rust: crash over corruption, assert invariants, avoid hacks.
What is code-quality?
A code-quality guide for writing reliable Rust code in production systems, particularly databases. Emphasizes correctness over convenience, explicit error handling, and pragmatic design patterns that prevent silent failures and data corruption.
- Enforce correctness-first principles: crash rather than corrupt data or silently fail
- Establish Rust patterns: make illegal states unrepresentable, use exhaustive matching, prefer enums over strings
- Require explicit error handling and assertion of invariants instead of workarounds or quick hacks
- Guide conditional logic: use if-statements only for expected branches, assert or error on impossible states
- Prevent over-engineering: avoid premature abstractions, unnecessary docstrings, and impossible-scenario error handling
- Highlight index mutation risks: verify ordering against SQLite to prevent index inconsistencies
How to install code-quality
npx skills add https://github.com/tursodatabase/turso --skill code-qualityHow to use code-quality
- 1.Review the Core Principle: correctness is paramount, crash over corrupt
- 2.Apply Correctness Rules: handle all errors, assert invariants, crash on invalid state, consider edge cases
- 3.Use Rust Patterns: make illegal states unrepresentable, use exhaustive matching, prefer enums, minimize allocations
- 4.Refactor if-statements: replace silent branches with assertions, errors, or unreachable!() macros
- 5.Write only necessary code: skip docstrings on unchanged code, delete unused code, avoid one-time abstractions
- 6.Double-check index mutations for correct ordering against SQLite behavior
Use cases
- Writing database engine code where data corruption is worse than crashes
- Reviewing Rust code for production systems to catch silent failures and unhandled edge cases
- Designing error handling strategies that distinguish between expected and impossible states
- Refactoring conditional logic to use assertions and exhaustive pattern matching instead of silent branches
- Optimizing for performance-critical paths by minimizing allocations and writing CPU-friendly code
- Rust developers working on production systems, especially databases
- Teams building safety-critical or data-integrity-focused applications
- Code reviewers enforcing correctness standards
- Engineers transitioning from permissive languages to Rust's type system
code-quality FAQ
Use if-statements only when both branches are expected execution paths. Use assert!(), return Err(), or unreachable!() when one branch should never happen—this prevents silent failures.
No. Don't add error handling for states that logically cannot occur. Instead, use assertions or unreachable!() to catch logic errors during development.
Only for Rust SAFETY comments explaining unsafe blocks. Avoid code comments on logic; the code should be clear. Don't add docstrings to unchanged code.
Make only changes directly requested or clearly necessary. Don't create abstractions for single-use operations. Three similar lines is better than premature abstraction.
Wrong ordering of index inserts, deletes, or conflict resolution causes index inconsistencies that are easy to miss. Always verify ordering against SQLite behavior.
Full instructions (SKILL.md)
Source of truth, from tursodatabase/turso.
name: code-quality description: General Correctness rules, Rust patterns, comments, avoiding over-engineering. When writing code always take these into account
Code Quality Guide
Core Principle
Production database. Correctness paramount. Crash > corrupt.
Correctness Rules
- No workarounds or quick hacks. Handle all errors, check invariants
- Assert often. Never silently fail or swallow edge cases
- Crash on invalid state if it risks data integrity. Don't continue in undefined state
- Consider edge cases. On long enough timeline, all possible bugs will happen
Rust Patterns
- Make illegal states unrepresentable
- Exhaustive pattern matching
- Prefer enums over strings/sentinels
- Minimize heap allocations
- Write CPU-friendly code (microsecond = long time)
If-Statements
Wrong:
if condition {
// happy path
} else {
// "shouldn't happen" - silently ignored
}
Right:
// If only one branch should ever be hit:
assert!(condition, "invariant violated: ...");
// OR
return Err(LimboError::InternalError("unexpected state".into()));
// OR
unreachable!("impossible state: ...");
Use if-statements only when both branches are expected paths.
Comments
- Don't add code comments, except for rust
SAFETYcomments.
Avoid Over-Engineering
- Only changes directly requested or clearly necessary
- Don't add features beyond what's asked
- Don't add docstrings/comments to unchanged code
- Don't add error handling for impossible scenarios
- Don't create abstractions for one-time operations
- Three similar lines > premature abstraction
Index Mutations
When code involves index inserts, deletes, or conflict resolution, double-check the ordering against SQLite. Wrong ordering causes index inconsistencies. and easy to miss.
Ensure understanding of IO model
- Async IO model
Cleanup
- Delete unused code completely
- No backwards-compat hacks (renamed
_vars, re-exports,// removedcomments)
Single-use helpers
If a helper function has no meaning outside of a single use case, move it inside the function that uses it:
fn do_something() {
something_specific();
fn something_specific() {
}
}
Related skills
More from tursodatabase/turso and the wider catalog.

debugging
Debug Turso database issues using bytecode comparison, logging, ThreadSanitizer, and deterministic simulation.

differential-fuzzer
Information about the differential fuzzer tool, how to run it and use it catch bugs in Turso. Always load this skill when running this tool

index-knowledge
Generate hierarchical AGENTS.md knowledge bases for codebases with complexity scoring and parallel analysis.

mvcc
Overview of Experimental MVCC feature - snapshot isolation, versioning, limitations

pr-workflow
General guidelines for Commits, formatting, CI, dependencies, security

storage-format
Understand SQLite file format, B-trees, pages, and storage internals used by Turso.