Newsletter service implemented in Rust using the Axum web framework, based on the "Zero To Production" book by Luca Palmieri.
Features:
- Health check endpoint
- Subscriber sign-up (POST /subscriptions)
- Email confirmation flow (GET /subscriptions/confirm)
- Newsletter publishing (POST /newsletters)
- Integration with an external email API
- Structured tracing and logging
- Configuration via YAML and environment variables
Tech Stack:
- Rust (edition 2024)
- Axum, Tower, Tokio
- SQLx (PostgreSQL)
- Serde, Config, Secrecy
- Tracing (tracing, tracing-subscriber)
- Docker (for local PostgreSQL)
Directory Layout:
.
├── configuration/ # base, development, production YAML files
├── diagrams/ # architecture and flow diagrams
├── infra/ # IaC templates (e.g., Azure Bicep, Terraform)
├── migrations/ # SQL migrations (sqlx)
├── scripts/ # helper scripts (init_db.sh)
├── src/ # application source code
│ ├── domain/ # core domain logic and types
│ ├── routes/ # HTTP handlers
│ ├── email_client.rs # external email API client
│ ├── configuration.rs # settings loader
│ ├── startup.rs # app and router setup
│ └── main.rs # entry point
└── tests/ # integration tests (api)
- Rust toolchain (1.68+)
- Docker
- sqlx-cli (install with
cargo install sqlx-cli --no-default-features --features postgres)
Copy and modify the sample YAML files in configuration/ or set environment variables prefixed with APP__ (e.g., APP__DATABASE__USERNAME).
./scripts/init_db.shcargo runThe API will be available at http://{host}:{port} as defined in your configuration.
Unit and integration tests can be executed with:
cargo testIntegration tests spin up an instance of the service and use wiremock to simulate the email API.
Use curl, Postman, or similar to interact with the endpoints:
- GET /health_check
- POST /subscriptions {"name": "...", "email": "..."}
- GET /subscriptions/confirm?subscription_token=...
- POST /newsletters {"title": "...", "content": {"text": "...", "html": "..."}}
Infrastructure-as-code templates can be found in infra/. Adjust them for your cloud provider (e.g., Azure Bicep, Terraform).
Contributions are welcome! Please open an issue or submit a pull request.
This project is provided for educational purposes only and does not include a license for production use.