Prerequisites
Before you begin, ensure you have the following installed:Development Workflow
Using dev.sh
Thedev.sh script provides convenient commands for common development tasks:
The
format command uses cargo +nightly fmt and lint runs cargo clippy with auto-fix enabled.Standard Cargo Commands
You can also use standard Cargo commands:Code Style Guidelines
Import Organization
Imports should be grouped in the following order (enforced byrustfmt.toml):
Never use wildcard imports like
use crate::module::*;. Always import items explicitly.Naming Conventions
- Types:
PascalCase(e.g.,FeedEntity,EventBus) - Functions/Variables:
snake_case(e.g.,get_feed,user_id) - Constants:
SCREAMING_SNAKE_CASE(e.g.,MAX_RETRIES,DEFAULT_TIMEOUT)
Formatting Standards
- Indentation: 4 spaces (no tabs)
- Line length: 100 characters maximum
- Trailing commas: Required in multi-line lists
Error Handling
- Use
anyhowfor application errors - Use
thiserrorfor custom error types - Suffix custom error types with
Error(e.g.,DatabaseError,ServiceError)
Async Conventions
- Use
tokio::spawnfor spawning tasks - Prefer
&selfwith interior mutability over&mut self - Use
tokio::sync::Mutexfor async-safe locks
Logging
Use thelog crate macros with contextual information:
Testing
- Use
#[tokio::test]for async tests - Place test utilities in
tests/common/ - Tests require
SQLX_OFFLINE=trueenvironment variable in CI
Commit Conventions
Follow these commit message guidelines:Commit Types
feat: New featurefix: Bug fixrefactor: Code refactoringdocs: Documentation changestest: Test additions or changeschore: Maintenance tasks
User-Facing Commits
Prefix user-facing changes withu_ to include them in release notes:
Format
Examples
CI/CD
GitHub Actions runs the following checks on every pull request:- Format check: Ensures code is properly formatted
- Build: Verifies the project compiles
- Clippy: Runs linter for code quality
- Tests: Executes the test suite
All CI checks must pass before a pull request can be merged.
Documentation
When updating architecture:- Edit
.mmdfiles indocs/diagrams/ - Compile diagrams to PNG:
- Commit both the source and generated images
Common Mistakes to Avoid
Stripping documentation comments
Stripping documentation comments
Always preserve
/// doc comments and //! module docs when refactoring or moving code. Never delete documentation.Not following commit conventions
Not following commit conventions
Strictly adhere to the commit message format. Use
u_ prefix for user-facing changes that should appear in release notes.Using wildcard imports
Using wildcard imports
Never use
use crate::*; or use module::*;. Always import items explicitly at the top of the file.Getting Help
For detailed guidelines on specific tasks:- Adding commands: See Adding Commands
- Database changes: See Database
- Architecture patterns: See Architecture
- Testing: See Testing Guidelines