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.
| 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
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 .env to 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-shortener
docker-compose up -d
See docs/DEPLOYMENT.md for production deployment guides.
# 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 lint
make build # Build project
make run # Run application
make test # Run tests
make fmt # Format code
make lint # Run clippy
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
git checkout -b feature/amazing-feature)git commit -m 'feat: add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
UNC-CH Google Developer Student Club (GDSC)