Development Environment Setup
Prerequisites
- Rust 1.56+: Latest stable Rust version
- Cargo: Rust package manager
- SQLx CLI: For database migrations
- Git: Version control
Clone Repository
Install Dependencies
Confirm tools with
cargo --version, sqlx --version, and cargo audit --version.Database Setup
Development Database
Zingat uses SQLite for development by default. The database file is created atzingat.db in the project root.
Codebase Structure
Key Modules
Models (src/models/)
paste.rs: Paste data model and operationsview.rs: View tracking and batch operations
Routes (src/routes/)
paste.rs: API endpoints for paste operationshealth.rs: Health check endpoints
Utilities (src/utils/)
database.rs: Database connection poolingsecurity.rs: Password hashing and validationid_generator.rs: Unique ID generation
Development Workflow
Running Development Server
Running CLI Client
Code Formatting
Linting
Testing
Unit Tests
Run unit tests:Integration Tests
Integration tests are in thetests/ directory:
Test Coverage
Install tarpaulin for test coverage:Database Testing
Tests use a separate test database:Code Quality
Security Audits
Documentation
Generate documentation:Benchmarking
Create benchmarks for performance-critical code:Code Standards
Rust Conventions
- Follow Rust naming conventions
- Use
rustfmtfor consistent formatting - Apply Clippy recommendations
- Document public APIs with
///comments
Error Handling
- Use Rust’s
Resulttype for fallible operations - Implement custom error types in
error.rs - Provide meaningful error messages
Database Operations
- Use prepared statements with SQLx
- Handle database errors appropriately
- Implement proper connection pooling
Security
- Hash passwords with Argon2
- Validate all user input
- Implement rate limiting
- Use HTTPS in production
Performance Considerations
Database Optimization
- Use batch operations for view tracking
- Implement proper indexing
- Monitor query performance
Memory Management
- Use Rust’s ownership system effectively
- Avoid unnecessary allocations
- Implement proper caching
Async Programming
- Use Tokio for async operations
- Avoid blocking calls in async context
- Implement proper error handling in async code
Debugging
Logging
Enable different log levels:1
Start the API server
Run
cargo run --bin httpd and ensure the server listens on the expected port.2
Smoke test the API
3
Run CLI client
Debugging Tools
- println! debugging: Simple output debugging
- dbg! macro: Quick value inspection
- Rust debugger: Use GDB or LLDB
- Tracing: Structured logging