This project is a step-by-step reconstruction of the application described in the book "Zero to Production in Rust" by Luca Palmieri. It demonstrates how to build a production-ready web application using Rust.
The application is a newsletter subscription service that allows users to subscribe with their email and name. It's built using modern Rust web development practices and follows a clean architecture approach.
-
Project Setup
- Created a new Rust project with both a library and a binary component
- Set up the project structure with separate modules for different concerns
-
Web Server Implementation
- Integrated Actix Web as the web framework
- Implemented a health check endpoint for monitoring
- Set up a subscription endpoint for newsletter sign-ups
-
Database Integration
- Added PostgreSQL support using SQLx
- Created a database migration for the subscriptions table
- Implemented database connection pooling
-
Configuration Management
- Added structured configuration using the config crate
- Created a YAML configuration file for application settings
- Implemented environment-based configuration
-
Development Tooling
- Added database initialization scripts for development
- Set up Docker integration for PostgreSQL
-
src/: Source codemain.rs: Application entry pointlib.rs: Library exportsconfiguration.rs: Configuration managementstartup.rs: Server setup and initializationroutes/: API endpointshealth_check.rs: Health check endpointsubscriptions.rs: Subscription handling
-
migrations/: Database migrations20250502133713_create_subscriptions_table.sql: Creates the subscriptions table
-
scripts/: Utility scriptsinit_db.ps1: PowerShell script for setting up the database (Windows)init_db.sh: Bash script for setting up the database (Unix/Linux)
-
configuration.yaml: Application configuration
- Rust: Programming language
- Actix Web: Web framework
- SQLx: Database toolkit and ORM
- PostgreSQL: Database
- Tokio: Async runtime
- config: Configuration management
- serde: Serialization/deserialization
- uuid: UUID generation
- chrono: Date and time handling
- Docker: Containerization for development
- Rust toolchain (install via rustup)
- Docker (for running PostgreSQL)
- SQLx CLI (install with
cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres)
-
Run the database initialization script:
Windows:
.\scripts\init_db.ps1
Unix/Linux:
./scripts/init_db.sh
This will:
- Start a PostgreSQL container
- Create the application database user
- Create the database
- Run migrations
-
Build and run the application:
cargo run -
The application will be available at http://127.0.0.1:8000
GET /health_check: Health check endpoint that returns a 200 OK responsePOST /subscriptions: Subscribe to the newsletter with email and name
Future enhancements could include:
- Email validation
- Authentication and authorization
- Newsletter sending functionality
- Admin interface
- Deployment configuration