Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Coding Conventions

Error Handling

LayerApproach
Domainthiserror for custom error types
Servicesanyhow::Result with .context() chaining
InfrastructureMap driver errors to domain errors
CLIDisplay user-friendly messages

Rules:

  • No unwrap() in production code
  • expect() requires a clear explanation message
  • Errors should be caught at the boundary closest to where they can be meaningfully handled

Async

  • All I/O is async
  • #[tokio::main] entry point
  • Services take &mut self for mutable repository access

Naming

ElementConventionExample
Variables / functionssnake_casewheel_count
Types / structsPascalCaseWheelProduct
DB columns in entitiesPreserve abbreviationspNO, pStatus, pwDia
Service structs{Domain}Service<R: {Domain}Repository>WheelService<R: WheelRepository>
Repo implementationsSqlServer{Domain}RepoSqlServerWheelRepo

Serialization

  • serde derive on all entities
  • #[serde(rename = "...")] for DB column / CSV mapping
  • Custom serializers for booleans, decimals, and dates

CLI Output

  • owo-colors for terminal coloring
  • dialoguer for interactive prompts
  • comfy-table for table formatting
  • indicatif for progress bars

Module Organization

  • One concept per file
  • mod.rs exports the public interface
  • Keep functions under 50 lines; extract sub-functions when exceeding