A production-ready, enterprise-grade Rust web services starter template with domain-driven design, comprehensive security, and first-class idempotency support.
- Domain-Driven Design: Clean architecture with clear separation of concerns
- Axum Web Framework: Production-ready HTTP server with middleware support
- Configuration Management: Environment-based configuration with validation
- Structured Logging: JSON/Pretty logging with tracing support
- Error Handling: Comprehensive error types with HTTP response mapping
- Health Checks: Ready/Live endpoints for monitoring
- Docker Support: Multi-stage Dockerfiles and docker-compose setup
- Phase 2: Security & Authentication + Idempotency Framework
- Phase 3: Advanced Features (Circuit Breakers, Message Queues, Observability)
- Phase 4: Developer Experience (Hot Reload, Coverage, API Client Generation, Feature Flags)
- Phase 5: Testing & Documentation
- Phase 6: Additional Framework Support (Actix-Web)
src/
βββ main.rs # Application entry point
βββ lib.rs # Library exports
βββ config/ # Configuration management
β βββ app_config.rs # Application settings
β βββ database.rs # Database configuration
β βββ observability.rs # Metrics/tracing config
βββ infrastructure/ # External integrations
β βββ database/ # Database abstraction
β β βββ traits.rs # Repository traits
β βββ observability/ # Metrics and tracing
β βββ tracing.rs # Tracing setup
βββ application/ # Application services
β βββ services/ # Business logic services
β βββ dto/ # Data transfer objects
βββ domain/ # Core business logic
β βββ entities/ # Domain entities
β βββ repositories/ # Repository traits
β βββ errors/ # Domain errors
βββ presentation/ # HTTP layer
β βββ handlers/ # HTTP handlers
β β βββ health_handlers.rs # Health check endpoints
β βββ middleware/ # HTTP middleware
β β βββ correlation_id.rs # Request correlation
β β βββ logging_middleware.rs # Request/response logging
β βββ frameworks/ # Framework implementations
β βββ axum_impl.rs # Axum server implementation
βββ shared/ # Shared utilities
βββ errors.rs # Global error types
βββ constants.rs # Application constants
βββ utils.rs # Utility functions
βββ types.rs # Common type definitions
- Web Framework: Axum (with Actix-Web support planned)
- Async Runtime: Tokio
- Database: SQLx with PostgreSQL (MySQL, SQLite support planned)
- Serialization: Serde
- Logging: Tracing with structured output
- Configuration: Config crate with environment variable support
- Security: JWT, Argon2, input validation
- Observability: Prometheus metrics, OpenTelemetry integration
- Testing: Comprehensive unit, integration, and smoke tests
- Rust 1.75+
- Docker and Docker Compose
- PostgreSQL (or use Docker)
git clone <repository-url>
cd rust_webservices_starter
cp .env.example .env.localEdit .env.local with your settings:
# Server
APP_SERVER__HOST=0.0.0.0
APP_SERVER__PORT=8080
# Database
APP_DATABASE__HOST=localhost
APP_DATABASE__USERNAME=postgres
APP_DATABASE__PASSWORD=password
APP_DATABASE__DATABASE=app_db
# JWT Secret (minimum 32 characters)
APP_AUTH__JWT_SECRET=your-super-secret-jwt-key-change-this-in-production-minimum-32-characters# Start all services (app, postgres, redis, prometheus, grafana)
docker-compose up -d
# View logs
docker-compose logs -f app# Start dependencies
docker-compose up postgres redis -d
# Run the application
cargo run --bin server# Health check
curl http://localhost:8080/health
# Readiness check (includes dependency health)
curl http://localhost:8080/health/ready
# Liveness check
curl http://localhost:8080/health/live- Application: http://localhost:8080
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin)
cargo buildcargo testcargo checkcargo fmtcargo clippyThe application uses environment-based configuration with the following sources (in order of precedence):
- Environment variables with
APP_prefix config/local.toml(for local overrides)config/{environment}.toml(development/staging/production)config/default.toml(defaults)
- Server: Host, port, timeouts, connection limits
- Database: Connection details, pool configuration
- Authentication: JWT settings, token expiration
- Observability: Logging format, metrics, tracing
- Feature Flags: Enable/disable specific features
- CORS: Configurable cross-origin resource sharing
- Request Logging: Comprehensive request/response logging with correlation IDs
- Error Handling: Secure error responses without information leakage
- Input Validation: Built-in validation framework
- Security Headers: Standard security headers applied
- Domain Layer: Core business logic and entities
- Application Layer: Use cases and application services
- Infrastructure Layer: External integrations and persistence
- Presentation Layer: HTTP handlers and framework-specific code
Presentation β Application β Domain
β β
Infrastructure β β β β
- Repository Pattern: Abstract data access
- Dependency Injection: Clean separation of concerns
- Error Propagation: Comprehensive error handling
- Configuration: Environment-based settings
# Unit tests
cargo test --lib
# Integration tests
cargo test --test integration
# All tests
cargo test- Follow the established project structure
- Add comprehensive tests for new features
- Update documentation for significant changes
- Ensure all checks pass:
cargo check,cargo test,cargo clippy
MIT License - see LICENSE file for details
- JWT authentication middleware
- Input validation and sanitization
- Rate limiting implementation
- Idempotency framework with Redis/Database storage
- Message queue abstraction (SQS, RabbitMQ, Redis Streams)
- Circuit breaker with jitter
- Comprehensive observability (Prometheus metrics)
- Advanced health checks
- Hot reload development server
- Code coverage integration
- OpenAPI schema generation
- API client generation (TypeScript, Python, Rust)
- Built-in feature flags system
- Comprehensive test suite
- CI/CD pipeline
- Interactive setup script
- Complete documentation
- Actix-Web implementation
- Alternative database drivers
- Additional message queue providers
For questions, issues, or contributions, please visit our GitHub repository.