A blazingly fast, production-ready URL shortening service built entirely in Rust
Features β’ Quick Start β’ Documentation β’ Contributing
A full-stack URL shortening service built with Rust, leveraging Actix-web for high performance and Diesel ORM for type-safe database operations. Perfect for learning Rust web development or deploying a production URL shortener.
- π Create Short URLs: Transform long URLs into short, shareable links
- π List & Manage: Retrieve and manage all shortened URLs
- β‘ Fast Redirects: Lightning-fast redirection to original URLs
- π Analytics: Track URL usage and statistics
- β° Expiration Support: Set expiration dates for URLs
- β‘ High Performance - Built with Actix-web, one of the fastest web frameworks
- π Type Safety - Diesel ORM provides compile-time query verification
- π³ Docker Ready - Multi-stage Docker builds for easy deployment
- π Statistics Tracking - Monitor URL usage and access patterns
- π Database Flexibility - Supports SQLite, PostgreSQL, and MySQL
- π§ͺ Well Tested - Comprehensive test suite with integration tests
- π Great Documentation - Extensive API and architecture documentation
- π CI/CD Ready - GitHub Actions workflows included
| Feature | Benefit |
|---|---|
| β‘ Performance | Near C/C++ speed with zero-cost abstractions |
| π Memory Safety | No garbage collector, no data races |
| π Concurrency | Fearless concurrency without data races |
| π οΈ Modern Tooling | Cargo, rustfmt, clippy for productive development |
| π Reliability | Catch bugs at compile time, not runtime |
| Component | Technology | Purpose |
|---|---|---|
| Web Framework | Actix-web 4.x | High-performance async HTTP server |
| ORM | Diesel 2.x | Type-safe SQL query builder |
| Database | SQLite / PostgreSQL / MySQL | Flexible data storage |
| Async Runtime | Tokio | Asynchronous runtime |
| Serialization | Serde | JSON serialization/deserialization |
| Environment | dotenvy | Environment variable management |
| Utilities | rand, chrono, uuid | Various utilities |
rust-url-shortener/
βββ .github/
β βββ workflows/ # CI/CD pipelines
β βββ ci.yml
β βββ docker.yml
βββ docs/ # Documentation
β βββ API.md
β βββ ARCHITECTURE.md
β βββ DEPLOYMENT.md
βββ examples/ # Usage examples
β βββ basic_usage.rs
β βββ README.md
βββ migrations/ # Database migrations
β βββ 20230310123456_create_urls/
β βββ 20230310123567_create_usage_logs/
β βββ 20230310123678_create_redirect_stats/
β βββ 20230310123789_add_expiration_date_to_urls/
βββ src/ # Source code
β βββ main.rs # Application entry point
β βββ lib.rs # Library root
β βββ config.rs # Configuration
β βββ db.rs # Database connection
β βββ error.rs # Error handling
β βββ handlers.rs # Request handlers
β βββ loggers.rs # Logging setup
β βββ models.rs # Data models
β βββ routes.rs # Route definitions
β βββ schema.rs # Database schema
β βββ utils.rs # Utilities
βββ scripts/ # Utility scripts
βββ tests/ # Integration tests
β βββ integrationTests.rs
βββ .dockerignore
βββ .env.example # Example environment file
βββ .gitignore
βββ CHANGELOG.md # Version history
βββ CONTRIBUTING.md # Contribution guidelines
βββ Cargo.toml # Rust dependencies
βββ clippy.toml # Linting configuration
βββ docker-compose.yml # Docker Compose setup
βββ Dockerfile # Docker image definition
βββ LICENSE # MIT License
βββ Makefile # Build automation
βββ README.md # This file
βββ rustfmt.toml # Code formatting rules
- Rust 1.56+ - Install via rustup
- SQLite - System SQLite library
- Diesel CLI - Database migration tool
-
Clone the repository
git clone https://github.com/UNC-GDSC/Rust-URL-Shortening.git cd Rust-URL-Shortening -
Install Diesel CLI
cargo install diesel_cli --no-default-features --features sqlite
-
Set up environment
cp .env.example .env
Edit
.envto configure your settings:DATABASE_URL=rust_url_shortener.db BASE_URL=http://localhost:8080 RUST_LOG=info
-
Run database migrations
diesel migration run
-
Build and run
cargo run
The server will start at
http://localhost:8080π
curl -X POST http://localhost:8080/ \
-H "Content-Type: application/json" \
-d '{"original_url": "https://example.com"}'Response:
{
"id": 1,
"original_url": "https://example.com",
"short_code": "abc123",
"created_at": "2024-01-15T10:30:00Z",
"expires_at": null
}curl http://localhost:8080/Simply visit: http://localhost:8080/abc123
For complete API documentation, see docs/API.md
# Build image
docker build -t rust-url-shortener .
# Run container
docker run -d -p 8080:8080 \
-e DATABASE_URL=rust_url_shortener.db \
-e BASE_URL=http://localhost:8080 \
rust-url-shortenerdocker-compose up -dSee docs/DEPLOYMENT.md for production deployment guides.
- API Documentation - Complete API reference with examples
- Architecture - System design and architecture decisions
- Deployment Guide - Deploy to various platforms
- Examples - Code examples for different use cases
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run integration tests
cargo test --test integrationTests# Format code
cargo fmt
# Run linter
cargo clippy
# Run checks
make lintmake build # Build project
make run # Run application
make test # Run tests
make fmt # Format code
make lint # Run clippyWe welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Rate limiting per IP
- Custom short codes
- Analytics dashboard
- QR code generation
- Batch URL creation
- API authentication
- Redis caching layer
- Prometheus metrics
This project is licensed under the MIT License - see the LICENSE file for details.
UNC-CH Google Developer Student Club (GDSC)
- π« Open an issue
- π¬ Discussions
- π Documentation
Made with β€οΈ by UNC-GDSC